TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Linear algebra tools

Detailed Description

Generic functions that wrap the BLAS and LAPACK interfaces to provide a more user-friendly approach for the most common linear algebra related tasks.

Functions

template<Vector X, Vector Y>
requires (nda::mem::have_host_compatible_addr_space<X, Y>)
auto nda::linalg::cross_product (X const &x, Y const &y)
 Compute the cross product \( \mathbf{x} \times \mathbf{y} \) of two 3-dimensional vectors \( \mathbf{x} \) and \( \mathbf{y} \).
template<Matrix M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<M> and is_blas_lapack_v<get_value_t<M>>)
auto nda::linalg::det (M const &m)
 Compute the determinant of an \( n \times n \) matrix \( \mathbf{M} \).
template<Matrix M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<M> and is_blas_lapack_v<get_value_t<M>>)
auto nda::linalg::det_in_place (M &&m)
 Compute the determinant of an \( n \times n \) matrix \( \mathbf{M} \).
template<typename X, typename Y>
requires ((Scalar<X> and Scalar<Y>) or (Vector<X> and Vector<Y>))
auto nda::linalg::dot (X const &x, Y const &y)
 Compute the dot product of two nda::vector objects or the product of two scalars.
template<bool star = false, Vector X, Vector Y>
requires (Scalar<get_value_t<X>> and Scalar<get_value_t<Y>> and mem::have_host_compatible_addr_space<X, Y>)
auto nda::linalg::dot_generic (X const &x, Y const &y)
 Generic loop-based dot product implementation for vectors.
template<typename X, typename Y>
requires ((Scalar<X> and Scalar<Y>) or (Vector<X> and Vector<Y>))
auto nda::linalg::dotc (X const &x, Y const &y)
 Compute the dotc (LHS operand is conjugated) product of two nda::vector objects or the product of two scalars.
template<Matrix A>
requires (Scalar<get_value_t<A>>)
auto nda::linalg::eigh (A const &a)
 Compute the eigenvalues and eigenvectors of a real symmetric or complex hermitian matrix.
template<Matrix A, Matrix B>
requires (Scalar<get_value_t<A>> and Scalar<get_value_t<B>>)
auto nda::linalg::eigh (A const &a, B const &b, int itype=1)
 Compute the eigenvalues and eigenvectors of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.
template<MemoryMatrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and is_blas_lapack_v<get_value_t<A>> and nda::blas::has_F_layout<A>)
auto nda::linalg::eigh_in_place (A &&a)
 Compute the eigenvalues and eigenvectors of a real symmetric or complex hermitian matrix.
template<MemoryMatrix A, MemoryMatrix B>
requires (nda::mem::have_host_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>> and have_same_value_type_v<A, B> and nda::blas::has_F_layout<A> and nda::blas::has_F_layout<B>)
auto nda::linalg::eigh_in_place (A &&a, B &&b, int itype=1)
 Compute the eigenvalues and eigenvectors of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.
template<Matrix A>
requires (Scalar<get_value_t<A>>)
auto nda::linalg::eigvalsh (A const &a)
 Compute the eigenvalues of a real symmetric or complex hermitian matrix.
template<Matrix A, Matrix B>
requires (Scalar<get_value_t<A>> and Scalar<get_value_t<B>>)
auto nda::linalg::eigvalsh (A const &a, B const &b, int itype=1)
 Compute the eigenvalues of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.
template<MemoryMatrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and is_blas_lapack_v<get_value_t<A>> and nda::blas::has_F_layout<A>)
auto nda::linalg::eigvalsh_in_place (A &&a)
 Compute the eigenvalues of a real symmetric or complex hermitian matrix.
template<MemoryMatrix A, MemoryMatrix B>
requires (nda::mem::have_host_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>> and have_same_value_type_v<A, B> and nda::blas::has_F_layout<A> and nda::blas::has_F_layout<B>)
auto nda::linalg::eigvalsh_in_place (A &&a, B &&b, int itype=1)
 Compute the eigenvalues of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.
template<typename LP = F_layout, MemoryMatrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and nda::blas::has_F_layout<A>)
auto nda::linalg::get_lu_matrices (A const &a)
 Get the \( \mathbf{L} \) and \( \mathbf{U} \) matrices from the output of nda::lapack::getrf.
template<Scalar T, typename LP = F_layout>
auto nda::linalg::get_permutation_matrix (Vector auto const &ipiv, int m)
 Get the permutation matrix \( \mathbf{P} \) from the pivot indices returned by nda::lapack::getrf or other LAPACK routines.
template<Scalar T, typename LP = F_layout>
auto nda::linalg::get_permutation_matrix (Vector auto const &sigma, bool column_permutations=false)
 Get the permutation matrix \( \mathbf{P} \) from a permutation vector \( \mathbf{\sigma} \).
auto nda::linalg::get_permutation_vector (Vector auto const &ipiv, int m)
 Get the permutation vector \( \mathbf{\sigma} \) from the pivot indices returned by nda::lapack::getrf or other LAPACK routines.
template<MemoryMatrix A, MemoryVector TAU>
requires (nda::mem::have_host_compatible_addr_space<A, TAU> and have_same_value_type_v<A, TAU> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::get_qr_matrices (A const &a, TAU const &tau, bool complete=false)
 Get the \( \mathbf{Q} \) and \( \mathbf{R} \) matrices from the output of nda::lapack::geqp3.
template<Matrix M>
requires (get_algebra<M> == 'M' and is_blas_lapack_v<get_value_t<M>>)
auto nda::linalg::inv (M const &m)
 Compute the inverse of an \( n \times n \) matrix \( \mathbf{M} \).
template<MemoryMatrix M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<M> and is_blas_lapack_v<get_value_t<M>>)
void nda::linalg::inv_in_place (M &&m)
 Compute the inverse of an \( n \times n \) matrix \( \mathbf{M} \).
template<Matrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::lu (A const &a, bool allow_singular=false)
 Compute the LU factorization of a matrix.
