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 > | |
auto | nda::dot (X &&x, Y &&y) |
Compute the dot product of two real arrays/views. | |
template<typename X , typename Y > | |
auto | nda::dotc (X &&x, Y &&y) |
Compute the dot product of two complex arrays/views. | |
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<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::matmul (A &&a, B &&b) |
Perform a matrix-matrix multiplication. | |
template<Matrix A, Vector X> | |
auto | nda::matvecmul (A &&a, X &&x) |
Perform a matrix-vector multiplication. | |
template<ArrayOfRank< 1 > A> | |
double | nda::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. | |
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 40 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 143 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 100 of file det_and_inverse.hpp.
auto nda::dot | ( | X && | x, |
Y && | y ) |
#include <nda/linalg/dot.hpp>
Compute the dot product of two real arrays/views.
It is generic in the sense that it allows the input arrays to belong to a different nda::mem::AddressSpace (as long as they are compatible).
If possible, it uses nda::blas::dot, otherwise it calls nda::blas::dot_generic.
X | Type of the left hand side array/view. |
Y | Type of the right hand side array/view. |
x | Left hand side array/view. |
y | Right hand side array/view. |
auto nda::dotc | ( | X && | x, |
Y && | y ) |
#include <nda/linalg/dot.hpp>
Compute the dot product of two complex arrays/views.
It is generic in the sense that it allows the input arrays to belong to a different nda::mem::AddressSpace (as long as they are compatible).
If possible, it uses nda::blas::dotc, otherwise it calls nda::blas::dotc_generic.
X | Type of the left hand side array/view. |
Y | Type of the right hand side array/view. |
x | Left hand side array/view. |
y | Right hand side array/view. |
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 98 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 117 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 135 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 297 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 169 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 184 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 210 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 254 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 80 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 61 of file det_and_inverse.hpp.
auto nda::matmul | ( | A && | a, |
B && | b ) |
#include <nda/linalg/matmul.hpp>
Perform a matrix-matrix multiplication.
It is generic in the sense that it allows the input matrices to belong to a different nda::mem::AddressSpace (as long as they are compatible).
If possible, it uses nda::blas::gemm, otherwise it calls nda::blas::gemm_generic.
A | nda::Matrix type of lhs operand. |
B | nda::Matrix type of rhs operand. |
a | Left hand side matrix operand. |
b | Right hand side matrix operand. |
Definition at line 87 of file matmul.hpp.
auto nda::matvecmul | ( | A && | a, |
X && | x ) |
#include <nda/linalg/matmul.hpp>
Perform a matrix-vector multiplication.
It is generic in the sense that it allows the input matrix and vector to belong to a different nda::mem::AddressSpace (as long as they are compatible).
If possible, it uses nda::blas::gemv, otherwise it calls nda::blas::gemv_generic.
A | nda::Matrix type of lhs operand. |
X | nda::Vector type of rhs operand. |
a | Left hand side matrix operand. |
x | Right hand side vector operand. |
Definition at line 152 of file matmul.hpp.
double nda::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. |
p | Order of the norm. |