TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Norms and other numbers

Detailed Description

Functions to compute various norms of arrays and views as well as other numbers like determinants.

Functions

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<blas_lapack::BlasArray< 2 > M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<M>)
auto nda::linalg::det_in_place (M &&m)
 Compute the determinant of an \( n \times n \) matrix \( \mathbf{M} \) in place.
template<ArrayOfRank< 1 > X>
requires (Scalar<get_value_t<X>>)
double nda::linalg::norm (X const &x, double p=2.0)
 Calculate the \( p \)-norm of a 1-dimensional array/view with scalar elements.

Function Documentation

◆ 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.

Note
\( \mathbf{M} \) is required to satisfy nda::mem::have_host_compatible_addr_space, to have algebra 'M' and to have a value type that satisfies nda::is_blas_lapack_v.
Template Parameters
Mnda::Matrix type.
Parameters
mInput matrix \( \mathbf{M} \).
Returns
The determinant \( \det(\mathbf{M}) \).

Definition at line 99 of file det.hpp.

◆ det_in_place()

template<blas_lapack::BlasArray< 2 > M>
requires (get_algebra<M> == 'M' and nda::mem::have_host_compatible_addr_space<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} \) in place.

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.

An exception is thrown, if the call to nda::lapack::getrf fails.

Note
\( \mathbf{M} \) is required to satisfy nda::mem::have_host_compatible_addr_space and to have algebra 'M'. It is modified if \( n \geq 4 \).
Template Parameters
Mnda::blas_lapack::BlasArray<2> type.
Parameters
mInput/output matrix. On entry, the matrix \( \mathbf{M} \). On exit, the matrix \( \mathbf{M} \) ( \(n < 4 \)) or the LU decomposition from nda::lapack::getrf ( \( n \geq 4 \)).
Returns
The determinant \( \det(\mathbf{M}) \).

Definition at line 49 of file det.hpp.

◆ norm()

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

#include <nda/linalg/norm.hpp>

Calculate the \( p \)-norm of a 1-dimensional array/view with scalar elements.

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 \} \).
Note
\( \mathbf{x} \) is required to have a value type that satisfies nda::Scalar.
Template Parameters
Xnda::ArrayOfRank<1> type.
Parameters
x1-dimensional array \( \mathbf{x} \).
pOrder of the norm.
Returns
\( p \)-norm of the array/view.

Definition at line 49 of file norm.hpp.