template<typename LP = F_layout, MemoryMatrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and nda::blas::has_F_layout<A> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::lu_in_place (A &&a, bool allow_singular=false)
 Compute the LU factorization of a matrix in place.
template<Matrix A, Matrix B>
auto nda::linalg::matmul (A &&a, B &&b)
 Compute the matrix-matrix product of two nda::matrix objects.
template<Matrix A, Vector X>
requires (mem::have_compatible_addr_space<A, X>)
auto nda::linalg::matvecmul (A const &a, X const &x)
 Compute the matrix-vector product of an nda::matrix and an nda::vector object.
template<ArrayOfRank< 1 > A>
requires (Scalar<get_value_t<A>>)
double nda::linalg::norm (A const &a, double p=2.0)
 Calculate the p-norm of an nda::ArrayOfRank<1> object \( \mathbf{x} \) with scalar values. The p-norm is defined as.
template<MemoryArray A, MemoryArray B>
requires ((nda::blas::has_C_layout<A> or nda::blas::has_F_layout<A>) and nda::blas::has_C_layout<A> == nda::blas::has_C_layout<B>)
auto nda::linalg::outer_product (A const &a, B const &b)
 Outer product of two arrays/views.
template<Matrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::qr (A const &a, bool complete=false)
 Compute the QR factorization of a matrix.
template<MemoryMatrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and nda::blas::has_F_layout<A> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::qr_in_place (A &&a, bool complete=false)
 Compute the QR factorization of a matrix in place.
