xtensor
Loading...
Searching...
No Matches
xt::xreducer< F, CT, X, O > Class Template Reference

Reducing function operating over specified axes. More...

#include <xreducer.hpp>

Inheritance diagram for xt::xreducer< F, CT, X, O >:
xt::xsharable_expression< xreducer< F, CT, X, O > > xt::xconst_iterable< xreducer< F, CT, X, O > > xt::xaccessible< xreducer< F, CT, X, O > > xt::xexpression< xreducer< F, CT, X, O > > xt::xconst_accessible< xreducer< F, CT, X, O > >

Public Types

using self_type = xreducer<F, CT, X, O>
using inner_types = xcontainer_inner_types<self_type>
using reduce_functor_type = typename inner_types::reduce_functor_type
using init_functor_type = typename inner_types::init_functor_type
using merge_functor_type = typename inner_types::merge_functor_type
using xreducer_functors_type = xreducer_functors<reduce_functor_type, init_functor_type, merge_functor_type>
using xexpression_type = typename inner_types::xexpression_type
using axes_type = X
using extension_base = extension::xreducer_base_t<F, CT, X, O>
using expression_tag = typename extension_base::expression_tag
using substepper_type = typename inner_types::substepper_type
using value_type = typename inner_types::value_type
using reference = typename inner_types::reference
using const_reference = typename inner_types::const_reference
using pointer = value_type*
using const_pointer = const value_type*
using size_type = typename inner_types::size_type
using difference_type = typename xexpression_type::difference_type
using iterable_base = xconst_iterable<self_type>
using inner_shape_type = typename iterable_base::inner_shape_type
using shape_type = inner_shape_type
using dim_mapping_type = typename select_dim_mapping_type<inner_shape_type>::type
using stepper = typename iterable_base::stepper
using const_stepper = typename iterable_base::const_stepper
using bool_load_type = typename xexpression_type::bool_load_type
template<class E, class Func = F, class Opts = O>
using rebind_t = xreducer<Func, E, X, Opts>
Public Types inherited from xt::xexpression< xreducer< F, CT, X, O > >
using derived_type
Public Types inherited from xt::xconst_iterable< xreducer< F, CT, X, O > >
using derived_type
using iterable_types
using inner_shape_type
using stepper
using const_stepper
using layout_iterator
using const_layout_iterator
using reverse_layout_iterator
using const_reverse_layout_iterator
using linear_iterator
using const_linear_iterator
using reverse_linear_iterator
using const_reverse_linear_iterator
using broadcast_iterator
using const_broadcast_iterator
using reverse_broadcast_iterator
using const_reverse_broadcast_iterator
using iterator
using const_iterator
using reverse_iterator
using const_reverse_iterator
Public Types inherited from xt::xaccessible< xreducer< F, CT, X, O > >
using base_type
using derived_type
using reference
using size_type
Public Types inherited from xt::xconst_accessible< xreducer< F, CT, X, O > >
using derived_type
using inner_types
using reference
using const_reference
using size_type

Public Member Functions

xreducer_functors_type functors () const
const O & options () const
Constructor
template<class Func, class CTA, class AX, class OX>
 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.
Size and shape
const inner_shape_type & shape () const noexcept
 Returns the shape of the expression.
layout_type layout () const noexcept
 Returns the shape of the expression.
bool is_contiguous () const noexcept
Data
template<class... Args>
const_reference operator() (Args... args) const
 Returns a constant reference to the element at the specified position in the reducer.
template<class... Args>
const_reference unchecked (Args... args) const
 Returns a constant reference to the element at the specified position in the reducer.
template<class It>
const_reference element (It first, It last) const
 Returns a constant reference to the element at the specified position in the reducer.
const xexpression_type & expression () const noexcept
 Returns a constant reference to the underlying expression of the reducer.
Broadcasting
template<class S>
bool broadcast_shape (S &shape, bool reuse_cache=false) const
 Broadcast the shape of the reducer to the specified parameter.
template<class S>
bool has_linear_assign (const S &strides) const noexcept
 Checks whether the xreducer can be linearly assigned to an expression with the specified strides.
template<class S>
const_stepper stepper_begin (const S &shape) const noexcept
template<class S>
const_stepper stepper_end (const S &shape, layout_type) const noexcept
template<class E>
rebind_t< E > build_reducer (E &&e) const
template<class E, class Func, class Opts>
rebind_t< E, Func, Opts > build_reducer (E &&e, Func &&func, Opts &&opts) const
Public Member Functions inherited from xt::xexpression< xreducer< F, CT, X, O > >
derived_type & derived_cast () &noexcept
 Returns a reference to the actual derived type of the xexpression.
