TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Mathematical functions

Detailed Description

Various mathematical functions that can be applied to arrays and views.

Mathematical functions are (mostly) implemented as lazy expressions. That means they do not return the result right away but the following proxy object instead:

This lazy function call expression satisfies the nda::Array concept and can therefore be used to assign to or construct nda::basic_array and nda::basic_array_view objects. Another way to evaluate lazy expressions is with nda::make_regular:

// create two arrays A and B
auto A = nda::array<int, 2>({{1, 2}, {3, 4}});
auto B = nda::array<int, 2>({{5, 6}, {7, 8}});
// add them elementwise
auto ex = A + B; // ex is an nda::expr object
// evaluate the lazy expression by constructing a new array
// evaluate the lazy expression using nda::make_regular
auto D = nda::make_regular(ex);
A generic multi-dimensional array.
decltype(auto) make_regular(A &&a)
Make a given object regular.
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.

Output:

C:
[[1,4]
[9,16]]
D:
[[1,4]
[9,16]]

Classes

struct  nda::conj_f
 Wrapper for nda::conj. More...
 
struct  nda::expr_call< F, As >
 A lazy function call expression on arrays/views. More...
 
struct  nda::mapped< F >
 Functor that is returned by the nda::map function. More...
 

Functions

template<Array A>
auto nda::abs (A &&a)
 Lazy, coefficient-wise abs function for nda::Array types.
 
template<Array A>
auto nda::abs2 (A &&a)
 Lazy, coefficient-wise abs2 function for nda::Array types.
 
double nda::abs2 (double x)
 Get the squared absolute value of a double.
 
double nda::abs2 (std::complex< double > z)
 Get the squared absolute value of a std::complex<double>.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::acos (A &&a)
 Lazy, coefficient-wise acos function for non-matrix nda::Array types.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::asin (A &&a)
 Lazy, coefficient-wise asin function for non-matrix nda::Array types.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::atan (A &&a)
 Lazy, coefficient-wise atan function for non-matrix nda::Array types.
 
template<Array A>
decltype(auto) nda::conj (A &&a)
 Lazy, coefficient-wise complex conjugate function for nda::Array types.
 
template<typename T >
requires (nda::is_scalar_v<T>)
auto nda::conj (T t)
 Get the complex conjugate of a scalar.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::cos (A &&a)
 Lazy, coefficient-wise cos function for non-matrix nda::Array types.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::cosh (A &&a)
 Lazy, coefficient-wise cosh function for non-matrix nda::Array types.
 
template<ArrayOfRank< 2 > M>
ArrayOfRank< 2 > auto nda::dagger (M const &m)
 Get the conjugate transpose of 2-dimensional array/view.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::exp (A &&a)
 Lazy, coefficient-wise exp function for non-matrix nda::Array types.
 
template<Array A>
auto nda::floor (A &&a)
 Lazy, coefficient-wise floor function for nda::Array types.
 
template<ArrayOfRank< 2 > A>
double nda::frobenius_norm (A const &a)
 Calculate the Frobenius norm of a 2-dimensional array.
 
template<Array A>
auto nda::imag (A &&a)
 Lazy, coefficient-wise imag function for nda::Array types.
 
template<Array A>
auto nda::isnan (A &&a)
 Lazy, coefficient-wise isnan function for nda::Array types.
 
bool nda::isnan (std::complex< double > const &z)
 Check if a std::complex<double> is NaN.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::log (A &&a)
 Lazy, coefficient-wise log function for non-matrix nda::Array types.
 
template<class F >
mapped< F > nda::map (F f)
 Create a lazy function call expression on arrays/views.
 
template<Array A>
auto nda::pow (A &&a, double p)
 Lazy, coefficient-wise power function for nda::Array types.
 
template<typename T >
requires (std::is_integral_v<T>)
nda::pow (T x, int n)
 Calculate the integer power of an integer.
 
template<Array A>
auto nda::real (A &&a)
 Lazy, coefficient-wise real function for nda::Array types.
 
template<typename T >
requires (nda::is_scalar_v<T>)
auto nda::real (T t)
 Get the real part of a scalar.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::sin (A &&a)
 Lazy, coefficient-wise sin function for non-matrix nda::Array types.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::sinh (A &&a)
 Lazy, coefficient-wise sinh function for non-matrix nda::Array types.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::sqrt (A &&a)
 Lazy, coefficient-wise sqrt function for non-matrix nda::Array types.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::tan (A &&a)
 Lazy, coefficient-wise tan function for non-matrix nda::Array types.
 
template<Array A>
requires (get_algebra<A> != 'M')
auto nda::tanh (A &&a)
 Lazy, coefficient-wise tanh function for non-matrix nda::Array types.
 
template<ArrayOfRank< 2 > M>
auto nda::trace (M const &m)
 Get the trace of a 2-dimensional square array/view.
 

Function Documentation

◆ abs()

template<Array A>
auto nda::abs ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise abs function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 95 of file mapped_functions.hxx.

◆ abs2() [1/3]

template<Array A>
auto nda::abs2 ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise abs2 function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 148 of file mapped_functions.hxx.

◆ abs2() [2/3]

double nda::abs2 ( double x)
inline

#include <nda/mapped_functions.hpp>

Get the squared absolute value of a double.

Parameters
xDouble value.
Returns
Squared absolute value of the given double.

Definition at line 83 of file mapped_functions.hpp.

◆ abs2() [3/3]

double nda::abs2 ( std::complex< double > z)
inline

#include <nda/mapped_functions.hpp>

Get the squared absolute value of a std::complex<double>.

Parameters
zstd::complex<double> value.
Returns
Squared absolute value of the given complex number.

