Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Reductions.hpp File Reference

Global and axis reductions in logical row-major order. More...

#include <stratax/core/dtypes/Concepts.hpp>
#include <stratax/exceptions/Exceptions.hpp>
#include <stratax/core/Shape.hpp>
#include <stratax/containers/Tensor.hpp>
#include <stratax/containers/Matrix.hpp>
#include <stratax/containers/Vector.hpp>
#include <stratax/core/Slice.hpp>
#include <stratax/indexing/Slicing.hpp>
#include <stratax/algorithms/Conversion.hpp>
#include <stratax/core/ReductionTraits.hpp>
#include <numeric>
#include <functional>
#include <cmath>
#include <type_traits>
#include <utility>
Include dependency graph for Reductions.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

template<Array A, typename Func >
using reduction::detail::axis_reduce_value_t = decltype(std::declval< Func >()(std::declval< const stratax::container::Tensor< typename A::value_type > & >()))
 Result type produced by invoking an axis-reduction callback.
 

Functions

template<bool FindMaximum, Array A>
requires Ordered<typename A::value_type>
std::pair< typename A::value_type, std::size_t > reduction::detail::ordered_extreme (const A &arr)
 Selects an extreme value and its logical index with an ordered scan.
 
bool reduction::detail::advance (const stratax::core::Shape &shape, std::vector< std::size_t > &indices)
 Advances a multidimensional index in row-major order.
 
template<Array A>
int reduction::detail::normalize_axis (const A &arr, int axis)
 Converts a possibly negative axis to its non-negative equivalent.
 
template<Array A>
std::vector< std::size_t > reduction::detail::result_shape (const A &arr, int axis, bool keepdims)
 Computes the dimensions produced by reducing one normalized axis.
 
template<Array A, typename Func >
stratax::container::Tensor< detail::axis_reduce_value_t< A, Func > > reduction::axis_reduce (const A &array, int axis, Func func, bool keepdims=false)
 Applies a scalar reduction callback independently along one axis.
 
template<Array A>
requires Numeric<typename A::value_type>
auto reduction::sum (const A &arr)
 Returns the sum of all elements in flat iterator order.
 
template<Array A>
requires Numeric<typename A::value_type>
auto reduction::prod (const A &arr)
 Returns the product of all elements in flat iterator order.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::max (const A &arr)
 Returns the largest element.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::min (const A &arr)
 Returns the smallest element.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmax (const A &arr)
 Returns the flat index of the largest element.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmin (const A &arr)
 Returns the flat index of the smallest element.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
double reduction::mean (const A &arr)
 Returns the arithmetic mean of all elements as double.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
double reduction::var (const A &arr)
 Returns the population variance using Welford's online algorithm.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
double reduction::std (const A &arr)
 Returns the population standard deviation of all elements.
 
template<Array A>
requires Numeric<typename A::value_type>
auto reduction::sum (const A &arr, int axis)
 Sums values along an axis and removes that dimension.
 
template<Array A>
requires Numeric<typename A::value_type>
auto reduction::sum (const A &arr, int axis, bool keepdims)
 Sums values along an axis with optional dimension retention.
 
template<Array A>
requires Numeric<typename A::value_type>
auto reduction::prod (const A &arr, int axis)
 Multiplies values along an axis and removes that dimension.
 
template<Array A>
requires Numeric<typename A::value_type>
auto reduction::prod (const A &arr, int axis, bool keepdims)
 Multiplies values along an axis with optional dimension retention.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::max (const A &arr, int axis)
 Finds maximum values along an axis and removes that dimension.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::max (const A &arr, int axis, bool keepdims)
 Finds maximum values along an axis with optional dimension retention.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::min (const A &arr, int axis)
 Finds minimum values along an axis and removes that dimension.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::min (const A &arr, int axis, bool keepdims)
 Finds minimum values along an axis with optional dimension retention.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmax (const A &arr, int axis)
 Finds indices of maximum values along an axis.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmax (const A &arr, int axis, bool keepdims)
 Finds indices of maximum values with optional dimension retention.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmin (const A &arr, int axis)
 Finds indices of minimum values along an axis.
 
