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>
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>
requires (nda::is_scalar_v<get_value_t<A>>)
auto nda::product (A const &a)
 Multiply all the elements of an nda::Array object.
 
template<Array A>
requires (nda::is_scalar_v<get_value_t<A>>)
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:199
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 113 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 92 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 63 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 128 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 147 of file algorithms.hpp.

◆ product()

template<Array A>
requires (nda::is_scalar_v<get_value_t<A>>)
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 196 of file algorithms.hpp.

◆ sum()

template<Array A>
requires (nda::is_scalar_v<get_value_t<A>>)
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 182 of file algorithms.hpp.