62 template <Array A,
typename F,
typename R>
63 auto fold(F f, A
const &a, R r) {
66 nda::for_each(a.shape(), [&a, &r2, &f](
auto &&...args) { r2 = f(r2, a(args...)); });
71 template <Array A,
typename F>
72 auto fold(F f, A
const &a) {
92 bool any(A
const &a) {
93 static_assert(std::is_same_v<get_value_t<A>,
bool>,
"Error in nda::any: Value type of the array must be bool");
94 return fold([](
bool r,
auto const &x) ->
bool {
return r or bool(x); }, a,
false);
114 static_assert(std::is_same_v<get_value_t<A>,
bool>,
"Error in nda::all: Value type of the array must be bool");
115 return fold([](
bool r,
auto const &x) ->
bool {
return r and bool(x); }, a,
true);
130 [](
auto const &x,
auto const &y) {
149 [](
auto const &x,
auto const &y) {
164 template <ArrayOfRank<2> A>
166 return std::sqrt(
fold(
167 [](
double r,
auto const &x) ->
double {
168 auto ab = std::abs(x);
185 return fold(std::plus<>{}, a);
Provides concepts for the nda library.
Provides for_each functions for multi-dimensional arrays/views.
auto max_element(A const &a)
Find the maximum element of an array.
auto fold(F f, A const &a, R r)
Perform a fold operation on the given nda::Array object.
auto product(A const &a)
Multiply all the elements of an nda::Array object.
bool any(A const &a)
Does any of the elements of the array evaluate to true?
auto min_element(A const &a)
Find the minimum element of an array.
auto sum(A const &a)
Sum all the elements of an nda::Array object.
bool all(A const &a)
Do all elements of the array evaluate to true?
double frobenius_norm(A const &a)
Calculate the Frobenius norm of a 2-dimensional array.
std::decay_t< decltype(get_first_element(std::declval< A const >()))> get_value_t
Get the value type of an array/view or a scalar type.
decltype(auto) get_first_element(A const &a)
Get the first element of an array/view or simply return the scalar if a scalar is given.
__inline__ void for_each(std::array< Int, R > const &shape, F &&f)
Loop over all possible index values of a given shape and apply a function to them.
constexpr bool is_scalar_v
Constexpr variable that is true if type S is a scalar type, i.e. arithmetic or complex.
Provides type traits for the nda library.