template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmin (const A &arr, int axis, bool keepdims)
 Finds indices of minimum values with optional dimension retention.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::mean (const A &arr, int axis, bool keepdims)
 Computes arithmetic means along an axis with optional dimension retention.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::mean (const A &arr, int axis)
 Computes arithmetic means along an axis and removes that dimension.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::var (const A &arr, int axis, bool keepdims)
 Computes population variances with optional dimension retention.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::var (const A &arr, int axis)
 Computes population variances along an axis and removes that dimension.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::std (const A &arr, int axis, bool keepdims)
 Computes population standard deviations with optional dimension retention.
 
template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::std (const A &arr, int axis)
 Computes population standard deviations and removes the reduced dimension.
 

Detailed Description

Global and axis reductions in logical row-major order.

Definition in file Reductions.hpp.

Typedef Documentation

◆ axis_reduce_value_t

template<Array A, typename Func >
using reduction::detail::axis_reduce_value_t = typedef decltype(std::declval<Func>()( std::declval<const stratax::container::Tensor<typename A::value_type>&>()))

Result type produced by invoking an axis-reduction callback.

Template Parameters
ASource array type satisfying Array.
FuncCallable accepting a const Tensor of A::value_type.

Definition at line 178 of file Reductions.hpp.

Function Documentation

◆ advance()

bool reduction::detail::advance ( const stratax::core::Shape &  shape,
std::vector< std::size_t > &  indices 
)
inline

Advances a multidimensional index in row-major order.

Parameters
shapeExtents that bound each component of indices.
indicesIndex updated in place, beginning with the final dimension.
Returns
true when another index exists; false after wrapping to all zeros.
Precondition
indices.size() == shape.rank() and every component is in range.
Complexity
O(shape.rank()) in the worst case.

Definition at line 82 of file Reductions.hpp.

