29namespace nda::linalg {
39 void inv_in_place_2d(MemoryMatrix
auto &&m) {
42 auto const det = (m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0));
43 if (
det == 0.0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::inv_in_place: Matrix is not invertible";
44 auto const detinv = 1.0 /
det;
55 void inv_in_place_3d(MemoryMatrix
auto &&m) {
60 adj(0, 0) = +m(1, 1) * m(2, 2) - m(1, 2) * m(2, 1);
61 adj(1, 0) = -m(1, 0) * m(2, 2) + m(1, 2) * m(2, 0);
62 adj(2, 0) = +m(1, 0) * m(2, 1) - m(1, 1) * m(2, 0);
63 adj(0, 1) = -m(0, 1) * m(2, 2) + m(0, 2) * m(2, 1);
64 adj(1, 1) = +m(0, 0) * m(2, 2) - m(0, 2) * m(2, 0);
65 adj(2, 1) = -m(0, 0) * m(2, 1) + m(0, 1) * m(2, 0);
66 adj(0, 2) = +m(0, 1) * m(1, 2) - m(0, 2) * m(1, 1);
67 adj(1, 2) = -m(0, 0) * m(1, 2) + m(0, 2) * m(1, 0);
68 adj(2, 2) = +m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0);
71 auto const det = m(0, 0) * adj(0, 0) + m(0, 1) * adj(1, 0) + m(0, 2) * adj(2, 0);
72 if (
det == 0.0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::inv_in_place: Matrix is not invertible";
73 auto const detinv = 1.0 /
det;
97 template <MemoryMatrix M>
103 auto const dim = m.shape()[0];
105 if (m(0, 0) == 0.0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::inv_in_place: Matrix is not invertible";
106 m(0, 0) = 1.0 / m(0, 0);
107 }
else if (dim == 2) {
108 detail::inv_in_place_2d(m);
109 }
else if (dim == 3) {
110 detail::inv_in_place_3d(m);
111 }
else if (dim > 3) {
115 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::inv_in_place: getrf routine failed: info = " << info;
119 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::inv_in_place: getri routine failed: info = " << info;
150 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::inv: getrf routine failed: info = " << info;
155 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::inv: getrs routine failed: info = " << info;
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides the generic class for arrays.
void swap(nda::basic_array_view< V1, R1, LP1, A1, AP1, OP1 > &a, nda::basic_array_view< V2, R2, LP2, A2, AP2, OP2 > &b)=delete
std::swap is deleted for nda::basic_array_view.
Provides basic functions to create and manipulate arrays and views.
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.
Provides a generic interface to the LAPACK getrs routine.
auto eye(Int dim)
Create an identity nda::matrix with ones on the diagonal.
decltype(auto) make_regular(A &&a)
Make a given object regular.
auto transpose(A &&a)
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.
bool is_matrix_square(A const &a, bool print_error=false)
Check if a given matrix is square, i.e. if the first dimension has the same extent as the second dime...
basic_array< ValueType, 1, C_layout, 'V', ContainerPolicy > vector
Alias template of an nda::basic_array with rank 1 and a 'V' algebra.
basic_array< ValueType, 2, Layout, 'M', ContainerPolicy > matrix
Alias template of an nda::basic_array with rank 2 and an 'M' algebra.
nda::basic_array< ValueType, 1+sizeof...(Ns), nda::basic_layout< nda::static_extents(N0, Ns...), nda::C_stride_order< 1+sizeof...(Ns)>, nda::layout_prop_e::contiguous >, 'A', nda::stack< N0 *(Ns *... *1)> > stack_array
Alias template of an nda::basic_array with static extents, contiguous C layout, 'A' algebra and nda::...
constexpr char get_algebra
Constexpr variable that specifies the algebra of a type.
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...
auto inv(A &&...__a)
Lazy version of nda::linalg::inv.
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.
int getrs(A const &a, B &&b, IPIV const &ipiv)
Interface to the LAPACK getrs routine.
static constexpr bool have_host_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Host.
static constexpr bool have_device_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Device.
heap_basic< mem::mallocator< AdrSp > > heap
Alias template of the nda::heap_basic policy using an nda::mem::mallocator.
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Provides definitions of various layout policies.
Macros used in the nda library.
Provides functions to create and manipulate matrices, i.e. arrays/view with 'M' algebra.
Defines various memory handling policies.
Contiguous layout policy with Fortran-order (column-major order).
Provides type traits for the nda library.