34namespace nda::linalg {
57 template <Vector WR, Vector WI>
61 auto const n = wr.size();
62 EXPECTS(n == wi.size());
66 for (
long i = 0; i < n; ++i) lambda(i) = std::complex<double>(wr(i), wi(i));
95 template <Vector WI, Matrix VA>
98 using namespace std::complex_literals;
101 auto const n = wi.size();
102 EXPECTS(va.shape() == (std::array<long, 2>{n, n}));
110 for (
long i = 0; i < n; ++i) {
111 X(i, j) = std::complex<double>{va(i, j), va(i, j + 1)};
112 X(i, j + 1) = std::complex<double>{va(i, j), -va(i, j + 1)};
117 X(nda::range::all, j) = va(nda::range::all, j);
128 template <MemoryMatrix A>
130 auto eig_impl(A &&a,
char jobvl,
char jobvr) {
133 auto const n = a.extent(0);
136 if (a.empty())
return std::make_tuple(arr_t{}, mat_t{}, mat_t{});
139 auto lambda = arr_t(n);
140 auto U = (jobvl ==
'V') ? mat_t(n, n) : mat_t();
141 auto V = (jobvr ==
'V') ? mat_t(n, n) : mat_t();
145 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::detail::eig_impl: geev routine failed: info = " << info;
147 return std::make_tuple(std::move(lambda), std::move(U), std::move(V));
151 template <MemoryMatrix A>
152 requires(std::same_as<double, get_value_t<A>>)
153 auto eig_impl(A &&a,
char jobvl,
char jobvr) {
156 auto const n = a.
extent(0);
159 if (a.empty())
return std::make_tuple(arr_t{}, mat_t{}, mat_t{});
169 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::detail::eig_impl: geev routine failed: info = " << info;
176 return std::make_tuple(std::move(lambda), std::move(U), std::move(V));
202 template <MemoryMatrix A>
205 auto [lambda, U, V] = detail::eig_impl(std::forward<A>(a),
'N',
'V');
206 return std::make_pair(std::move(lambda), std::move(V));
228 template <MemoryMatrix A>
231 auto [lambda, U, V] = detail::eig_impl(std::forward<A>(a),
'N',
'N');
262 template <MemoryMatrix A>
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides the generic class for arrays.
long extent(int i) const noexcept
Get the extent of the ith dimension.
Provides concepts for the nda library.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
Provides a generic interface to the LAPACK geev routine.
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
basic_array< ValueType, 2, Layout, 'M', ContainerPolicy > matrix
Alias template of an nda::basic_array with rank 2 and an 'M' algebra.
constexpr bool have_same_value_type_v
Constexpr variable that is true if all types in As have the same value type as A0.
static constexpr bool has_F_layout
Constexpr variable that is true if the given nda::Array type has nda::F_layout.
int geev(A &&a, WR &&wr, WI &&wi, VL &&vl, VR &&vr, char jobvl='N', char jobvr='V')
Interface to the LAPACK geev routine for real matrices.
static constexpr bool have_host_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Host.
constexpr bool is_complex_v
Constexpr variable that is true if type T is a std::complex type.
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Provides definitions of various layout policies.
Provides utility functions for the nda::linalg namespace.
Macros used in the nda library.
Provides functions to create and manipulate matrices, i.e. arrays/view with 'M' algebra.
Contiguous layout policy with Fortran-order (column-major order).
Provides type traits for the nda library.