◆ argmax() [1/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmax ( const A &  arr)

Returns the flat index of the largest element.

Template Parameters
AStratax array type satisfying Array whose values are ordered.
Parameters
arrNon-empty array to search.
Returns
Zero-based logical row-major index as stratax::dtype::int64; ties choose the first largest value.
Note
Uses the same ordinary comparisons and NaN selection behavior as max.
Exceptions
Exceptions::IndexErrorIf arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 385 of file Reductions.hpp.

◆ argmax() [2/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmax ( const A &  arr,
int  axis 
)

Finds indices of maximum values along an axis.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor<stratax::dtype::int64> containing the first maximum's zero-based index within each axis slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 692 of file Reductions.hpp.

◆ argmax() [3/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmax ( const A &  arr,
int  axis,
bool  keepdims 
)

Finds indices of maximum values with optional dimension retention.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor<stratax::dtype::int64> containing the first maximum's zero-based index within each axis slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 710 of file Reductions.hpp.

◆ argmin() [1/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmin ( const A &  arr)

Returns the flat index of the smallest element.

Template Parameters
AStratax array type satisfying Array whose values are ordered.
Parameters
arrNon-empty array to search.
Returns
Zero-based logical row-major index as stratax::dtype::int64; ties choose the first smallest value.
Note
Uses the same ordinary comparisons and NaN selection behavior as min.
Exceptions
Exceptions::IndexErrorIf arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 406 of file Reductions.hpp.

◆ argmin() [2/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmin ( const A &  arr,
int  axis 
)

Finds indices of minimum values along an axis.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor<stratax::dtype::int64> containing the first minimum's zero-based index within each axis slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 730 of file Reductions.hpp.

◆ argmin() [3/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::argmin ( const A &  arr,
int  axis,
bool  keepdims 
)

Finds indices of minimum values with optional dimension retention.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor<stratax::dtype::int64> containing the first minimum's zero-based index within each axis slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 748 of file Reductions.hpp.

◆ axis_reduce()

template<Array A, typename Func >
stratax::container::Tensor< detail::axis_reduce_value_t< A, Func > > reduction::axis_reduce ( const A &  array,
int  axis,
Func  func,
bool  keepdims = false 
)

Applies a scalar reduction callback independently along one axis.

Negative axes count backward from the final dimension. Each output position is computed from a strided view into an initial owning copy of the input. With keepdims false the axis is removed; with it true the axis has extent one. Because rank-zero tensors cannot store a scalar in the current container model, reducing a rank-one array without keepdims returns shape {1}. Empty output domains return immediately without invoking func. The callback result type determines the returned tensor's value type.

Template Parameters
ASource array or view satisfying Array.
FuncCallable accepting both Tensor and ArrayView inputs and returning a supported dtype. A generic lambda is appropriate.
Parameters
arraySource array.
axisAxis in [-array.rank(), array.rank() - 1].
funcScalar reduction applied to every axis slice.
keepdimsWhether the reduced dimension remains with extent one.
Returns
Owning Tensor containing one callback result per output position. Its value type is inferred from invoking func on a const Tensor<A::value_type>. Actual calls receive a Tensor for the rank-one, keepdims-false case and an ArrayView otherwise.
Exceptions
Exceptions::AxisErrorIf axis is outside the valid range.
Anyexception propagated by conversion, slicing, allocation, or func.
Note
Callbacks must not retain views or references into the temporary input copy.
func is not invoked when the result shape has zero elements.
Complexity
O((n + p + 1) * r) plus callback work, where n is input size, p is output size and r is input rank; O(n + p + r) auxiliary storage.

Definition at line 215 of file Reductions.hpp.

◆ max() [1/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::max ( const A &  arr)

Returns the largest element.

Template Parameters
AStratax array type satisfying Array whose values are ordered.
Parameters
arrNon-empty array to search.
Returns
Largest value; ties select the first occurrence.
Note
Uses ordinary comparisons. With IEEE-style NaNs an initial NaN remains selected, while a later NaN does not replace the current candidate. Signed zeros tie and retain the first occurrence's sign.
Exceptions
Exceptions::IndexErrorIf arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 341 of file Reductions.hpp.

◆ max() [2/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::max ( const A &  arr,
int  axis 
)

Finds maximum values along an axis and removes that dimension.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor containing the first maximum value from each slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 616 of file Reductions.hpp.

◆ max() [3/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::max ( const A &  arr,
int  axis,
bool  keepdims 
)

Finds maximum values along an axis with optional dimension retention.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor containing the first maximum value from each slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 634 of file Reductions.hpp.

◆ mean() [1/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
double reduction::mean ( const A &  arr)

Returns the arithmetic mean of all elements as double.

Template Parameters
AArray whose value_type is Numeric and Ordered (real numeric values).
Parameters
arrNon-empty array to reduce.
Returns
Mean accumulated and divided in long double, then converted to double.
Note
Each input is converted before addition, so integer inputs cannot overflow an integer sum accumulator. ReductionTraits does not affect this operation. Accumulation follows logical iterator order and is neither compensated nor guaranteed exact. Long double precision and range are platform dependent; floating-point overflow and rounding remain possible. NaNs and infinities follow native floating arithmetic.
Exceptions
Exceptions::ZeroDivisionErrorIf arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 435 of file Reductions.hpp.

◆ mean() [2/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::mean ( const A &  arr,
int  axis 
)

Computes arithmetic means along an axis and removes that dimension.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor<double> containing one mean per axis slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::ZeroDivisionErrorIf a produced output has an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 797 of file Reductions.hpp.

◆ mean() [3/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::mean ( const A &  arr,
int  axis,
bool  keepdims 
)

Computes arithmetic means along an axis with optional dimension retention.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor<double> containing one mean per axis slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::ZeroDivisionErrorIf a produced output has an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 773 of file Reductions.hpp.

◆ min() [1/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::min ( const A &  arr)

Returns the smallest element.

Template Parameters
AStratax array type satisfying Array whose values are ordered.
Parameters
arrNon-empty array to search.
Returns
Smallest value; ties select the first occurrence.
Note
Uses ordinary comparisons. With IEEE-style NaNs an initial NaN remains selected, while a later NaN does not replace the current candidate. Signed zeros tie and retain the first occurrence's sign.
Exceptions
Exceptions::IndexErrorIf arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 364 of file Reductions.hpp.

◆ min() [2/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::min ( const A &  arr,
int  axis 
)

Finds minimum values along an axis and removes that dimension.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor containing the first minimum value from each slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 654 of file Reductions.hpp.

◆ min() [3/3]

template<Array A>
requires Ordered<typename A::value_type>
auto reduction::min ( const A &  arr,
int  axis,
bool  keepdims 
)

Finds minimum values along an axis with optional dimension retention.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor containing the first minimum value from each slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::IndexErrorIf a produced output requires reducing an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 672 of file Reductions.hpp.

◆ normalize_axis()

template<Array A>
int reduction::detail::normalize_axis ( const A &  arr,
int  axis 
)
inline

Converts a possibly negative axis to its non-negative equivalent.

Template Parameters
AStratax array type satisfying Array.
Parameters
arrArray whose rank defines the negative-axis offset.
axisAxis in the range [-arr.rank(), arr.rank() - 1] when valid.
Returns
axis unchanged when non-negative, otherwise axis + arr.rank().
Note
This helper normalizes but does not validate the resulting axis.
Complexity
O(1).

Definition at line 112 of file Reductions.hpp.

◆ ordered_extreme()

template<bool FindMaximum, Array A>
requires Ordered<typename A::value_type>
std::pair< typename A::value_type, std::size_t > reduction::detail::ordered_extreme ( const A &  arr)

Selects an extreme value and its logical index with an ordered scan.

The first value initializes the candidate. Each later value replaces it only when a strict comparison succeeds. This preserves the first occurrence on ties, including signed zeros. With IEEE-style NaNs, an initial NaN remains selected and later NaNs never replace the candidate. The explicit scan does not depend on standard-library extrema algorithms' treatment of NaNs.

Template Parameters
FindMaximumSelects the largest value when true, otherwise the smallest.
AArray or view with an Ordered value_type.
Parameters
arrNon-empty input in logical row-major iterator order.
Returns
Pair containing the selected value and its zero-based logical index.
Precondition
arr is non-empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views. Stores one candidate value and two indices, plus iterators.

Definition at line 49 of file Reductions.hpp.

◆ prod() [1/3]

template<Array A>
requires Numeric<typename A::value_type>
auto reduction::prod ( const A &  arr)

Returns the product of all elements in flat iterator order.

Template Parameters
AStratax array type satisfying Array.
Parameters
arrArray to reduce.
Returns
Element product in reduction_prod_t<A::value_type>, or that type's multiplicative identity when arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 316 of file Reductions.hpp.

◆ prod() [2/3]

template<Array A>
requires Numeric<typename A::value_type>
auto reduction::prod ( const A &  arr,
int  axis 
)

Multiplies values along an axis and removes that dimension.

Template Parameters
ANumeric Stratax array type.
Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor<reduction_prod_t<A::value_type>> of per-slice products; empty slices produce the selected type's multiplicative identity.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 571 of file Reductions.hpp.

◆ prod() [3/3]

template<Array A>
requires Numeric<typename A::value_type>
auto reduction::prod ( const A &  arr,
int  axis,
bool  keepdims 
)

Multiplies values along an axis with optional dimension retention.

Template Parameters
ANumeric Stratax array type.
Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor<reduction_prod_t<A::value_type>> of per-slice products; empty slices produce the selected type's multiplicative identity.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 594 of file Reductions.hpp.

◆ result_shape()

template<Array A>
std::vector< std::size_t > reduction::detail::result_shape ( const A &  arr,
int  axis,
bool  keepdims 
)
inline

Computes the dimensions produced by reducing one normalized axis.

Template Parameters
AStratax array type satisfying Array.
Parameters
arrArray providing the input shape.
axisValid, non-negative axis to reduce.
keepdimsWhether to retain the reduced axis with extent one.
Returns
Input dimensions with axis removed or replaced by one.
Exceptions
std::bad_allocIf result-dimension allocation fails.
Complexity
O(arr.rank()).

Definition at line 135 of file Reductions.hpp.

◆ std() [1/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
double reduction::std ( const A &  arr)

Returns the population standard deviation of all elements.

Template Parameters
AArray whose value_type is Numeric and Ordered (real numeric values).
Parameters
arrNon-empty array to reduce.
Returns
Square root of var(arr).
Exceptions
Exceptions::ZeroDivisionErrorIf arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 504 of file Reductions.hpp.

◆ std() [2/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::std ( const A &  arr,
int  axis 
)

Computes population standard deviations and removes the reduced dimension.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor<double> containing one population standard deviation per slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::ZeroDivisionErrorIf a produced output has an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 889 of file Reductions.hpp.

◆ std() [3/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::std ( const A &  arr,
int  axis,
bool  keepdims 
)

Computes population standard deviations with optional dimension retention.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor<double> containing one population standard deviation per slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::ZeroDivisionErrorIf a produced output has an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 865 of file Reductions.hpp.

◆ sum() [1/3]

template<Array A>
requires Numeric<typename A::value_type>
auto reduction::sum ( const A &  arr)

Returns the sum of all elements in flat iterator order.

Template Parameters
AStratax array type satisfying Array.
Parameters
arrArray to reduce.
Returns
Element sum in reduction_sum_t<A::value_type>, or that type's additive identity when arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 295 of file Reductions.hpp.

◆ sum() [2/3]

template<Array A>
requires Numeric<typename A::value_type>
auto reduction::sum ( const A &  arr,
int  axis 
)

Sums values along an axis and removes that dimension.

Template Parameters
ANumeric Stratax array type.
Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor<reduction_sum_t<A::value_type>> with the axis removed (shape {1} for rank-one input); empty slices produce the selected type's additive identity.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 525 of file Reductions.hpp.

◆ sum() [3/3]

template<Array A>
requires Numeric<typename A::value_type>
auto reduction::sum ( const A &  arr,
int  axis,
bool  keepdims 
)

Sums values along an axis with optional dimension retention.

Template Parameters
ANumeric Stratax array type.
Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor<reduction_sum_t<A::value_type>> of per-slice sums; empty slices produce the selected type's additive identity.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 548 of file Reductions.hpp.

◆ var() [1/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
double reduction::var ( const A &  arr)

Returns the population variance using Welford's online algorithm.

Template Parameters
AArray whose value_type is Numeric and Ordered (real numeric values).
Parameters
arrNon-empty array to reduce.
Returns
Sum of squared deviations divided by arr.size().
Note
Inputs and intermediates use double. Welford's algorithm avoids the cancellation in mean(x*x) - mean(x)*mean(x), but rounding, conversion loss, and overflow remain possible. NaNs and infinite inputs generally produce NaN; this is not a NaN-skipping reduction.
Exceptions
Exceptions::ZeroDivisionErrorIf arr is empty.
Complexity
O(arr.size()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.

Definition at line 468 of file Reductions.hpp.

◆ var() [2/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::var ( const A &  arr,
int  axis 
)

Computes population variances along an axis and removes that dimension.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
Returns
Tensor<double> containing one population variance per slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::ZeroDivisionErrorIf a produced output has an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 843 of file Reductions.hpp.

◆ var() [3/3]

template<Array A>
requires ( Numeric<typename A::value_type> && Ordered<typename A::value_type> )
stratax::container::Tensor< double > reduction::var ( const A &  arr,
int  axis,
bool  keepdims 
)

Computes population variances with optional dimension retention.

Parameters
arrSource array.
axisAxis to reduce; negative values count from the end.
keepdimsRetains the reduced axis with extent one when true.
Returns
Tensor<double> containing one population variance per slice.
Exceptions
Exceptions::AxisErrorIf axis is invalid.
Exceptions::ZeroDivisionErrorIf a produced output has an empty slice.
See also
axis_reduce for result-shape conventions and allocation behavior.
Complexity
O((arr.size() + output_size + 1) * arr.rank()).

Definition at line 819 of file Reductions.hpp.