34namespace nda::linalg {
62 template <Vector WR, Vector WI>
66 auto const n = wr.size();
67 EXPECTS(n == wi.size());
72 for (
long i = 0; i < n; ++i) lambda(i) = std::complex<fp_t>(wr(i), wi(i));
109 template <Vector WI, Matrix VA>
112 using namespace std::complex_literals;
115 auto const n = wi.size();
116 EXPECTS(va.shape() == (std::array<long, 2>{n, n}));
125 for (
long i = 0; i < n; ++i) {
126 X(i, j) = std::complex<fp_t>{va(i, j), va(i, j + 1)};
127 X(i, j + 1) = std::complex<fp_t>{va(i, j), -va(i, j + 1)};
132 X(range::all, j) = va(range::all, j);
163 template <Vector AR, Vector AI, Vector B>
167 auto const n = alphar.size();
168 EXPECTS(n == alphai.size());
169 EXPECTS(n == beta.size());
174 for (
long i = 0; i < n; ++i) lambda(i) = std::complex<fp_t>(alphar(i), alphai(i)) / std::complex<fp_t>(beta(i));
196 template <Vector A, Vector B>
201 auto const n = alpha.size();
202 EXPECTS(n == beta.size());
207 for (
long i = 0; i < n; ++i) lambda(i) = alpha(i) / beta(i);
214 template <blas_lapack::BlasArrayCplx<2> A>
215 auto eig_impl(A &&a,
char jobvl,
char jobvr) {
218 auto const n = a.extent(0);
221 if (a.empty())
return std::make_tuple(arr_t{}, mat_t{}, mat_t{});
224 auto lambda = arr_t(n);
225 auto U = (jobvl ==
'V') ? mat_t(n, n) : mat_t();
226 auto V = (jobvr ==
'V') ? mat_t(n, n) : mat_t();
230 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::detail::eig_impl: geev routine failed: info = " << info;
232 return std::make_tuple(std::move(lambda), std::move(U), std::move(V));
236 template <blas_lapack::BlasArrayReal<2> A>
237 auto eig_impl(A &&a,
char jobvl,
char jobvr) {
241 auto const n = a.
extent(0);
244 if (a.empty())
return std::make_tuple(arr_t{}, mat_t{}, mat_t{});
253 int info =
lapack::geev(a, wr, wi, vl, vr, jobvl, jobvr);
254 if (info != 0) NDA_RUNTIME_ERROR <<
"Error in nda::linalg::detail::eig_impl: geev routine failed: info = " << info;
261 return std::make_tuple(std::move(lambda), std::move(U), std::move(V));
290 template <blas_lapack::BlasArray<2> A>
293 auto [lambda, U, V] = detail::eig_impl(std::forward<A>(a),
'N',
'V');
294 return std::make_pair(std::move(lambda), std::move(V));
317 template <blas_lapack::BlasArray<2> A>
320 auto [lambda, U, V] = detail::eig_impl(std::forward<A>(a),
'N',
'N');
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.
Check if T is the same as any of the types in Us.
Check if a given type is either a float or double type.
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.
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.
typename remove_complex< get_value_t< A > >::type get_fp_t
Get the floating-point type associated with the value type of an array/view/scalar type.
static constexpr bool has_F_layout
Constexpr variable that is true if all given nda::Array types have nda::F_layout.
auto eig(A const &a)
Compute the eigenvalues and right eigenvectors of a general matrix.
auto eigvals(A const &a)
Compute the eigenvalues of a general matrix.
auto get_ggev_eigenvalues(const AR &alphar, const AI &alphai, const B &beta)
Get the complex eigenvalues from nda::lapack::ggev output for real matrices.
auto eig_in_place(A &&a)
Compute the eigenvalues and right eigenvectors of a general matrix in place.
auto get_geev_eigenvalues(const WR &wr, const WI &wi)
Get the complex eigenvalues from nda::lapack::geev output for real matrices.
auto eigvals_in_place(A &&a)
Compute the eigenvalues of a general matrix in place.
auto unpack_eigenvectors(const WI &wi, const VA &va)
Unpack eigenvectors of real matrices from nda::lapack::geev or nda::lapack::ggev output.
int geev(A &&a, WR &&wr, WI &&wi, VL &&vl, VR &&vr, char jobvl='N', char jobvr='V', W1 &&work=vector_value_t< A >{})
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_blas_lapack_v
Constexpr variable that is true if type T is either of type 'float', double, std::complex<float>' or ...
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.