template<Matrix A, Array B>
requires (have_same_value_type_v<A, B> and nda::mem::have_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::solve (A const &a, B const &b)
 Solve a system of linear equations.
template<MemoryMatrix A, MemoryArray B>
requires (have_same_value_type_v<A, B> and nda::mem::have_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>>)
void nda::linalg::solve_in_place (A &&a, B &&b)
 Solve a system of linear equations in-place.
template<Matrix A>
requires (is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::svd (A const &a)
 Compute the singular value decomposition (SVD) of a matrix.
template<MemoryMatrix A>
requires (is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::svd_in_place (A &&a)
 Compute the singular value decomposition (SVD) of a matrix in place.

Function Documentation

◆ cross_product()

template<Vector X, Vector Y>
requires (nda::mem::have_host_compatible_addr_space<X, Y>)
auto nda::linalg::cross_product ( X const & x,
Y const & y )

#include <nda/linalg/cross_product.hpp>

Compute the cross product \( \mathbf{x} \times \mathbf{y} \) of two 3-dimensional vectors \( \mathbf{x} \) and \( \mathbf{y} \).

Template Parameters
Xnda::Vector type.
Ynda::Vector type.
Parameters
xInput vector \( \mathbf{x} \).
yInput vector \( \mathbf{y} \).
Returns
nda::vector containing the cross product of the two vectors.

Definition at line 35 of file cross_product.hpp.

◆ det()

template<Matrix M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<M> and is_blas_lapack_v<get_value_t<M>>)
auto nda::linalg::det ( M const & m)

#include <nda/linalg/det.hpp>

Compute the determinant of an \( n \times n \) matrix \( \mathbf{M} \).

The given matrix/view is not modified. It first makes a copy of the matrix/view and then calls nda::linalg::det_in_place.

Template Parameters
Mnda::MemoryMatrix type.
Parameters
mInput matrix. The matrix \( \mathbf{M} \).
Returns
The determinant \( \det(\mathbf{M}) \).

Definition at line 95 of file det.hpp.

◆ det_in_place()

template<Matrix M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<M> and is_blas_lapack_v<get_value_t<M>>)
auto nda::linalg::det_in_place ( M && m)

#include <nda/linalg/det.hpp>

Compute the determinant of an \( n \times n \) matrix \( \mathbf{M} \).

For small matrices ( \( n < 4 \)), it uses optimized inline implementations.

For larger matrices, it calls nda::lapack::getrf and calculates the determinant from its LU decomposition.

It throws an exception if the call to nda::lapack::getrf fails.

Note
The matrix \( \mathbf{M} \) is modified if its number of rows/columns is greater than 3.
Template Parameters
Mnda::Matrix type.
Parameters
mInput/output matrix. On entry, the matrix \( \mathbf{M} \). On exit, the matrix \( \mathbf{M} \) or the LU decomposition of \( \mathbf{M} \) from nda::lapack::getrf.
Returns
The determinant \( \det(\mathbf{M}) \).

Definition at line 48 of file det.hpp.

◆ dot()

template<typename X, typename Y>
requires ((Scalar<X> and Scalar<Y>) or (Vector<X> and Vector<Y>))
auto nda::linalg::dot ( X const & x,
Y const & y )

#include <nda/linalg/dot.hpp>

Compute the dot product of two nda::vector objects or the product of two scalars.

The behaviour of this function is identical to nda::blas::dot, except that it allows

  • the two input objects to be scalars,
  • lazy expressions as input vectors,
  • the value types of the input vectors to be different from each other and
  • the value types of the input vectors to be different from nda::is_double_or_complex_v.

For vectors, it calls nda::blas::dot if possible, otherwise it simply loops over the input arrays/views and sums up the element-wise products.

Note
The first argument is never conjugated. Even for complex types. Use nda::linalg::dotc for that.
Template Parameters
Xnda::Vector or nda::Scalar type.
Ynda::Vector or nda::Scalar type.
Parameters
xInput vector/scalar.
yInput vector/scalar.
Returns
Result of the dot product.

Definition at line 104 of file dot.hpp.

◆ dot_generic()

template<bool star = false, Vector X, Vector Y>
requires (Scalar<get_value_t<X>> and Scalar<get_value_t<Y>> and mem::have_host_compatible_addr_space<X, Y>)
auto nda::linalg::dot_generic ( X const & x,
Y const & y )

#include <nda/linalg/dot.hpp>

Generic loop-based dot product implementation for vectors.

Computes the dot product of two vector objects with optional conjugation:

  • For star = false: result = sum(x[i] * y[i])
  • For star = true: result = sum(conj(x[i]) * y[i]) for complex types
Template Parameters
starIf true, conjugate the first operand (for complex types only).
XVector type.
YVector type.
Parameters
xFirst input vector.
ySecond input vector.
Returns
The computed dot product.

Definition at line 45 of file dot.hpp.

◆ dotc()

template<typename X, typename Y>
requires ((Scalar<X> and Scalar<Y>) or (Vector<X> and Vector<Y>))
auto nda::linalg::dotc ( X const & x,
Y const & y )

#include <nda/linalg/dot.hpp>

Compute the dotc (LHS operand is conjugated) product of two nda::vector objects or the product of two scalars.

The behaviour of this function is identical to nda::blas::dotc, except that it allows

  • the two input objects to be scalars,
  • lazy expressions as input vectors,
  • the value types of the input vectors to be different from each other and
  • the value types of the input vectors to be different from nda::is_double_or_complex_v.

For vectors, it calls nda::blas::dotc if possible, otherwise it simply loops over the input arrays/views and sums up the element-wise products with the LHS operand conjugated.

Template Parameters
Xnda::Vector or nda::Scalar type.
Ynda::Vector or nda::Scalar type.
Parameters
xInput vector/scalar.
yInput vector/scalar.
Returns
Result of the dotc product.

Definition at line 135 of file dot.hpp.

◆ eigh() [1/2]

template<Matrix A>
requires (Scalar<get_value_t<A>>)
auto nda::linalg::eigh ( A const & a)

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues and eigenvectors of a real symmetric or complex hermitian matrix.

It computes the eigenvectors \( \mathbf{v}_i \) and eigenvalues \( \lambda_i \) of the matrix \(\mathbf{A} \) such that

\[ \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \; . \]

It makes a copy of the given matrix/view and calls nda::linalg::eigh_in_place with the copy.

Template Parameters
Anda::Matrix type.
Parameters
aInput matrix. The matrix \( \mathbf{A} \).
Returns
std::pair containing an nda::array with the real eigenvalues \( \lambda_i \) in ascending order and an nda::matrix in nda::F_layout containing the eigenvectors \( \mathbf{v}_i \) in its columns.

Definition at line 162 of file eigh.hpp.

◆ eigh() [2/2]

template<Matrix A, Matrix B>
requires (Scalar<get_value_t<A>> and Scalar<get_value_t<B>>)
auto nda::linalg::eigh ( A const & a,
B const & b,
int itype = 1 )

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues and eigenvectors of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.

It computes the eigenvectors \( \mathbf{v}_i \) and eigenvalues \( \lambda_i \) of one of the following eigenvalue problems:

  • \( \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{B} \mathbf{v}_i \) (itype = 1),
  • \( \mathbf{A} \mathbf{B} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 2) or
  • \( \mathbf{B} \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 3).

It makes a copy of the given matrices/views and calls nda::linalg::eigh_in_place(A &&, B&&, int) with the copies.

Template Parameters
Anda::Matrix type.
Bnda::Matrix type.
Parameters
aInput matrix. The matrix \( \mathbf{A} \).
bInput matrix. The matrix \( \mathbf{B} \).
itypeSpecifies the problem to be solved.
Returns
std::pair containing an nda::array with the real eigenvalues \( \lambda_i \) in ascending order and an nda::matrix in nda::F_layout containing the eigenvectors \( \mathbf{v}_i \) in its columns.

Definition at line 191 of file eigh.hpp.

◆ eigh_in_place() [1/2]

auto nda::linalg::eigh_in_place ( A && a)

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues and eigenvectors of a real symmetric or complex hermitian matrix.

It computes the eigenvectors \( \mathbf{v}_i \) and eigenvalues \( \lambda_i \) of the matrix \(\mathbf{A} \) such that

\[ \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \; . \]

If the elements of \( \mathbf{A} \) are real, it calls nda::lapack::syev. If the elements of \( \mathbf{A} \) are complex, it calls nda::lapack::heev.

It throws an exception if the call to LAPACK fails.

Note
The given matrix/view must have Fortran layout, is modified and contains the eigenvectors in its columns after the call.
Template Parameters
Anda::MemoryMatrix type.
Parameters
aInput/output matrix. On entry, the matrix \( \mathbf{A} \). On exit, it contains the orthonormal eigenvectors \( \mathbf{v}_i \) in its columns.
Returns
An nda::array containing the real eigenvalues \( \lambda_i \) in ascending order.

Definition at line 104 of file eigh.hpp.

◆ eigh_in_place() [2/2]

template<MemoryMatrix A, MemoryMatrix B>
requires (nda::mem::have_host_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>> and have_same_value_type_v<A, B> and nda::blas::has_F_layout<A> and nda::blas::has_F_layout<B>)
auto nda::linalg::eigh_in_place ( A && a,
B && b,
int itype = 1 )

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues and eigenvectors of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.

It computes the eigenvectors \( \mathbf{v}_i \) and eigenvalues \( \lambda_i \) of one of the following eigenvalue problems:

  • \( \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{B} \mathbf{v}_i \) (itype = 1),
  • \( \mathbf{A} \mathbf{B} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 2) or
  • \( \mathbf{B} \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 3).

Here \( \mathbf{A} \) and \( \mathbf{B} \) are assumed to be real symmetric or complex hermitian. In addition, \( \mathbf{B} \) is assumed to be positive definite.

If \( \mathbf{A} \) and \( \mathbf{B} \) are real, it calls nda::lapack::sygv. Otherwise, it calls nda::lapack::hegv.

It throws an exception if the call to LAPACK fails.

Note
The given matrices/views must have Fortran layout and are modified.
Template Parameters
Anda::MemoryMatrix type.
Bnda::MemoryMatrix type.
Parameters
aInput/output matrix. On entry, the matrix \( \mathbf{A} \). On exit, it contains the normalized eigenvectors \( \mathbf{v}_i \) in its columns (see nda::lapack::sygv or nda::lapack::hegv for details).
bInput/output matrix. On entry, the matrix \( \mathbf{B} \). On exit, it is overwritten (see nda::lapack::sygv or nda::lapack::hegv for details).
itypeSpecifies the problem to be solved.
Returns
An nda::array containing the real eigenvalues \( \lambda_i \) in ascending order.

Definition at line 140 of file eigh.hpp.

◆ eigvalsh() [1/2]

template<Matrix A>
requires (Scalar<get_value_t<A>>)
auto nda::linalg::eigvalsh ( A const & a)

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues of a real symmetric or complex hermitian matrix.

It computes the eigenvalues \( \lambda_i \) of the matrix \( \mathbf{A} \) such that

\[ \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \; . \]

It makes a copy of the given matrix/view and calls nda::linalg::eigvalsh_in_place with the copy.

Template Parameters
Anda::Matrix type.
Parameters
aInput matrix. The matrix \( \mathbf{A} \).
Returns
An nda::array containing the real eigenvalues in ascending order.

Definition at line 276 of file eigh.hpp.

◆ eigvalsh() [2/2]

template<Matrix A, Matrix B>
requires (Scalar<get_value_t<A>> and Scalar<get_value_t<B>>)
auto nda::linalg::eigvalsh ( A const & a,
B const & b,
int itype = 1 )

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.

It computes the eigenvalues \( \lambda_i \) of one of the following eigenvalue problems:

  • \( \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{B} \mathbf{v}_i \) (itype = 1),
  • \( \mathbf{A} \mathbf{B} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 2) or
  • \( \mathbf{B} \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 3).

It makes a copy of the given matrices/views and calls nda::linalg::eigvalsh_in_place(A &&, B&&, int) with the copies.

Template Parameters
Anda::Matrix type.
Bnda::Matrix type.
Parameters
aInput matrix. The matrix \( \mathbf{A} \).
bInput matrix. The matrix \( \mathbf{B} \).
itypeSpecifies the problem to be solved.
Returns
An nda::array containing the real eigenvalues in ascending order.

Definition at line 303 of file eigh.hpp.

◆ eigvalsh_in_place() [1/2]

auto nda::linalg::eigvalsh_in_place ( A && a)

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues of a real symmetric or complex hermitian matrix.

It computes the eigenvalues \( \lambda_i \) of the matrix \( \mathbf{A} \) such that

\[ \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \; . \]

If the elements of \( \mathbf{A} \) are real, it calls nda::lapack::syev. If the elements of \( \mathbf{A} \) are complex, it calls nda::lapack::heev.

It throws an exception if the call to LAPACK fails.

Note
The given matrix/view must have Fortran layout and is modified.
Template Parameters
Anda::MemoryMatrix type.
Parameters
aInput/output matrix. On entry, the matrix \( \mathbf{A} \). On exit, the contents of \( \mathbf{A} \) are destroyed.
Returns
An nda::array containing the real eigenvalues in ascending order.

Definition at line 221 of file eigh.hpp.

◆ eigvalsh_in_place() [2/2]

template<MemoryMatrix A, MemoryMatrix B>
requires (nda::mem::have_host_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>> and have_same_value_type_v<A, B> and nda::blas::has_F_layout<A> and nda::blas::has_F_layout<B>)
auto nda::linalg::eigvalsh_in_place ( A && a,
B && b,
int itype = 1 )

#include <nda/linalg/eigh.hpp>

Compute the eigenvalues of a generalized real symmetric-definite or complex hermitian-definite eigenvalue problem.

It computes the eigenvalues \( \lambda_i \) of one of the following eigenvalue problems:

  • \( \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{B} \mathbf{v}_i \) (itype = 1),
  • \( \mathbf{A} \mathbf{B} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 2) or
  • \( \mathbf{B} \mathbf{A} \mathbf{v}_i = \lambda_i \mathbf{v}_i \) (itype = 3).

Here \( \mathbf{A} \) and \( \mathbf{B} \) are assumed to be real symmetric or complex hermitian. In addition, \( \mathbf{B} \) is assumed to be positive definite.

If \( \mathbf{A} \) and \( \mathbf{B} \) are real, it calls nda::lapack::sygv. Otherwise, it calls nda::lapack::hegv.

It throws an exception if the call to LAPACK fails.

Note
The given matrices/views must have Fortran layout and are modified.
Template Parameters
Anda::MemoryMatrix type.
Bnda::MemoryMatrix type.
Parameters
aInput/output matrix. On entry, the matrix \( \mathbf{A} \). On exit, the contents of \( \mathbf{A} \) are destroyed.
bInput/output matrix. On entry, the matrix \( \mathbf{B} \). On exit, it is overwritten (see nda::lapack::sygv or nda::lapack::hegv for details).
itypeSpecifies the problem to be solved.
Returns
An nda::array containing the real eigenvalues \( \lambda_i \) in ascending order.

Definition at line 256 of file eigh.hpp.

◆ get_lu_matrices()

template<typename LP = F_layout, MemoryMatrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and nda::blas::has_F_layout<A>)
auto nda::linalg::get_lu_matrices ( A const & a)