Public Member Functions inherited from xt::xconst_iterable< xreducer< F, CT, X, O > >
const_layout_iterator< L > begin () const noexcept
 Returns a constant iterator to the first element of the expression.
const_layout_iterator< L > end () const noexcept
 Returns a constant iterator to the element following the last element of the expression.
const_layout_iterator< L > cbegin () const noexcept
 Returns a constant iterator to the first element of the expression.
const_layout_iterator< L > cend () const noexcept
 Returns a constant iterator to the element following the last element of the expression.
const_reverse_layout_iterator< L > rbegin () const noexcept
 Returns a constant iterator to the first element of the reversed expression.
const_reverse_layout_iterator< L > rend () const noexcept
 Returns a constant iterator to the element following the last element of the reversed expression.
const_reverse_layout_iterator< L > crbegin () const noexcept
 Returns a constant iterator to the first element of the reversed expression.
const_reverse_layout_iterator< L > crend () const noexcept
 Returns a constant iterator to the element following the last element of the reversed expression.
Public Member Functions inherited from xt::xaccessible< xreducer< F, CT, X, O > >
const_reference at (Args... args) const
 Returns a constant reference to the element at the specified position in the expression, after dimension and bounds checking.
disable_integral_t< S, const_reference > operator[] (const S &index) const
 Returns a constant reference to the element at the specified position in the expression.
const_reference operator[] (std::initializer_list< I > index) const
const_reference operator[] (size_type i) const
const_reference back () const
 Returns a constant reference to last the element of the expression.
const_reference front () const
 Returns a constant reference to first the element of the expression.
const_reference periodic (Args... args) const
 Returns a constant reference to the element at the specified position in the expression, after applying periodicity to the indices (negative and 'overflowing' indices are changed).
Public Member Functions inherited from xt::xconst_accessible< xreducer< F, CT, X, O > >
size_type size () const noexcept(noexcept(derived_cast().shape()))
 Returns the size of the expression.
size_type dimension () const noexcept
 Returns the number of dimensions of the expression.
size_type shape (size_type index) const
 Returns the i-th dimension of the expression.
const_reference at (Args... args) const
 Returns a constant reference to the element at the specified position in the expression, after dimension and bounds checking.
disable_integral_t< S, const_reference > operator[] (const S &index) const
 Returns a constant reference to the element at the specified position in the expression.
const_reference periodic (Args... args) const
 Returns a constant reference to the element at the specified position in the expression, after applying periodicity to the indices (negative and 'overflowing' indices are changed).
bool in_bounds (Args... args) const
 Returns true only if the the specified position is a valid entry in the expression.
const_reference front () const
 Returns a constant reference to first the element of the expression.
const_reference back () const
 Returns a constant reference to last the element of the expression.

Static Public Attributes

static constexpr layout_type static_layout = layout_type::dynamic
static constexpr bool contiguous_layout = false

Friends

class xreducer_stepper< F, CT, X, O >

Additional Inherited Members

Protected Member Functions inherited from xt::xsharable_expression< xreducer< F, CT, X, O > >
xsharable_expression & operator= (const xsharable_expression &)=default
Protected Member Functions inherited from xt::xexpression< xreducer< F, CT, X, O > >
xexpression & operator= (const xexpression &)=default
const inner_shape_type & get_shape () const
Protected Member Functions inherited from xt::xaccessible< xreducer< F, CT, X, O > >
xaccessible & operator= (const xaccessible &)=default
Protected Member Functions inherited from xt::xconst_accessible< xreducer< F, CT, X, O > >
xconst_accessible & operator= (const xconst_accessible &)=default

Detailed Description

template<class F, class CT, class X, class O>
class xt::xreducer< 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.

Template Parameters
Fa tuple of functors (class xreducer_functors or compatible)
CTthe closure type of the xexpression to reduce
Xthe list of 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

Template Parameters
CT.
See also
reduce

Definition at line 804 of file xreducer.hpp.

Member Typedef Documentation

◆ axes_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::axes_type = X

Definition at line 820 of file xreducer.hpp.

◆ bool_load_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::bool_load_type = typename xexpression_type::bool_load_type

Definition at line 843 of file xreducer.hpp.

◆ const_pointer

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::const_pointer = const value_type*

Definition at line 830 of file xreducer.hpp.

◆ const_reference

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::const_reference = typename inner_types::const_reference

Definition at line 828 of file xreducer.hpp.

