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

Detailed Description

Various algorithms that can be applied to arrays and views.

We can group the different algorithms into

Functions

template<Array A>
bool nda::all (A const &a)
 Do all elements of the array evaluate to true?
 
template<Array A>
bool nda::any (A const &a)
 Does any of the elements of the array evaluate to true?
 
template<Array A, typename F >
auto nda::fold (F f, A const &a)
 The same as nda::fold, except that the initial value is a default constructed value type of the array.
 
template<Array A, typename F , typename R >
auto nda::fold (F f, A const &a, R r)
 Perform a fold operation on the given nda::Array object.
 
template<Array A, Array B>
requires (nda::get_rank<A> == nda::get_rank<B>)
constexpr auto nda::hadamard (A &&a, B &&b)
 Hadamard product of two nda::Array objects.
 
constexpr auto nda::hadamard (nda::Scalar auto a, nda::Scalar auto b)
 Hadamard product of two arithmetic types.
 
template<typename T , typename U , size_t R>
constexpr auto nda::hadamard (std::array< T, R > const &a, std::array< U, R > const &b)
 Hadamard product of two std::array objects.
 
template<typename T , typename U >
constexpr auto nda::hadamard (std::vector< T > const &a, std::vector< U > const &b)
 Hadamard product of two std::vector objects.
 
template<Array A>
auto nda::max_element (A const &a)
 Find the maximum element of an array.
 
template<Array A>
auto nda::min_element (A const &a)
 Find the minimum element of an array.
 
template<Array A, typename Value = get_value_t<A>>
requires (nda::Scalar<Value> or nda::Array<Value>)
auto nda::product (A const &a)
 Multiply all the elements of an nda::Array object.
 
template<Array A, typename Value = get_value_t<A>>
requires (nda::Scalar<Value> or nda::Array<Value>)
auto nda::sum (A const &a)
 Sum all the elements of an nda::Array object.
 

Function Documentation

◆ all()

template<Array A>
bool nda::all ( A const & a)

#include <nda/algorithms.hpp>

Do all elements of the array evaluate to true?

The given nda::Array object can also be some lazy expression that evaluates to a boolean. For example:

auto greater0 = nda::map([](auto x) { return x > 0.0; })(A);
auto res = nda::all(greater0);
static basic_array rand(std::array< Int, Rank > const &shape)
Make a random-initialized array with the given shape.
bool all(A const &a)
Do all elements of the array evaluate to true?
mapped< F > map(F f)
Create a lazy function call expression on arrays/views.
Definition map.hpp:213
Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
True if all elements of the array evaluate to true, false otherwise.

Definition at line 120 of file algorithms.hpp.

◆ any()

template<Array A>
bool nda::any ( A const & a)

#include <nda/algorithms.hpp>

Does any of the elements of the array evaluate to true?

The given nda::Array object can also be some lazy expression that evaluates to a boolean. For example:

auto greater05 = nda::map([](auto x) { return x > 0.5; })(A);
auto res = nda::any(greater05);
bool any(A const &a)
Does any of the elements of the array evaluate to true?
Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
True if at least one element of the array evaluates to true, false otherwise.

Definition at line 99 of file algorithms.hpp.

◆ fold()

template<Array A, typename F , typename R >
auto nda::fold ( F f,
A const & a,
R r )

#include <nda/algorithms.hpp>

Perform a fold operation on the given nda::Array object.

It calculates the following (where r is an initial value);

auto res = f(...f(f(f(r, a(0,...,0)), a(0,...,1)), a(0,...,2)), ...);
Note
The array is always traversed in C-order.
Template Parameters
Anda::Array type.
FCallable type.
RType of the initial value.
Parameters
fCallable object taking two arguments compatible with the initial value and the array value type.
anda::Array object.
rInitial value.
Returns
Result of the fold operation.

Definition at line 69 of file algorithms.hpp.

◆ hadamard() [1/4]

template<Array A, Array B>
requires (nda::get_rank<A> == nda::get_rank<B>)
auto nda::hadamard ( A && a,
B && b )
nodiscardconstexpr

#include <nda/algorithms.hpp>

Hadamard product of two nda::Array objects.

Template Parameters
Anda::Array type.
Bnda::Array type.
Parameters
anda::Array object.
bnda::Array object.
Returns
A lazy nda::expr_call object representing the elementwise product of the two input objects.

Definition at line 228 of file algorithms.hpp.

◆ hadamard() [2/4]

auto nda::hadamard ( nda::Scalar auto a,
nda::Scalar auto b )
constexpr

#include <nda/algorithms.hpp>

Hadamard product of two arithmetic types.

Template Parameters
Tnda::Scalar type of the first input.
Unda::Scalar type of the second input.
Parameters
aFirst input.
bSecond input.
Returns
Product of the two inputs.

Definition at line 275 of file algorithms.hpp.

◆ hadamard() [3/4]

template<typename T , typename U , size_t R>
auto nda::hadamard ( std::array< T, R > const & a,
std::array< U, R > const & b )
nodiscardconstexpr

#include <nda/algorithms.hpp>

Hadamard product of two std::array objects.

Template Parameters
TValue type of the first array.
UValue type of the second array.
RSize of the arrays.
Parameters
astd::array object.
bstd::array object.
Returns
std::array containing the elementwise product of the two input arrays.

Definition at line 243 of file algorithms.hpp.

◆ hadamard() [4/4]

template<typename T , typename U >
auto nda::hadamard ( std::vector< T > const & a,
std::vector< U > const & b )
nodiscardconstexpr

#include <nda/algorithms.hpp>

Hadamard product of two std::vector objects.

Template Parameters
TValue type of the first input vector.
UValue type of the second input vector.
Parameters
astd::vector object.
bstd::vector object.
Returns
std::vector containing the elementwise product of the two input vectors.

Definition at line 257 of file algorithms.hpp.

◆ max_element()

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

#include <nda/algorithms.hpp>

Find the maximum element of an array.

It uses nda::fold and std::max.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
Maximum element of the array.

Definition at line 135 of file algorithms.hpp.

◆ min_element()

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

#include <nda/algorithms.hpp>

Find the minimum element of an array.

It uses nda::fold and std::min.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
Minimum element of the array.

Definition at line 154 of file algorithms.hpp.

◆ product()

template<Array A, typename Value = get_value_t<A>>
requires (nda::Scalar<Value> or nda::Array<Value>)
auto nda::product ( A const & a)

#include <nda/algorithms.hpp>

Multiply all the elements of an nda::Array object.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
Product of all elements.

Definition at line 207 of file algorithms.hpp.

◆ sum()

template<Array A, typename Value = get_value_t<A>>
requires (nda::Scalar<Value> or nda::Array<Value>)
auto nda::sum ( A const & a)

#include <nda/algorithms.hpp>

Sum all the elements of an nda::Array object.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
Sum of all elements.

Definition at line 189 of file algorithms.hpp.