|
TRIQS/nda 2.0.0
Multi-dimensional array library for C++
|
Functions to solve linear systems of equations and to invert matrices.
Functions | |
| 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 \( \mathbf{M}^{-1} \) of an \( n \times n \) matrix \( \mathbf{M} \). | |
| template<blas_lapack::BlasArray< 2 > M> requires (get_algebra<M> == 'M' and mem::have_host_compatible_addr_space<M>) | |
| void | nda::linalg::inv_in_place (M &&m) |
| Compute the inverse \( \mathbf{M}^{-1} \) of an \( n \times n \) matrix \( \mathbf{M} \) in place. | |
| template<Matrix A, Array B> requires (have_same_value_type_v<A, B> and 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<blas_lapack::BlasArray< 2 > A, blas_lapack::BlasArrayFor< A > B> requires ((get_rank<B> == 1 || get_rank<B> == 2) and blas_lapack::has_F_layout<B>) | |
| void | nda::linalg::solve_in_place (A &&a, B &&b) |
| Solve a system of linear equations in place. | |
| auto nda::linalg::inv | ( | M const & | m | ) |
#include <nda/linalg/inv.hpp>
Compute the inverse \( \mathbf{M}^{-1} \) of an \( n \times n \) matrix \( \mathbf{M} \).
The given matrix/view is not modified. Depending on the address space of the input matrix, the function does the following:
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.
| M | nda::Matrix type. |
| m | Input matrix \( \mathbf{M} \). |
| void nda::linalg::inv_in_place | ( | M && | m | ) |
#include <nda/linalg/inv.hpp>
Compute the inverse \( \mathbf{M}^{-1} \) of an \( n \times n \) matrix \( \mathbf{M} \) in place.
For small matrices ( \( n < 4 \)), it uses optimized direct inversion formulas.
For larger matrices, it calls nda::lapack::getrf and nda::lapack::getri.
An exception is thrown, if the matrix is not invertible, i.e. if \( \det(\mathbf{M}) = 0 \), or if a LAPACK call fails.
| M | nda::blas_lapack::BlasArray<2> type. |
| m | Input/output matrix. On entry, the matrix \( \mathbf{M} \). On exit, the matrix \( \mathbf{M}^{-1} \). |
| auto nda::linalg::solve | ( | A const & | a, |
| B const & | b ) |
#include <nda/linalg/solve.hpp>
Solve a system of linear equations.
It makes a copy of the input matrix \( \mathbf{A} \) and the right hand side matrix \( \mathbf{B} \) or vector \( \mathbf{b} \) and calls nda::linalg::solve_in_place.
The solution matrix \( \mathbf{X} \) is always in nda::F_layout.
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.
| A | nda::Matrix type. |
| B | nda::Array type of rank 1 or 2. |
| a | Input matrix. The \( n \times n \) matrix \( \mathbf{A} \) determining the linear system. |
| b | Input array. 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 \( n \times n_{\mathrm{rhs}} \) 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 a LAPACK/cuSOLVER call fails.
| A | nda::blas_lapack::BlasArray<2> type. |
| B | nda::blas_lapack::BlasArrayFor 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, its 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, the solution matrix \( \mathbf{X} \) or vector \( \mathbf{x} \). |