#include <nda/linalg/lu.hpp>

Get the \( \mathbf{L} \) and \( \mathbf{U} \) matrices from the output of nda::lapack::getrf.

If the original matrix \( \mathbf{A} \) is of size \( m \times n \), then the returned \( \mathbf{L} \) matrix is of size \( m \times k \) and \( \mathbf{U} \) is of size \( k \times n \), where \( k = \min(m, n) \).

Template Parameters
LPPolicy determining the memory layout of the \( \mathbf{L} \) and \( \mathbf{U} \) matrices.
Mnda::MemoryMatrix type.
Parameters
anda::MemoryMatrix containing the output of nda::lapack::getrf.
Returns
A tuple containing the \( \mathbf{L} \) and \( \mathbf{U} \) matrices.

Definition at line 63 of file lu.hpp.

◆ get_permutation_matrix() [1/2]

template<Scalar T, typename LP = F_layout>
auto nda::linalg::get_permutation_matrix ( Vector auto const & ipiv,
int m )

#include <nda/linalg/utils.hpp>

Get the permutation matrix \( \mathbf{P} \) from the pivot indices returned by nda::lapack::getrf or other LAPACK routines.

It simply calls nda::linalg::get_permutation_vector to get the permutation vector from the pivot indices, and then calls nda::linalg::get_permutation_matrix to get the permutation matrix.

