62 bool r = (a.shape()[0] == a.shape()[1]);
63 if (not r and print_error)
64 std::cerr <<
"Error in nda::detail::is_matrix_square: Dimensions are: (" << a.shape()[0] <<
"," << a.shape()[1] <<
")\n" << std::endl;
82 if (not r and print_error) std::cerr <<
"Error in nda::detail::is_matrix_diagonal: Non-diagonal matrix: " << a << std::endl;
104 static_assert(std::is_convertible_v<value_t, double> or std::is_convertible_v<value_t, std::complex<double>>,
105 "Error in nda::determinant_in_place: Value type needs to be convertible to double or std::complex<double>");
106 static_assert(not std::is_const_v<M>,
"Error in nda::determinant_in_place: Value type cannot be const");
109 if (m.empty())
return value_t{1};
112 if (m.extent(0) != m.extent(1)) NDA_RUNTIME_ERROR <<
"Error in nda::determinant_in_place: Matrix is not square: " << m.shape();
115 const int dim = m.extent(0);
118 if (info < 0) NDA_RUNTIME_ERROR <<
"Error in nda::determinant_in_place: info = " << info;
121 auto det = value_t{1};
123 for (
int i = 0; i < dim; i++) {
126 if (ipiv(i) != i + 1) ++n_flips;
129 return ((n_flips % 2 == 1) ? -det : det);
142 template <
typename M>
167 template <MemoryMatrix M>
170 if (m(0, 0) == 0.0) NDA_RUNTIME_ERROR <<
"Error in nda::inverse1_in_place: Matrix is not invertible";
171 m(0, 0) = 1.0 / m(0, 0);
182 template <MemoryMatrix M>
186 std::swap(m(0, 0), m(1, 1));
189 auto det = (m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0));
190 if (det == 0.0) NDA_RUNTIME_ERROR <<
"Error in nda::inverse2_in_place: Matrix is not invertible";
191 auto detinv = 1.0 / det;
208 template <MemoryMatrix M>
212 auto b00 = +m(1, 1) * m(2, 2) - m(1, 2) * m(2, 1);
213 auto b10 = -m(1, 0) * m(2, 2) + m(1, 2) * m(2, 0);
214 auto b20 = +m(1, 0) * m(2, 1) - m(1, 1) * m(2, 0);
215 auto b01 = -m(0, 1) * m(2, 2) + m(0, 2) * m(2, 1);
216 auto b11 = +m(0, 0) * m(2, 2) - m(0, 2) * m(2, 0);
217 auto b21 = -m(0, 0) * m(2, 1) + m(0, 1) * m(2, 0);
218 auto b02 = +m(0, 1) * m(1, 2) - m(0, 2) * m(1, 1);
219 auto b12 = -m(0, 0) * m(1, 2) + m(0, 2) * m(1, 0);
220 auto b22 = +m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0);
223 auto det = m(0, 0) * b00 + m(0, 1) * b10 + m(0, 2) * b20;
224 if (det == 0.0) NDA_RUNTIME_ERROR <<
"Error in nda::inverse3_in_place: Matrix is not invertible";
225 auto detinv = 1.0 / det;
228 m(0, 0) = detinv * b00;
229 m(0, 1) = detinv * b01;
230 m(0, 2) = detinv * b02;
231 m(1, 0) = detinv * b10;
232 m(1, 1) = detinv * b11;
233 m(1, 2) = detinv * b12;
234 m(2, 0) = detinv * b20;
235 m(2, 1) = detinv * b21;
236 m(2, 2) = detinv * b22;
252 template <MemoryMatrix M>
258 if (m.empty())
return;
262 if (m.shape()[0] == 1) {
267 if (m.shape()[0] == 2) {
272 if (m.shape()[0] == 3) {
281 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::inverse_in_place: Matrix is not invertible: info = " << info;
283 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::inverse_in_place: Matrix is not invertible: info = " << info;
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides the generic class for arrays.
Provides basic functions to create and manipulate arrays and views.
A generic multi-dimensional array.
Provides concepts for the nda library.
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
Provides a generic interface to the LAPACK getrf routine.
Provides a generic interface to the LAPACK getri routine.
decltype(auto) make_regular(A &&a)
Make a given object regular.
ArrayOfRank< 1 > auto diagonal(M &m)
Get a view of the diagonal of a 2-dimensional array/view.
ArrayOfRank< 2 > auto diag(V const &v)
Get a new nda::matrix with the given values on the diagonal.
constexpr char get_algebra
Constexpr variable that specifies the algebra of a type.
constexpr bool is_matrix_or_view_v
Constexpr variable that is true if type A is a regular matrix or a view of a matrix.
std::decay_t< decltype(get_first_element(std::declval< A const >()))> get_value_t
Get the value type of an array/view or a scalar type.
#define CLEF_MAKE_FNT_LAZY(name)
Macro to make any function lazy, i.e. accept lazy arguments and return a function call expression nod...
int getri(A &&a, IPIV const &ipiv)
Interface to the LAPACK getri routine.
int getrf(A &&a, IPIV &&ipiv)
Interface to the LAPACK getrf routine.
static constexpr bool on_host
Constexpr variable that is true if all given types have a Host address space.
Provides definitions of various layout policies.
Provides functionality to make objects, functions and methods lazy.
Provides functions to create and manipulate matrices, i.e. arrays/view with 'M' algebra.
Defines various memory handling policies.
Provides various overloads of the operator<< for nda related objects.
Contiguous layout policy with C-order (row-major order).
Memory policy using an nda::mem::handle_sso.
Provides type traits for the nda library.