|
TRIQS/nda 1.3.0
Multi-dimensional array library for C++
|
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. | |
| 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} \).
| X | nda::Vector type. |
| Y | nda::Vector type. |
| x | Input vector \( \mathbf{x} \). |
| y | Input vector \( \mathbf{y} \). |
Definition at line 35 of file cross_product.hpp.
| 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.
| M | nda::MemoryMatrix type. |
| m | Input matrix. The matrix \( \mathbf{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.
| M | nda::Matrix type. |
| m | Input/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. |
| 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
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.
| X | nda::Vector or nda::Scalar type. |
| Y | nda::Vector or nda::Scalar type. |
| x | Input vector/scalar. |
| y | Input vector/scalar. |
| 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:
| star | If true, conjugate the first operand (for complex types only). |
| X | Vector type. |
| Y | Vector type. |
| x | First input vector. |
| y | Second input vector. |
| 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
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.
| X | nda::Vector or nda::Scalar type. |
| Y | nda::Vector or nda::Scalar type. |
| x | Input vector/scalar. |
| y | Input vector/scalar. |
| 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.
| A | nda::Matrix type. |
| a | Input matrix. The matrix \( \mathbf{A} \). |
| 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:
It makes a copy of the given matrices/views and calls nda::linalg::eigh_in_place(A &&, B&&, int) with the copies.
| A | nda::Matrix type. |
| B | nda::Matrix type. |
| a | Input matrix. The matrix \( \mathbf{A} \). |
| b | Input matrix. The matrix \( \mathbf{B} \). |
| itype | Specifies the problem to be solved. |
| 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.
| A | nda::MemoryMatrix type. |
| a | Input/output matrix. On entry, the matrix \( \mathbf{A} \). On exit, it contains the orthonormal eigenvectors \( \mathbf{v}_i \) in its columns. |
| 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:
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.
| A | nda::MemoryMatrix type. |
| B | nda::MemoryMatrix type. |
| a | Input/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). |
| b | Input/output matrix. On entry, the matrix \( \mathbf{B} \). On exit, it is overwritten (see nda::lapack::sygv or nda::lapack::hegv for details). |
| itype | Specifies the problem to be solved. |
| 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.
| A | nda::Matrix type. |
| a | Input matrix. The matrix \( \mathbf{A} \). |
| 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:
It makes a copy of the given matrices/views and calls nda::linalg::eigvalsh_in_place(A &&, B&&, int) with the copies.
| A | nda::Matrix type. |
| B | nda::Matrix type. |
| a | Input matrix. The matrix \( \mathbf{A} \). |
| b | Input matrix. The matrix \( \mathbf{B} \). |
| itype | Specifies the problem to be solved. |
| 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.
| A | nda::MemoryMatrix type. |
| a | Input/output matrix. On entry, the matrix \( \mathbf{A} \). On exit, the contents of \( \mathbf{A} \) are destroyed. |
| 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:
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.
| A | nda::MemoryMatrix type. |
| B | nda::MemoryMatrix type. |
| a | Input/output matrix. On entry, the matrix \( \mathbf{A} \). On exit, the contents of \( \mathbf{A} \) are destroyed. |
| b | Input/output matrix. On entry, the matrix \( \mathbf{B} \). On exit, it is overwritten (see nda::lapack::sygv or nda::lapack::hegv for details). |
| itype | Specifies the problem to be solved. |
| 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) \).
| LP | Policy determining the memory layout of the \( \mathbf{L} \) and \( \mathbf{U} \) matrices. |
| M | nda::MemoryMatrix type. |
| a | nda::MemoryMatrix containing the output of nda::lapack::getrf. |
| 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.
| T | nda::Scalar value type of the permutation matrix. |
| LP | Policy determining the memory layout of the permutation matrix. |
| ipiv | nda::Vector containing the pivot indices returned by nda::lapack::getrf. |
| m | Number of rows/columns of the square permutation matrix \( \mathbf{P} \). |
| 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 \)):
| T | nda::Scalar value type of the permutation matrix. |
| LP | Policy determining the memory layout of the permutation matrix. |
| sigma | nda::Vector containing the permutation vector with values \( \in \{0, 1, \ldots, m - 1 \} \). |
| column_permutations | If true, constructs the permutation matrix for column permutations. |
| 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 \).
| ipiv | nda::Vector containing the pivot indices returned by nda::lapack::getrf. |
| m | Number of elements of the permutation vector \( \mathbf{\sigma} \). |
| 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:
| A | nda::MemoryMatrix type. |
| TAU | nda::MemoryVector type. |
| a | Input matrix containing the output of nda::lapack::geqp3. |
| tau | Input vector containing the scalar factors of the elementary reflectors as returned by nda::lapack::geqp3. |
| complete | If true, retrieves the matrices for the complete QR factorization. |
| 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
| M | nda::MemoryMatrix type. |
| m | Input matrix. The matrix \( \mathbf{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.
| M | nda::MemoryMatrix type. |
| m | Input/output matrix. On entry, the matrix \( \mathbf{M} \). On exit, the matrix \( \mathbf{M}^{-1} \). |
| 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.
| A | nda::Matrix type. |
| a | Input matrix. The \( m \times n \) matrix \( \mathbf{A} \) to be factorized. |
| allow_singular | If true, allows factorization of singular matrices. If false (default), throws an error when the matrix is detected to be singular. |
| 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.
| LP | Policy determining the memory layout of the \( \mathbf{L} \) and \( \mathbf{U} \) matrices. |
| M | nda::MemoryMatrix type. |
| a | Input/Output nda::MemoryMatrix. On entry, the \( m \times n \) matrix \( \mathbf{A} \). On exit, the result of the nda::lapack::getrf call. |
| allow_singular | If true, allows factorization of singular matrices. If false (default), throws an error when the matrix is detected to be singular. |
| 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.
| A | nda::Matrix type. |
| B | nda::Matrix type. |
| a | Input matrix \( \mathrm{op}_A(\mathbf{A}) \) of size \( m \times k \). |
| b | Input matrix \( \mathrm{op}_B(\mathbf{B}) \) of size \( k \times n \). |
Definition at line 128 of file matmul.hpp.
| 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.
| A | nda::Matrix type. |
| X | nda::Vector type. |
| a | Input matrix \( \mathrm{op}_A(\mathbf{A}) \) of size \( m \times n \). |
| x | Input vector \( \mathrm{op}_x(\mathbf{x}) \) of size \( n \). |
Definition at line 119 of file matvecmul.hpp.
| 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)
| A | nda::ArrayOfRank<1> type. |
| a | nda::ArrayOfRank<1> object \( \mathbf{x} \). |
| p | Order of the norm. |
| 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.
| A | nda::MemoryArray type. |
| B | nda::MemoryArray type. |
| a | Input array/view \( \mathbf{A} \). |
| b | Input array/view \( \mathbf{B} \). |
Definition at line 52 of file outer_product.hpp.
| 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.
| A | nda::Matrix type. |
| a | Input matrix. The \( m \times n \) matrix \( \mathbf{A} \) to be factorized. |
| complete | If true, computes the complete QR factorization. See nda::linalg::qr_in_place for details. |
| 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:
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.
| A | nda::MemoryMatrix type. |
| a | Input/Output matrix. On entry, the \( m \times n \) matrix \( \mathbf{A} \). On exit, the result of the nda::lapack::geqp3 call. |
| complete | If true, computes the complete QR factorization. |
| 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
with a general \( n \times n \) matrix \( \mathbf{A} \) and either
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} \).
| A | nda::Matrix type. |
| B | nda::Array type of rank 1 or 2. |
| a | The \( n \times n \) matrix \( \mathbf{A} \) determining the linear system. |
| b | Right hand side matrix \( \mathbf{B} \) or vector \( \mathbf{b} \). |
| 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
with a general \( n \times n \) matrix \( \mathbf{A} \) and either
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.
| A | nda::MemoryMatrix type. |
| B | nda::MemoryArray type of rank 1 or 2. |
| a | Input/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. |
| b | Input/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} \). |
| 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} \).
| A | nda::MemoryMatrix type. |
| a | Input matrix \( \mathbf{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.
| A | nda::MemoryMatrix type. |
| a | Input/output matrix. On entry, the \( m \times n \) matrix \( \mathbf{A} \). On exit, the contents of \( \mathbf{A} \) are destroyed. |