Template Parameters
Tnda::Scalar value type of the permutation matrix.
LPPolicy determining the memory layout of the permutation matrix.
Parameters
ipivnda::Vector containing the pivot indices returned by nda::lapack::getrf.
mNumber of rows/columns of the square permutation matrix \( \mathbf{P} \).
Returns
Permutation matrix \( \mathbf{P} \) as an nda::matrix.

Definition at line 103 of file utils.hpp.

◆ get_permutation_matrix() [2/2]

template<Scalar T, typename LP = F_layout>
auto nda::linalg::get_permutation_matrix ( Vector auto const & sigma,
bool column_permutations = false )

#include <nda/linalg/utils.hpp>

Get the permutation matrix \( \mathbf{P} \) from a permutation vector \( \mathbf{\sigma} \).

The function constructs the permutation matrix \( \mathbf{P} \) of size \( m \times m \) from the permutation vector \( \sigma \) of size \( m \).

The permutation matrix only has the following non-zero elements (for all \( i = 0, 1, \ldots, m - 1 \)):

  • \( \mathbf{P}_{i, \sigma_i} = 1 \) for row permutations,
  • \( \mathbf{P}_{\sigma_i, i} = 1 \) for column permutations.
Template Parameters
Tnda::Scalar value type of the permutation matrix.
LPPolicy determining the memory layout of the permutation matrix.
Parameters
sigmanda::Vector containing the permutation vector with values \( \in \{0, 1, \ldots, m - 1 \} \).
column_permutationsIf true, constructs the permutation matrix for column permutations.
Returns
Permutation matrix \( \mathbf{P} \) as an nda::matrix.

Definition at line 81 of file utils.hpp.

◆ get_permutation_vector()

auto nda::linalg::get_permutation_vector ( Vector auto const & ipiv,
int m )

#include <nda/linalg/utils.hpp>

Get the permutation vector \( \mathbf{\sigma} \) from the pivot indices returned by nda::lapack::getrf or other LAPACK routines.

The function constructs the permutation vector \( \mathbf{\sigma} \) of size \( m \) from the pivot index vector ipiv of size \( l \). Starting from an identity permutation, i.e. \( \mathbf{\sigma} = (0, 1, \ldots, m - 1) \), it interchanges \( \sigma_i \) with \( \sigma_{\mathrm{ipiv}_i - 1} \) for all \( i = 0, 1, \dots, l - 1 \).

Parameters
ipivnda::Vector containing the pivot indices returned by nda::lapack::getrf.
mNumber of elements of the permutation vector \( \mathbf{\sigma} \).
Returns
Permutation vector \( \mathbf{\sigma} \) as an nda::vector.

Definition at line 56 of file utils.hpp.

◆ get_qr_matrices()

template<MemoryMatrix A, MemoryVector TAU>
requires (nda::mem::have_host_compatible_addr_space<A, TAU> and have_same_value_type_v<A, TAU> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::get_qr_matrices ( A const & a,
TAU const & tau,
bool complete = false )

#include <nda/linalg/qr.hpp>

Get the \( \mathbf{Q} \) and \( \mathbf{R} \) matrices from the output of nda::lapack::geqp3.

\( \mathbf{R} \) is simply the upper triangular (trapezoidal) part of the \( m \times n \) matrix \(\mathbf{A} \) returned by nda::lapack::geqp3.

\( \mathbf{Q} \) is computed from the elementary reflectors stored in the lower part of \( \mathbf{A} \) and the vector of scalar factors \( \mathbf{\tau} \) using nda::lapack::orgqr or nda::lapack::ungqr.

\( \mathbf{Q} \) has dimensions \( m \times k \) and \( \mathbf{R} \) has dimensions \( k \times n \), where \( k \) depends on the mode of the factorization:

  • reduced mode (default): \( k = \min(m, n) \).
  • complete mode: \( k = m \).
Note
\( \mathbf{Q} \) and \( \mathbf{R} \) are always in nda::F_layout.
Template Parameters
Anda::MemoryMatrix type.
TAUnda::MemoryVector type.
Parameters
aInput matrix containing the output of nda::lapack::geqp3.
tauInput vector containing the scalar factors of the elementary reflectors as returned by nda::lapack::geqp3.
completeIf true, retrieves the matrices for the complete QR factorization.
Returns
A tuple containing the \( \mathbf{Q} \) and \( \mathbf{R} \) matrices.

Definition at line 77 of file qr.hpp.

◆ inv()

template<Matrix M>
requires (get_algebra<M> == 'M' and is_blas_lapack_v<get_value_t<M>>)
auto nda::linalg::inv ( M const & m)

#include <nda/linalg/inv.hpp>

Compute the inverse of an \( n \times n \) matrix \( \mathbf{M} \).

The given matrix/view is not modified. It first makes a copy of the matrix/view and then

Warning
This function makes copies of the input arrays/views. When working on the device memory space, this may lead to runtime errors if the copying fails.
Template Parameters
Mnda::MemoryMatrix type.
Parameters
mInput matrix. The matrix \( \mathbf{M} \).
Returns
The inverse matrix \( \mathbf{M}^{-1} \).

Definition at line 141 of file inv.hpp.

◆ inv_in_place()

template<MemoryMatrix M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<M> and is_blas_lapack_v<get_value_t<M>>)
void nda::linalg::inv_in_place ( M && m)

#include <nda/linalg/inv.hpp>

Compute the inverse of an \( n \times n \) matrix \( \mathbf{M} \).

For small matrices ( \( 1 \times 1 \), \( 2 \times 2 \) or \( 3 \times 3 \)), it uses optimized direct inversion formulas.

For larger matrices, it calls nda::lapack::getrf and nda::lapack::getri.

