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 an array A
auto A = nda::array<int, 2>({{1, 2}, {3, 4}});
// square the elements of A
auto ex = nda::pow(A, 2); // ex is a lazy expression
// evaluate the lazy expression by constructing a new array
std::cout << A_sq << std::endl;
// evaluate the lazy expression using nda::make_regular
std::cout << nda::make_regular(ex) << std::endl;
A generic multi-dimensional array.
decltype(auto) make_regular(A &&a)
Make a given object regular.
auto pow(A &&a, double p)
Function pow for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.

Output:

[[1,4]
[9,16]]
[[1,4]
[9,16]]

Classes

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<ArrayOrScalar A>
auto nda::abs (A &&a)
 Function abs for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
auto nda::abs2 (A &&a)
 Function abs2 for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::acos (A &&a)
 Function acos for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::asin (A &&a)
 Function asin for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::atan (A &&a)
 Function atan for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
decltype(auto) nda::conj (A &&a)
 Function conj for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types with a complex value type).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::cos (A &&a)
 Function cos for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::cosh (A &&a)
 Function cosh for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for 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<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::exp (A &&a)
 Function exp for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
auto nda::floor (A &&a)
 Function floor for nda::ArrayOrScalar types (lazy and coefficient-wise 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<ArrayOrScalar A>
auto nda::imag (A &&a)
 Function imag for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
auto nda::isnan (A &&a)
 Function isnan for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::log (A &&a)
 Function log for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<class F >
mapped< F > nda::map (F f)
 Create a lazy function call expression on arrays/views.
 
template<ArrayOrScalar A>
auto nda::pow (A &&a, double p)
 Function pow for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
auto nda::real (A &&a)
 Function real for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::sin (A &&a)
 Function sin for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::sinh (A &&a)
 Function sinh for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::sqrt (A &&a)
 Function sqrt for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::tan (A &&a)
 Function tan for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).
 
template<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::tanh (A &&a)
 Function tanh for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for 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<ArrayOrScalar A>
auto nda::abs ( A && a)

#include <nda/mapped_functions.hxx>

Function abs for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::abs applied to the object (nda::Scalar).

Definition at line 96 of file mapped_functions.hxx.

◆ abs2()

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

#include <nda/mapped_functions.hxx>

Function abs2 for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type..
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of nda::detail::abs2 applied to the object (nda::Scalar).

Definition at line 149 of file mapped_functions.hxx.

◆ acos()

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

#include <nda/mapped_functions.hxx>

Function acos for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::acos applied to the object (nda::Scalar).

Definition at line 269 of file mapped_functions.hxx.

◆ asin()

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

#include <nda/mapped_functions.hxx>

Function asin for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::asin applied to the object (nda::Scalar).

Definition at line 283 of file mapped_functions.hxx.

◆ atan()

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

#include <nda/mapped_functions.hxx>

Function atan for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::atan applied to the object (nda::Scalar).

Definition at line 297 of file mapped_functions.hxx.

◆ conj()

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

#include <nda/mapped_functions.hpp>

Function conj for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types with a complex value type).

Template Parameters
Anda::ArrayOrScalar type..
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array and complex valued), the forwarded input object (nda::Array and not complex valued) or the complex conjugate of the scalar input.

Definition at line 105 of file mapped_functions.hpp.

◆ cos()

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

#include <nda/mapped_functions.hxx>

Function cos for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::cos applied to the object (nda::Scalar).

Definition at line 185 of file mapped_functions.hxx.

◆ cosh()

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

#include <nda/mapped_functions.hxx>

Function cosh for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::cosh applied to the object (nda::Scalar).

Definition at line 227 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<ArrayOrScalar A>
requires (get_algebra<A> != 'M')
auto nda::exp ( A && a)

#include <nda/mapped_functions.hxx>

Function exp for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::exp applied to the object (nda::Scalar).

Definition at line 171 of file mapped_functions.hxx.

◆ floor()

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

#include <nda/mapped_functions.hxx>

Function floor for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::floor applied to the object (nda::Scalar).

Definition at line 124 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 172 of file algorithms.hpp.

◆ imag()

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

#include <nda/mapped_functions.hxx>

Function imag for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::imag applied to the object (nda::Scalar).

Definition at line 110 of file mapped_functions.hxx.

◆ isnan()

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

#include <nda/mapped_functions.hxx>

Function isnan for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type..
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of nda::detail::isnan applied to the object (nda::Scalar).

Definition at line 160 of file mapped_functions.hxx.

◆ log()

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

#include <nda/mapped_functions.hxx>

Function log for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::log applied to the object (nda::Scalar).

Definition at line 311 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 213 of file map.hpp.

◆ pow()

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

#include <nda/mapped_functions.hpp>

Function pow for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type..
Parameters
anda::ArrayOrScalar object.
pExponent value.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::pow applied to the object (nda::Scalar).

Definition at line 88 of file mapped_functions.hpp.

◆ real()

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

#include <nda/mapped_functions.hxx>

Function real for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type..
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of nda::detail::real applied to the object (nda::Scalar).

Definition at line 138 of file mapped_functions.hxx.

◆ sin()

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

#include <nda/mapped_functions.hxx>

Function sin for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::sin applied to the object (nda::Scalar).

Definition at line 199 of file mapped_functions.hxx.

◆ sinh()

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

#include <nda/mapped_functions.hxx>

Function sinh for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::sinh applied to the object (nda::Scalar).

Definition at line 241 of file mapped_functions.hxx.

◆ sqrt()

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

#include <nda/mapped_functions.hxx>

Function sqrt for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::sqrt applied to the object (nda::Scalar).

Definition at line 325 of file mapped_functions.hxx.

◆ tan()

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

#include <nda/mapped_functions.hxx>

Function tan for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::tan applied to the object (nda::Scalar).

Definition at line 213 of file mapped_functions.hxx.

◆ tanh()

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

#include <nda/mapped_functions.hxx>

Function tanh for non-matrix nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types).

Template Parameters
Anda::ArrayOrScalar type.
Parameters
anda::ArrayOrScalar object.
Returns
A lazy nda::expr_call object (nda::Array) or the result of std::tanh applied to the object (nda::Scalar).

Definition at line 255 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.