Definition at line 91 of file mapped_functions.hpp.

◆ acos()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::acos ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise acos function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 268 of file mapped_functions.hxx.

◆ asin()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::asin ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise asin function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 282 of file mapped_functions.hxx.

◆ atan()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::atan ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise atan function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 296 of file mapped_functions.hxx.

◆ conj() [1/2]

template<Array A>
decltype(auto) nda::conj ( A && a)

#include <nda/mapped_functions.hpp>

Lazy, coefficient-wise complex conjugate function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object if the array is complex valued, otherwise the array itself.

Definition at line 148 of file mapped_functions.hpp.

◆ conj() [2/2]

template<typename T >
requires (nda::is_scalar_v<T>)
auto nda::conj ( T t)

#include <nda/mapped_functions.hpp>

Get the complex conjugate of a scalar.

Template Parameters
TScalar type.
Parameters
tScalar value.
Returns
The given scalar if it is not complex, otherwise its complex conjugate.

Definition at line 67 of file mapped_functions.hpp.

◆ cos()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::cos ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise cos function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 184 of file mapped_functions.hxx.

◆ cosh()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::cosh ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise cosh function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 226 of file mapped_functions.hxx.

◆ dagger()

template<ArrayOfRank< 2 > M>
ArrayOfRank< 2 > auto nda::dagger ( M const & m)

#include <nda/matrix_functions.hpp>

Get the conjugate transpose of 2-dimensional array/view.

It first calls nda::transpose and then the lazy nda::conj function in case the array/view is complex valued.

Template Parameters
Mnda::ArrayOfRank<2> type.
Parameters
m2-dimensional array/view.
Returns
(Lazy) Conjugate transpose of the array/view.

Definition at line 91 of file matrix_functions.hpp.

◆ exp()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::exp ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise exp function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 170 of file mapped_functions.hxx.

◆ floor()

template<Array A>
auto nda::floor ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise floor function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 123 of file mapped_functions.hxx.

◆ frobenius_norm()

template<ArrayOfRank< 2 > A>
double nda::frobenius_norm ( A const & a)

#include <nda/algorithms.hpp>

Calculate the Frobenius norm of a 2-dimensional array.

Template Parameters
Anda::ArrayOfRank<2> type.
Parameters
aArray object.
Returns
Frobenius norm of the array/matrix.

Definition at line 165 of file algorithms.hpp.

◆ imag()

template<Array A>
auto nda::imag ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise imag function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 109 of file mapped_functions.hxx.

◆ isnan() [1/2]

template<Array A>
auto nda::isnan ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise isnan function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 159 of file mapped_functions.hxx.

◆ isnan() [2/2]

bool nda::isnan ( std::complex< double > const & z)
inline

#include <nda/mapped_functions.hpp>

Check if a std::complex<double> is NaN.

Parameters
zstd::complex<double> value.
Returns
True if either the real or imaginary part of the given complex number is NaN, false otherwise.

Definition at line 99 of file mapped_functions.hpp.

◆ log()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::log ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise log function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 310 of file mapped_functions.hxx.

◆ map()

template<class F >
mapped< F > nda::map ( F f)

#include <nda/map.hpp>

Create a lazy function call expression on arrays/views.

The callable should take the array/view elements as arguments.

Template Parameters
FCallable type.
Parameters
fCallable object.
Returns
A lazy nda::mapped object.

Definition at line 199 of file map.hpp.

◆ pow() [1/2]

template<Array A>
auto nda::pow ( A && a,
double p )

#include <nda/mapped_functions.hpp>

Lazy, coefficient-wise power function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
pExponent value.
Returns
A lazy nda::expr_call object.

Definition at line 127 of file mapped_functions.hpp.

◆ pow() [2/2]

template<typename T >
requires (std::is_integral_v<T>)
T nda::pow ( T x,
int n )

#include <nda/mapped_functions.hpp>

Calculate the integer power of an integer.

Template Parameters
TInteger type.
Parameters
xBase value.
nExponent value.
Returns
The result of the base raised to the power of the exponent.

Definition at line 110 of file mapped_functions.hpp.

◆ real() [1/2]

template<Array A>
auto nda::real ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise real function for nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 137 of file mapped_functions.hxx.

◆ real() [2/2]

template<typename T >
requires (nda::is_scalar_v<T>)
auto nda::real ( T t)

#include <nda/mapped_functions.hpp>

Get the real part of a scalar.

Template Parameters
TScalar type.
Parameters
tScalar value.
Returns
Real part of the scalar.

Definition at line 49 of file mapped_functions.hpp.

◆ sin()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::sin ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise sin function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 198 of file mapped_functions.hxx.

◆ sinh()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::sinh ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise sinh function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 240 of file mapped_functions.hxx.

◆ sqrt()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::sqrt ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise sqrt function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 324 of file mapped_functions.hxx.

◆ tan()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::tan ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise tan function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 212 of file mapped_functions.hxx.

◆ tanh()

template<Array A>
requires (get_algebra<A> != 'M')
auto nda::tanh ( A && a)

#include <nda/mapped_functions.hxx>

Lazy, coefficient-wise tanh function for non-matrix nda::Array types.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
A lazy nda::expr_call object.

Definition at line 254 of file mapped_functions.hxx.

◆ trace()

template<ArrayOfRank< 2 > M>
auto nda::trace ( M const & m)

#include <nda/matrix_functions.hpp>

Get the trace of a 2-dimensional square array/view.

Template Parameters
Mnda::ArrayOfRank<2> type.
Parameters
m2-dimensional array/view.
Returns
Sum of the diagonal elements of the array/view.

Definition at line 70 of file matrix_functions.hpp.