It throws an exception if the matrix is not invertible, i.e. if \( \det(\mathbf{M}) = 0 \), or if a call to LAPACK fails.

Note
The inversion is performed in place.
Template Parameters
Mnda::MemoryMatrix type.
Parameters
mInput/output matrix. On entry, the matrix \( \mathbf{M} \). On exit, the matrix \( \mathbf{M}^{-1} \).

Definition at line 99 of file inv.hpp.

◆ lu()

auto nda::linalg::lu ( A const & a,
bool allow_singular = false )

#include <nda/linalg/lu.hpp>

Compute the LU factorization of a matrix.

It makes a copy of the input matrix \( \mathbf{A} \) and calls nda::linalg::lu_in_place.

Note
\( \mathbf{L} \) and \( \mathbf{U} \) have the same layout as the input matrix \( \mathbf{A} \).
Template Parameters
Anda::Matrix type.
Parameters
aInput matrix. The \( m \times n \) matrix \( \mathbf{A} \) to be factorized.
allow_singularIf true, allows factorization of singular matrices. If false (default), throws an error when the matrix is detected to be singular.
Returns
A tuple containing \( \mathbf{\sigma} \), \( \mathbf{L} \) and \( \mathbf{U} \).

Definition at line 148 of file lu.hpp.

◆ lu_in_place()

