|
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<typename V> | |
| auto | nda::linalg::cross_product (V const &x, V const &y) |
| Compute the cross product of two 3-dimensional vectors. | |
|
template<typename... A> requires (nda::clef::is_any_lazy<A...>) | |
| auto | nda::clef::determinant (A &&...__a) |
| Lazy version of nda::determinant. | |
| template<typename M> | |
| auto | nda::determinant (M const &m) |
| Compute the determinant of a square matrix/view. | |
| template<typename M> requires (is_matrix_or_view_v<M>) | |
| auto | nda::determinant_in_place (M &m) |
| Compute the determinant of a square matrix/view. | |
| 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<typename M> | |
| auto | nda::linalg::eigenelements (M const &m) |
| Find the eigenvalues and eigenvectors of a symmetric (real) or hermitian (complex) matrix/view. | |
| template<typename M> | |
| auto | nda::linalg::eigenvalues (M const &m) |
| Find the eigenvalues of a symmetric (real) or hermitian (complex) matrix/view. | |
| template<typename M> | |
| auto | nda::linalg::eigenvalues_in_place (M &m) |
| Find the eigenvalues of a symmetric (real) or hermitian (complex) matrix/view. | |
|
template<typename... A> requires (nda::clef::is_any_lazy<A...>) | |
| auto | nda::clef::inverse (A &&...__a) |
| Lazy version of nda::inverse. | |
| template<Matrix M> requires (get_algebra<M> == 'M') | |
| auto | nda::inverse (M const &m) |
| Compute the inverse of an n-by-n matrix. | |
| template<MemoryMatrix M> requires (get_algebra<M> == 'M' and mem::on_host<M>) | |
| void | nda::inverse1_in_place (M &&m) |
| Compute the inverse of a 1-by-1 matrix. | |
| template<MemoryMatrix M> requires (get_algebra<M> == 'M' and mem::on_host<M>) | |
| void | nda::inverse2_in_place (M &&m) |
| Compute the inverse of a 2-by-2 matrix. | |
| template<MemoryMatrix M> requires (get_algebra<M> == 'M' and mem::on_host<M>) | |
| void | nda::inverse3_in_place (M &&m) |
| Compute the inverse of a 3-by-3 matrix. | |
| template<MemoryMatrix M> requires (get_algebra<M> == 'M') | |
| void | nda::inverse_in_place (M &&m) |
| Compute the inverse of an n-by-n matrix. | |
| template<typename A> | |
| bool | nda::is_matrix_diagonal (A const &a, bool print_error=false) |
| Check if a given array/view is diagonal, i.e. if it is square (see nda::is_matrix_square) and all the the off-diagonal elements are zero. | |
| template<typename A> | |
| bool | nda::is_matrix_square (A const &a, bool print_error=false) |
| Check if a given array/view is square, i.e. if the first dimension has the same extent as the second dimension. | |
| 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<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. | |
| auto nda::linalg::cross_product | ( | V const & | x, |
| V const & | y ) |
#include <nda/linalg/cross_product.hpp>
Compute the cross product of two 3-dimensional vectors.
| V | Vector type. |
| x | Left hand side vector. |
| y | Right hand side vector. |
Definition at line 29 of file cross_product.hpp.
| auto nda::determinant | ( | M const & | m | ) |
#include <nda/linalg/det_and_inverse.hpp>
Compute the determinant of a square matrix/view.
The given matrix/view is not modified. It first makes a copy of the given matrix/view and then calls nda::determinant_in_place with the copy.
| M | Type of the matrix/view. |
| m | Matrix/view object. |
Definition at line 132 of file det_and_inverse.hpp.
| auto nda::determinant_in_place | ( | M & | m | ) |
#include <nda/linalg/det_and_inverse.hpp>
Compute the determinant of a square matrix/view.
It uses nda::lapack::getrf to compute the LU decomposition of the matrix and then calculates the determinant by multiplying the diagonal elements of the \( \mathbf{U} \) matrix and taking into account that getrf may change the ordering of the rows/columns of the matrix.
The given matrix/view is modified in place.
| M | Type of the matrix/view. |
| m | Matrix/view object. |
Definition at line 89 of file det_and_inverse.hpp.
| 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::eigenelements | ( | M const & | m | ) |
#include <nda/linalg/eigenelements.hpp>
Find the eigenvalues and eigenvectors of a symmetric (real) or hermitian (complex) matrix/view.
For a real symmetric matrix/view, it calls the LAPACK routine syev. For a complex hermitian matrix/view, it calls the LAPACK routine heev.
The given matrix/view is copied and the original is not modified.
| M | Type of the matrix/view. |
| m | Matrix/View to diagonalize. |
Definition at line 87 of file eigenelements.hpp.
| auto nda::linalg::eigenvalues | ( | M const & | m | ) |
#include <nda/linalg/eigenelements.hpp>
Find the eigenvalues of a symmetric (real) or hermitian (complex) matrix/view.
For a real symmetric matrix/view, it calls the LAPACK routine syev. For a complex hermitian matrix/view, it calls the LAPACK routine heev.
The given matrix/view is copied and the original is not modified.
| M | Type of the matrix/view. |
| m | Matrix/View to diagonalize. |
Definition at line 106 of file eigenelements.hpp.
| auto nda::linalg::eigenvalues_in_place | ( | M & | m | ) |
#include <nda/linalg/eigenelements.hpp>
Find the eigenvalues of a symmetric (real) or hermitian (complex) matrix/view.
For a real symmetric matrix/view, it calls the LAPACK routine syev. For a complex hermitian matrix/view, it calls the LAPACK routine heev.
The given matrix/view will be modified by the diagonalization process.
| M | Type of the matrix/view. |
| m | Matrix/View to diagonalize. |
Definition at line 124 of file eigenelements.hpp.
| auto nda::inverse | ( | M const & | m | ) |
#include <nda/linalg/det_and_inverse.hpp>
Compute the inverse of an n-by-n matrix.
The given matrix/view is not modified. It first makes copy of the given matrix/view and then calls nda::inverse_in_place with the copy.
| M | nda::MemoryMatrix type. |
| m | nda::MemoryMatrix object to be inverted. |
Definition at line 286 of file det_and_inverse.hpp.
| void nda::inverse1_in_place | ( | M && | m | ) |
#include <nda/linalg/det_and_inverse.hpp>
Compute the inverse of a 1-by-1 matrix.
The inversion is performed in place.
| M | nda::MemoryMatrix type. |
| m | nda::MemoryMatrix object to be inverted. |
Definition at line 158 of file det_and_inverse.hpp.
| void nda::inverse2_in_place | ( | M && | m | ) |
#include <nda/linalg/det_and_inverse.hpp>
Compute the inverse of a 2-by-2 matrix.
The inversion is performed in place.
| M | nda::MemoryMatrix type. |
| m | nda::MemoryMatrix object to be inverted. |
Definition at line 173 of file det_and_inverse.hpp.
| void nda::inverse3_in_place | ( | M && | m | ) |
#include <nda/linalg/det_and_inverse.hpp>
Compute the inverse of a 3-by-3 matrix.
The inversion is performed in place.
| M | nda::MemoryMatrix type. |
| m | nda::MemoryMatrix object to be inverted. |
Definition at line 199 of file det_and_inverse.hpp.
| void nda::inverse_in_place | ( | M && | m | ) |
#include <nda/linalg/det_and_inverse.hpp>
Compute the inverse of an n-by-n matrix.
The inversion is performed in place.
For small matrices (1-by-1, 2-by-2, 3-by-3), we directly compute the matrix inversion using the optimized routines: nda::inverse1_in_place, nda::inverse2_in_place, nda::inverse3_in_place.
For larger matrices, it uses nda::lapack::getrf and nda::lapack::getri.
| M | nda::MemoryMatrix type. |
| m | nda::MemoryMatrix object to be inverted. |
Definition at line 243 of file det_and_inverse.hpp.
| bool nda::is_matrix_diagonal | ( | A const & | a, |
| bool | print_error = false ) |
#include <nda/linalg/det_and_inverse.hpp>
Check if a given array/view is diagonal, i.e. if it is square (see nda::is_matrix_square) and all the the off-diagonal elements are zero.
| A | Array/View type. |
| a | Array/View object. |
| print_error | If true, print an error message if the matrix is not diagonal. |
Definition at line 69 of file det_and_inverse.hpp.
| bool nda::is_matrix_square | ( | A const & | a, |
| bool | print_error = false ) |
#include <nda/linalg/det_and_inverse.hpp>
Check if a given array/view is square, i.e. if the first dimension has the same extent as the second dimension.
| A | Array/View type. |
| a | Array/View object. |
| print_error | If true, print an error message if the matrix is not square. |
Definition at line 50 of file det_and_inverse.hpp.
| 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}_1(\mathbf{A}) \mathrm{op}_2(\mathbf{B}) \), where \( \mathbf{A} \) and \( \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 \( \mathbf{A} \) of size \( m \times k \). |
| b | Input matrix \( \mathbf{B} \) of size \( k \times n \). |
Definition at line 124 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}_1(\mathbf{A}) \mathrm{op}_2(\mathbf{x}) \), where \( \mathbf{A} \) is an \( m \times n \) matrix, \( \mathbf{x} \) is a vector of size \( n \), and \( \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 \( \mathbf{A} \) of size \( m \times n \). |
| x | Input vector \( \mathbf{x} \) of size \( n \). |
Definition at line 116 of file matvecmul.hpp.
| 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.