xreducer¶
Defined in xtensor/xreducer.hpp

template <class F, class CT, class X>
classxreducer
: public xt::xexpression<xreducer<F, CT, X>>, public xt::xconst_iterable<xreducer<F, CT, X>>¶ Reducing function operating over specified axes.
The xreducer class implements an xexpression applying a reducing function to an xexpression over the specified axes.
The reducer’s result_type is deduced from the result type of function
F::reduce_functor_type
when called with elements of the expression See
 reduce
 Template Parameters
F
: a tuple of functors (class xreducer_functors or compatible)CT
: the closure type of the xexpression to reduceX
: the list of axes
 Template Parameters
CT.
:
Constructor

template <class Func, class CTA, class AX>
xreducer
(Func &&func, CTA &&e, AX &&axes)¶ Constructs an xreducer expression applying the specified function to the given expression over the given axes.
 Parameters
func
: the function to applye
: the expression to reduceaxes
: the axes along which the reduction is performed
Size and shape

auto
size
() const¶ Returns the size of the expression.

auto
dimension
() const¶ Returns the number of dimensions of the expression.

auto
shape
() const¶ Returns the shape of the expression.

layout_type
layout
() const¶ Returns the shape of the expression.
Data

template <class... Args>
autooperator()
(Args... args) const¶ Returns a constant reference to the element at the specified position in the reducer.
 Parameters
args
: a list of indices specifying the position in the reducer. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the reducer.

template <class... Args>
autoat
(Args... args) const¶ Returns a constant reference to the element at the specified position in the expression, after dimension and bounds checking.
 Parameters
args
: a list of indices specifying the position in the function. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the expression.
 Exceptions
std::out_of_range
: if the number of argument is greater than the number of dimensions or if indices are out of bounds.

template <class... Args>
autounchecked
(Args... args) const¶ Returns a constant reference to the element at the specified position in the reducer.
 Warning
 This method is meant for performance, for expressions with a dynamic number of dimensions (i.e. not known at compile time). Since it may have undefined behavior (see parameters), operator() should be prefered whenever it is possible.
 Warning
 This method is NOT compatible with broadcasting, meaning the following code has undefined behavior:
xt::xarray<double> a = {{0, 1}, {2, 3}}; xt::xarray<double> b = {0, 1}; auto fd = a + b; double res = fd.uncheked(0, 1);
 Parameters
args
: a list of indices specifying the position in the reducer. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the reducer, else the behavior is undefined.

template <class S>
autooperator[]
(const S &index) const¶ Returns a constant reference to the element at the specified position in the reducer.
 Parameters
index
: a sequence of indices specifying the position in the reducer. Indices must be unsigned integers, the number of indices in the sequence should be equal or greater than the number of dimensions of the reducer.

template <class It>
autoelement
(It first, It last) const¶ Returns a constant reference to the element at the specified position in the reducer.
 Parameters
first
: iterator starting the sequence of indiceslast
: iterator ending the sequence of indices The number of indices in the sequence should be equal to or greater than the number of dimensions of the reducer.
Broadcasting

template <class S>
boolbroadcast_shape
(S &shape, bool reuse_cache = false) const¶ Broadcast the shape of the reducer to the specified parameter.
 Return
 a boolean indicating whether the broadcasting is trivial
 Parameters
shape
: the result shapereuse_cache
: parameter for internal optimization

template <class S>
boolis_trivial_broadcast
(const S &strides) const¶ Compares the specified strides with those of the container to see whether the broadcasting is trivial.
 Return
 a boolean indicating whether the broadcasting is trivial

template <class F, class E, class X, class EVS = evaluation_strategy::lazy, class = std::enable_if_t<!std::is_base_of<evaluation_strategy::base, std::decay_t<X>>::value, int>>
autoxt
::
reduce
(F &&f, E &&e, X &&axes, EVS es = EVS()) Returns an xexpression applying the specified reducing function to an expression over the given axes.
The returned expression either hold a const reference to
e
or a copy depending on whethere
is an lvalue or an rvalue. Parameters
f
: the reducing function to apply.e
: the xexpression to reduce.axes
: the list of axes.evaluation_strategy
: evaluation strategy to use (lazy (default), or immediate)