◆ const_stepper

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::const_stepper = typename iterable_base::const_stepper

Definition at line 842 of file xreducer.hpp.

◆ difference_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::difference_type = typename xexpression_type::difference_type

Definition at line 833 of file xreducer.hpp.

◆ dim_mapping_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::dim_mapping_type = typename select_dim_mapping_type<inner_shape_type>::type

Definition at line 839 of file xreducer.hpp.

◆ expression_tag

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::expression_tag = typename extension_base::expression_tag

Definition at line 823 of file xreducer.hpp.

◆ extension_base

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::extension_base = extension::xreducer_base_t<F, CT, X, O>

Definition at line 822 of file xreducer.hpp.

◆ init_functor_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::init_functor_type = typename inner_types::init_functor_type

Definition at line 815 of file xreducer.hpp.

◆ inner_shape_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::inner_shape_type = typename iterable_base::inner_shape_type

Definition at line 836 of file xreducer.hpp.

◆ inner_types

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::inner_types = xcontainer_inner_types<self_type>

Definition at line 812 of file xreducer.hpp.

◆ iterable_base

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::iterable_base = xconst_iterable<self_type>

Definition at line 835 of file xreducer.hpp.

◆ merge_functor_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::merge_functor_type = typename inner_types::merge_functor_type

Definition at line 816 of file xreducer.hpp.

◆ pointer

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::pointer = value_type*

Definition at line 829 of file xreducer.hpp.

◆ rebind_t

template<class F, class CT, class X, class O>
template<class E, class Func = F, class Opts = O>
using xt::xreducer< F, CT, X, O >::rebind_t = xreducer<Func, E, X, Opts>

Definition at line 877 of file xreducer.hpp.

◆ reduce_functor_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::reduce_functor_type = typename inner_types::reduce_functor_type

Definition at line 814 of file xreducer.hpp.

◆ reference

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::reference = typename inner_types::reference

Definition at line 827 of file xreducer.hpp.

◆ self_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::self_type = xreducer<F, CT, X, O>

Definition at line 811 of file xreducer.hpp.

◆ shape_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::shape_type = inner_shape_type

Definition at line 837 of file xreducer.hpp.

◆ size_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::size_type = typename inner_types::size_type

Definition at line 832 of file xreducer.hpp.

◆ stepper

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::stepper = typename iterable_base::stepper

Definition at line 841 of file xreducer.hpp.

◆ substepper_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::substepper_type = typename inner_types::substepper_type

Definition at line 825 of file xreducer.hpp.

◆ value_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::value_type = typename inner_types::value_type

Definition at line 826 of file xreducer.hpp.

◆ xexpression_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::xexpression_type = typename inner_types::xexpression_type

Definition at line 819 of file xreducer.hpp.

◆ xreducer_functors_type

template<class F, class CT, class X, class O>
using xt::xreducer< F, CT, X, O >::xreducer_functors_type = xreducer_functors<reduce_functor_type, init_functor_type, merge_functor_type>

Definition at line 817 of file xreducer.hpp.

Constructor & Destructor Documentation

◆ xreducer()

template<class F, class CT, class X, class O>
template<class Func, class CTA, class AX, class OX>
xt::xreducer< F, CT, X, O >::xreducer ( Func && func,
CTA && e,
AX && axes,
OX && options )
inline

Constructs an xreducer expression applying the specified function to the given expression over the given axes.

Parameters
functhe function to apply
ethe expression to reduce
axesthe axes along which the reduction is performed
optionsreducer options controlling evaluation strategy and related settings

Definition at line 1406 of file xreducer.hpp.

Member Function Documentation

◆ broadcast_shape()

template<class F, class CT, class X, class O>
template<class S>
bool xt::xreducer< F, CT, X, O >::broadcast_shape ( S & shape,
bool reuse_cache = false ) const
inline

Broadcast the shape of the reducer to the specified parameter.

Parameters
shapethe result shape
reuse_cacheparameter for internal optimization
Returns
a boolean indicating whether the broadcasting is trivial

Definition at line 1601 of file xreducer.hpp.

◆ build_reducer() [1/2]

template<class F, class CT, class X, class O>
template<class E>
auto xt::xreducer< F, CT, X, O >::build_reducer ( E && e) const -> rebind_t< E >
inline

Definition at line 1639 of file xreducer.hpp.

◆ build_reducer() [2/2]

template<class F, class CT, class X, class O>
template<class E, class Func, class Opts>
auto xt::xreducer< F, CT, X, O >::build_reducer ( E && e,
Func && func,
Opts && opts ) const
inline