template<typename LP = F_layout, MemoryMatrix A>
requires (nda::mem::have_host_compatible_addr_space<A> and nda::blas::has_F_layout<A> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::lu_in_place ( A && a,
bool allow_singular = false )

#include <nda/linalg/lu.hpp>

Compute the LU factorization of a matrix in place.

The function computes the LU factorization of a general \( m \times n \) matrix \( \mathbf{A} \) using nda::lapack::getrf. The factorization has the form

\[ \mathbf{P A} = \mathbf{L U} \]

where \( \mathbf{P} \) is an \( m \times m \) permutation matrix, \( \mathbf{L} \) is an \( m \times k \) lower triangular (trapezoidal if \( m > n \)) matrix with unit diagonal elements, and \( \mathbf{U} \) is a \(k \times n \) upper triangular (trapezoidal if \( m < n \)) matrix. Here, \( k = \min(m, n) \).

\( \mathbf{P} \) is returned as a permutation vector \( \mathbf{\sigma} \) of size \( m \). See nda::linalg::get_permutation_vector for more information.

Note
\( \mathbf{A} \) must be in nda::F_layout. See nda::linalg::lu for a version that handles C-layout input. \( \mathbf{L} \) and \( \mathbf{U} \) can be returned in a different layout by specifying the LP template parameter.
Template Parameters
LPPolicy determining the memory layout of the \( \mathbf{L} \) and \( \mathbf{U} \) matrices.
Mnda::MemoryMatrix type.
Parameters
aInput/Output nda::MemoryMatrix. On entry, the \( m \times n \) matrix \( \mathbf{A} \). On exit, the result of the nda::lapack::getrf call.
allow_singularIf true, allows factorization of singular matrices. If false (default), throws an error when the matrix is detected to be singular.
Returns
A tuple containing \( \mathbf{\sigma} \), \( \mathbf{L} \) and \( \mathbf{U} \).

Definition at line 112 of file lu.hpp.

◆ matmul()

template<Matrix A, Matrix B>
auto nda::linalg::matmul ( A && a,
B && b )

#include <nda/linalg/matmul.hpp>

Compute the matrix-matrix product of two nda::matrix objects.

This function computes the matrix-matrix product

\[ \mathrm{op}_A(\mathbf{A}) \mathrm{op}_B(\mathbf{B}) \; , \]

where \( \mathrm{op}_A(\mathbf{A}) \) and \( \mathrm{op}_B(\mathbf{B}) \) are \( m \times k \) and \( k \times n \) matrices, respectively. \( \mathrm{op}_i \) can be some lazy operation, e.g. nda::conj, nda::sin, etc.

We try to call nda::blas::gemm whenever possible, i.e. when the value type of the result is compatible with nda::is_blas_lapack_v, even if this requires to make copies of the input arrays/views. Otherwise, we perform a very naive and inefficient matrix-matrix multiplication manually.

Therefore, if performance is important, users should make sure to pass input arrays/views which are compatible with nda::blas::gemm.

Note
The layout of the returned matrix depends on the layout of the input matrices. If both input matrices are in nda::F_layout, the returned matrix is also in nda::F_layout. Otherwise, it is in nda::C_layout.
Warning
This function might make copies of the input arrays/views. When working on the device memory space, this may lead to runtime errors if the copying fails.
Template Parameters
Anda::Matrix type.
Bnda::Matrix type.
Parameters
aInput matrix \( \mathrm{op}_A(\mathbf{A}) \) of size \( m \times k \).
bInput matrix \( \mathrm{op}_B(\mathbf{B}) \) of size \( k \times n \).
Returns
Resulting matrix of the matrix-matrix multiplication of size \( m \times n \).

Definition at line 128 of file matmul.hpp.

◆ matvecmul()

template<Matrix A, Vector X>
requires (mem::have_compatible_addr_space<A, X>)
auto nda::linalg::matvecmul ( A const & a,
X const & x )

#include <nda/linalg/matvecmul.hpp>

Compute the matrix-vector product of an nda::matrix and an nda::vector object.

This function computes the matrix-vector product

\[ \mathrm{op}_A(\mathbf{A}) \mathrm{op}_x(\mathbf{x}) \; , \]

where \( \mathrm{op}_A(\mathbf{A}) \) is an \( m \times n \) matrix and \( \mathrm{op}_x(\mathbf{x}) \) is a vector of size \( n \). \( \mathrm{op}_i \) can be some lazy operation, e.g. nda::conj, nda::sin, etc.

We try to call nda::blas::gemv whenever possible, i.e. when the value type of the result is compatible with nda::is_blas_lapack_v, even if this requires to make copies of the input arrays/views. Otherwise, we perform a very naive and inefficient matrix-vector multiplication manually.

Therefore, if performance is important, users should make sure to pass input arrays/views which are compatible with nda::blas::gemv.

Warning
This function might make copies of the input arrays/views. When working on the device memory space, this may lead to runtime errors if the copying fails.
Template Parameters
Anda::Matrix type.
Xnda::Vector type.
Parameters
aInput matrix \( \mathrm{op}_A(\mathbf{A}) \) of size \( m \times n \).
xInput vector \( \mathrm{op}_x(\mathbf{x}) \) of size \( n \).
Returns
Resulting vector of the matrix-vector multiplication of size \( m \).

Definition at line 119 of file matvecmul.hpp.

◆ norm()

template<ArrayOfRank< 1 > A>
requires (Scalar<get_value_t<A>>)
double nda::linalg::norm ( A const & a,
double p = 2.0 )

#include <nda/linalg/norm.hpp>

Calculate the p-norm of an nda::ArrayOfRank<1> object \( \mathbf{x} \) with scalar values. The p-norm is defined as.

\[ || \mathbf{x} ||_p = \left( \sum_{i=0}^{N-1} |x_i|^p \right)^{1/p} \]

with the special cases (following numpy.linalg.norm convention)

  • \( || \mathbf{x} ||_0 = \text{number of non-zero elements} \),
  • \( || \mathbf{x} ||_{\infty} = \max \{ |x_i| : i = 0, \dots, N - 1 \} \),
  • \( || \mathbf{x} ||_{-\infty} = \min \{ |x_i| : i = 0, \dots, N - 1 \} \).
Template Parameters
Anda::ArrayOfRank<1> type.
Parameters
anda::ArrayOfRank<1> object \( \mathbf{x} \).
pOrder of the norm.
Returns
p-norm of the array/view.

Definition at line 46 of file norm.hpp.

◆ outer_product()

template<MemoryArray A, MemoryArray B>
requires ((nda::blas::has_C_layout<A> or nda::blas::has_F_layout<A>) and nda::blas::has_C_layout<A> == nda::blas::has_C_layout<B>)
auto nda::linalg::outer_product ( A const & a,
B const & b )

#include <nda/linalg/outer_product.hpp>

Outer product of two arrays/views.

It calculates the outer product \( \mathbf{C} = \mathbf{A} \otimes \mathbf{B} \), such that

\[ \mathbf{C}_{i_1 \ldots i_k j_1 \ldots j_l} = \mathbf{A}_{i_1 \ldots i_k} \mathbf{B}_{j_1 \ldots j_l} \; . \]

Here, \( \mathbf{A} \) and \( \mathbf{B} \) are the input arrays with shape \( (m_1, \ldots, m_k) \) and \((n_1, \ldots, n_l) \), respectively. The resulting array \( \mathbf{C} \) has shape \( (m_1, \ldots, m_k, n_1, \ldots, n_l) \).

The outer product is performed by calling nda::blas::ger, which imposes various constraints on the supported input arrays/views, e.g.

See nda::blas::ger for more details.

Template Parameters
Anda::MemoryArray type.
Bnda::MemoryArray type.
Parameters
aInput array/view \( \mathbf{A} \).
bInput array/view \( \mathbf{B} \).
Returns
Outer product \( \mathbf{A} \otimes \mathbf{B} \).

Definition at line 52 of file outer_product.hpp.

◆ qr()

auto nda::linalg::qr ( A const & a,
bool complete = false )

#include <nda/linalg/qr.hpp>

Compute the QR factorization of a matrix.

It makes a copy of the input matrix \( \mathbf{A} \) and calls nda::linalg::qr_in_place.

Note
\( \mathbf{Q} \) and \( \mathbf{R} \) have the same layout as the input matrix \( \mathbf{A} \).
Template Parameters
Anda::Matrix type.
Parameters
aInput matrix. The \( m \times n \) matrix \( \mathbf{A} \) to be factorized.
completeIf true, computes the complete QR factorization. See nda::linalg::qr_in_place for details.
Returns
A tuple containing \( \mathbf{\sigma} \), \( \mathbf{Q} \) and \( \mathbf{R} \).

Definition at line 165 of file qr.hpp.

◆ qr_in_place()

auto nda::linalg::qr_in_place ( A && a,
bool complete = false )

#include <nda/linalg/qr.hpp>

Compute the QR factorization of a matrix in place.

The function computes the QR factorization of a general \( m \times n \) matrix \( \mathbf{A} \) using nda::lapack::geqp3 and nda::lapack::orgqr or nda::lapack::ungqr. The factorization has the form

\[ \mathbf{A P} = \mathbf{Q R} \]

where \( \mathbf{P} \) is a \( k \times k \) permutation matrix, \( \mathbf{Q} \) is an \( m \times k \) (orthogonal/unitary if \( k = m \)) matrix, and \( \mathbf{R} \) is a \( k \times n \) upper triangular (trapezoidal if \( k < n \)) matrix.

The dimension \( k \) depends on the mode of the factorization:

  • reduced mode (default): \( k = \min(m, n) \).
  • complete mode: \( k = m \).

    \( \mathbf{P} \) is returned as a permutation vector \( \mathbf{\sigma} \) of size \( n \). See nda::linalg::get_permutation_vector for more information.

Note
\( \mathbf{A} \), \( \mathbf{Q} \) and \( \mathbf{R} \) are always in nda::F_layout. See nda::linalg::qr for a version that accepts and returns matrices in nda::C_layout as well.
Template Parameters
Anda::MemoryMatrix type.
Parameters
aInput/Output matrix. On entry, the \( m \times n \) matrix \( \mathbf{A} \). On exit, the result of the nda::lapack::geqp3 call.
completeIf true, computes the complete QR factorization.
Returns
A tuple containing \( \mathbf{\sigma} \), \( \mathbf{Q} \) and \( \mathbf{R} \).

Definition at line 131 of file qr.hpp.

◆ solve()

template<Matrix A, Array B>
requires (have_same_value_type_v<A, B> and nda::mem::have_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::solve ( A const & a,
B const & b )

#include <nda/linalg/solve.hpp>

Solve a system of linear equations.

The function solves a system of linear equations

  • \( \mathbf{A X} = \mathbf{B} \) or
  • \( \mathbf{A x} = \mathbf{b} \),

with a general \( n \times n \) matrix \( \mathbf{A} \) and either

  • \( n \times m \) matrices \( \mathbf{X} \) and \( \mathbf{B} \) or
  • vectors \( \mathbf{x} \) and \( \mathbf{b} \) of size \( n \).

It calls nda::linalg::solve_in_place with a copy of the input matrix \( \mathbf{A} \) and the right hand side matrix \( \mathbf{B} \) or vector \( \mathbf{b} \).

Note
The solution matrix \( \mathbf{X} \) is always in nda::F_layout.
Warning
This function makes copies of the input arrays/views. When working on the device memory space, this may lead to runtime errors if the copying fails.
Template Parameters
Anda::Matrix type.
Bnda::Array type of rank 1 or 2.
Parameters
aThe \( n \times n \) matrix \( \mathbf{A} \) determining the linear system.
bRight hand side matrix \( \mathbf{B} \) or vector \( \mathbf{b} \).
Returns
Solution matrix \( \mathbf{X} \) or vector \( \mathbf{x} \).

Definition at line 126 of file solve.hpp.

◆ solve_in_place()

template<MemoryMatrix A, MemoryArray B>
requires (have_same_value_type_v<A, B> and nda::mem::have_compatible_addr_space<A, B> and is_blas_lapack_v<get_value_t<A>>)
void nda::linalg::solve_in_place ( A && a,
B && b )

#include <nda/linalg/solve.hpp>

Solve a system of linear equations in-place.

The function solves a system of linear equations

  • \( \mathbf{A X} = \mathbf{B} \) or
  • \( \mathbf{A x} = \mathbf{b} \),

with a general \( n \times n \) matrix \( \mathbf{A} \) and either

  • \( n \times m \) matrices \( \mathbf{X} \) and \( \mathbf{B} \) or
  • vectors \( \mathbf{x} \) and \( \mathbf{b} \) of size \( n \).

It uses nda::lapack::getrf to compute the LU factorization of the matrix \( \mathbf{A} \) and then nda::lapack::getrs to solve the system of linear equations.

An exception is thrown, if the LAPACK calls return a non-zero value.

Note
Right hand side matrix \( \mathbf{B} \) must have nda::F_layout.
Template Parameters
Anda::MemoryMatrix type.
Bnda::MemoryArray type of rank 1 or 2.
Parameters
aInput/Output matrix. On entry, the \( n \times n \) matrix \( \mathbf{A} \) determining the linear system. On exit, contains the LU factorization as calculated by nda::lapack::getrf.
bInput/Output array. On entry, the right hand side matrix \( \mathbf{B} \) or vector \( \mathbf{b} \). On exit, contains the solution matrix \( \mathbf{X} \) or vector \( \mathbf{x} \).

Definition at line 75 of file solve.hpp.

◆ svd()

template<Matrix A>
requires (is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::svd ( A const & a)

#include <nda/linalg/svd.hpp>

Compute the singular value decomposition (SVD) of a matrix.

The function computes the SVD of a given \( m \times n \) matrix \( \mathbf{A} \):

\[ \mathbf{A} = \mathbf{U} \mathbf{S} \mathbf{V}^H \; , \]

where \( \mathbf{U} \) is a unitary \( m \times m \) matrix, \( \mathbf{V} \) is a unitary \( n \times n \) matrix and \( \mathbf{S} \) is an \( m \times n \) matrix with non-negative real numbers on the diagonal.

It calls nda::linalg::svd_in_place with a copy of the input matrix \( \mathbf{A} \).

Note
If the input matrix \( \mathbf{A} \) is in nda::F_layout, the output matrices \( \mathbf{U} \) and \( \mathbf{V}^H \) are also in nda::F_layout. Otherwise, they are in nda::C_layout.
Warning
This function makes copies of the input arrays/views. When working on the device memory space, this may lead to runtime errors if the copying fails.
Template Parameters
Anda::MemoryMatrix type.
Parameters
aInput matrix \( \mathbf{A} \).
Returns
std::tuple containing \( \mathbf{U} \), \( \mathbf{s} \) and \( \mathbf{V}^H \).

Definition at line 114 of file svd.hpp.

◆ svd_in_place()

template<MemoryMatrix A>
requires (is_blas_lapack_v<get_value_t<A>>)
auto nda::linalg::svd_in_place ( A && a)

#include <nda/linalg/svd.hpp>

Compute the singular value decomposition (SVD) of a matrix in place.

The function computes the SVD of a given \( m \times n \) matrix \( \mathbf{A} \):

\[ \mathbf{A} = \mathbf{U} \mathbf{S} \mathbf{V}^H \; , \]

where \( \mathbf{U} \) is a unitary \( m \times m \) matrix, \( \mathbf{V} \) is a unitary \( n \times n \) matrix and \( \mathbf{S} \) is an \( m \times n \) matrix with non-negative real numbers on the diagonal.

It first constructs the output vector \( \mathbf{s} \), which contains the singular values, and the output matrices \( \mathbf{U} \) and \( \mathbf{V}^H \). It then calls nda::lapack::gesvd to compute the SVD.

An exception is thrown, if the LAPACK call returns a non-zero value.

Note
If the input matrix \( \mathbf{A} \) is in nda::F_layout, the output matrices \( \mathbf{U} \) and \( \mathbf{V}^H \) are also in nda::F_layout. Otherwise, they are in nda::C_layout.
Template Parameters
Anda::MemoryMatrix type.
Parameters
aInput/output matrix. On entry, the \( m \times n \) matrix \( \mathbf{A} \). On exit, the contents of \( \mathbf{A} \) are destroyed.
Returns
std::tuple containing \( \mathbf{U} \), \( \mathbf{s} \) and \( \mathbf{V}^H \).

Definition at line 73 of file svd.hpp.