xreducer
Defined in xtensor/xreducer.hpp
-
template<class F, class CT, class X, class O>
class xreducer : public xt::xsharable_expression<xreducer<F, CT, X, O>>, public xt::xconst_iterable<xreducer<F, CT, X, O>>, public xt::xaccessible<xreducer<F, CT, X, O>>, public extension::xreducer_base_t<F, CT, X, O> 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 expressionSee also
reduce
- Template Parameters:
F – a tuple of functors (class xreducer_functors or compatible)
CT – the closure type of the xexpression to reduce
X – the list of axes
CT. –
Constructor
-
template<class Func, class CTA, class AX, class OX>
inline xreducer(Func &&func, CTA &&e, AX &&axes, OX &&options) Constructs an xreducer expression applying the specified function to the given expression over the given axes.
- Parameters:
func – the function to apply
e – the expression to reduce
axes – the axes along which the reduction is performed
Size and shape
-
inline const inner_shape_type &shape() const noexcept
Returns the shape of the expression.
-
inline layout_type layout() const noexcept
Returns the shape of the expression.
Data
-
inline const xexpression_type &expression() const noexcept
Returns a constant reference to the underlying expression of the reducer.
-
template<class ...Args>
inline const_reference operator()(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>
inline const_reference unchecked(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 preferred 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 It>
inline const_reference element(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 indices
last – 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>
inline bool broadcast_shape(S &shape, bool reuse_cache = false) const Broadcast the shape of the reducer to the specified parameter.
- Parameters:
shape – the result shape
reuse_cache – parameter for internal optimization
- Returns:
a boolean indicating whether the broadcasting is trivial
Warning
doxygenfunction: Unable to resolve function “xt::reduce” with arguments (F&&, E&&, X&&, EVS&&) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:
- template<class F, class E, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<is_reducer_options<EVS>, detail::is_xreducer_functors<F>> = 0> auto reduce(F &&f, E &&e, EVS &&options = EVS())
- template<class F, class E, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<is_reducer_options<EVS>, detail::is_xreducer_functors<F>> = 0> auto reduce(F &&f, E &&e, EVS &&options = EVS())
- template<class F, class E, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<is_reducer_options<EVS>, std::negation<detail::is_xreducer_functors<F>>> = 0> auto reduce(F &&f, E &&e, EVS &&options = EVS())
- template<class F, class E, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<is_reducer_options<EVS>, std::negation<detail::is_xreducer_functors<F>>> = 0> auto reduce(F &&f, E &&e, EVS &&options = EVS())
- template<class F, class E, class I, std::size_t N, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<detail::is_xreducer_functors<F>> = 0> auto reduce(F &&f, E &&e, const I (&axes)[N], EVS options = EVS())
- template<class F, class E, class I, std::size_t N, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<detail::is_xreducer_functors<F>> = 0> auto reduce(F &&f, E &&e, const I (&axes)[N], EVS options = EVS())
- template<class F, class E, class I, std::size_t N, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<std::negation<detail::is_xreducer_functors<F>>> = 0> auto reduce(F &&f, E &&e, const I (&axes)[N], EVS options = EVS())
- template<class F, class E, class I, std::size_t N, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<std::negation<detail::is_xreducer_functors<F>>> = 0> auto reduce(F &&f, E &&e, const I (&axes)[N], EVS options = EVS())
- template<class F, class E, class X, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<std::negation<is_reducer_options<X>>, detail::is_xreducer_functors<F>> = 0> auto reduce(F &&f, E &&e, X &&axes, EVS &&options = EVS())
- template<class F, class E, class X, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<std::negation<is_reducer_options<X>>, detail::is_xreducer_functors<F>> = 0> auto reduce(F &&f, E &&e, X &&axes, EVS &&options = EVS())
- template<class F, class E, class X, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<std::negation<is_reducer_options<X>>, std::negation<detail::is_xreducer_functors<F>>> = 0> auto reduce(F &&f, E &&e, X &&axes, EVS &&options = EVS())
- template<class F, class E, class X, class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<std::negation<is_reducer_options<X>>, std::negation<detail::is_xreducer_functors<F>>> = 0> auto reduce(F &&f, E &&e, X &&axes, EVS &&options = EVS())