Definition at line 1651 of file xreducer.hpp.

◆ element()

template<class F, class CT, class X, class O>
template<class It>
auto xt::xreducer< F, CT, X, O >::element ( It first,
It last ) const -> const_reference
inline

Returns a constant reference to the element at the specified position in the reducer.

Parameters
firstiterator starting the sequence of indices
lastiterator 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.

Definition at line 1552 of file xreducer.hpp.

◆ expression()

template<class F, class CT, class X, class O>
auto xt::xreducer< F, CT, X, O >::expression ( ) const
inlinenoexcept

Returns a constant reference to the underlying expression of the reducer.

Definition at line 1582 of file xreducer.hpp.

◆ functors()

template<class F, class CT, class X, class O>
xreducer_functors_type xt::xreducer< F, CT, X, O >::functors ( ) const
inline

Definition at line 885 of file xreducer.hpp.

◆ has_linear_assign()

template<class F, class CT, class X, class O>
template<class S>
bool xt::xreducer< F, CT, X, O >::has_linear_assign ( const S & strides) const
inlinenoexcept

Checks whether the xreducer can be linearly assigned to an expression with the specified strides.

Returns
a boolean indicating whether a linear assign is possible

Definition at line 1613 of file xreducer.hpp.

◆ is_contiguous()

template<class F, class CT, class X, class O>
bool xt::xreducer< F, CT, X, O >::is_contiguous ( ) const
inlinenoexcept

Definition at line 1489 of file xreducer.hpp.

◆ layout()

template<class F, class CT, class X, class O>
layout_type xt::xreducer< F, CT, X, O >::layout ( ) const
inlinenoexcept

Returns the shape of the expression.

Definition at line 1483 of file xreducer.hpp.

◆ operator()()

template<class F, class CT, class X, class O>
template<class... Args>
auto xt::xreducer< F, CT, X, O >::operator() ( Args... args) const -> const_reference
inline

Returns a constant reference to the element at the specified position in the reducer.

Parameters
argsa 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.

Definition at line 1508 of file xreducer.hpp.

◆ options()

template<class F, class CT, class X, class O>
const O & xt::xreducer< F, CT, X, O >::options ( ) const
inline

Definition at line 892 of file xreducer.hpp.

◆ shape()

template<class F, class CT, class X, class O>
auto xt::xreducer< F, CT, X, O >::shape ( ) const
inlinenoexcept

Returns the shape of the expression.

Definition at line 1474 of file xreducer.hpp.

◆ stepper_begin()

template<class F, class CT, class X, class O>
template<class S>
auto xt::xreducer< F, CT, X, O >::stepper_begin ( const S & shape) const -> const_stepper
inlinenoexcept

Definition at line 1622 of file xreducer.hpp.

◆ stepper_end()

template<class F, class CT, class X, class O>
template<class S>
auto xt::xreducer< F, CT, X, O >::stepper_end ( const S & shape,
layout_type l ) const -> const_stepper
inlinenoexcept

Definition at line 1630 of file xreducer.hpp.

◆ unchecked()

template<class F, class CT, class X, class O>
template<class... Args>
auto xt::xreducer< F, CT, X, O >::unchecked ( Args... args) const -> const_reference
inline

Returns a constant reference to the element at the specified position in the reducer.

Parameters
argsa 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.
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.
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);
xarray_container< uvector< T, A >, L, xt::svector< typename uvector< T, A >::size_type, 4, SA, true > > xarray
Alias template on xarray_container with default parameters for data container type and shape / stride...

Definition at line 1537 of file xreducer.hpp.

◆ xreducer_stepper< F, CT, X, O >

template<class F, class CT, class X, class O>
friend class xreducer_stepper< F, CT, X, O >
friend

Definition at line 906 of file xreducer.hpp.

Member Data Documentation

◆ contiguous_layout

template<class F, class CT, class X, class O>
bool xt::xreducer< F, CT, X, O >::contiguous_layout = false
staticconstexpr

Definition at line 846 of file xreducer.hpp.

◆ static_layout

template<class F, class CT, class X, class O>
layout_type xt::xreducer< F, CT, X, O >::static_layout = layout_type::dynamic
staticconstexpr

Definition at line 845 of file xreducer.hpp.


The documentation for this class was generated from the following files:
  • /home/runner/work/xtensor/xtensor/include/xtensor/io/xmime.hpp
  • /home/runner/work/xtensor/xtensor/include/xtensor/reducers/xreducer.hpp