xtensor
Loading...
Searching...
No Matches
xt::xgenerator< F, R, S > Class Template Reference

Multidimensional function operating on indices. More...

#include <xgenerator.hpp>

Inheritance diagram for xt::xgenerator< F, R, S >:
xt::xsharable_expression< xgenerator< F, R, S > > xt::xconst_iterable< xgenerator< F, R, S > > xt::xconst_accessible< xgenerator< F, R, S > > xt::xexpression< D >

Public Types

using self_type = xgenerator<F, R, S>
 
using functor_type = typename std::remove_reference<F>::type
 
using accessible_base = xconst_accessible<self_type>
 
using extension_base = extension::xgenerator_base_t<F, R, S>
 
using expression_tag = typename extension_base::expression_tag
 
using inner_types = xcontainer_inner_types<self_type>
 
using value_type = R
 
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 = std::ptrdiff_t
 
using iterable_base = xconst_iterable<self_type>
 
using inner_shape_type = typename iterable_base::inner_shape_type
 
using shape_type = inner_shape_type
 
using stepper = typename iterable_base::stepper
 
using const_stepper = typename iterable_base::const_stepper
 
using bool_load_type = xt::bool_load_type<R>
 
template<class OR , class OF >
using rebind_t = xgenerator<OF, OR, S>
 
- Public Types inherited from xt::xexpression< D >
using derived_type = D
 
- Public Types inherited from xt::xconst_iterable< xgenerator< F, R, S > >
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::xconst_accessible< xgenerator< F, R, S > >
using derived_type
 
using inner_types
 
using reference
 
using const_reference
 
using size_type
 

Public Member Functions

template<class... Args>
const_reference operator() (Args... args) const
 
template<class... Args>
const_reference unchecked (Args... args) const
 
template<class It >
const_reference element (It first, It last) const
 
template<class O >
const_stepper stepper_begin (const O &shape) const noexcept
 
template<class O >
const_stepper stepper_end (const O &shape, layout_type) const noexcept
 
template<class OR , class OF >
rebind_t< OR, OFbuild_generator (OF &&func) const
 
size_type shape (size_type index) const
 Returns the i-th dimension of the expression.
 
Constructor
template<class Func >
 xgenerator (Func &&f, const S &shape) noexcept
 Constructs an xgenerator applying the specified function over the given shape.
 
Size and shape
const inner_shape_type & shape () const noexcept
 Returns the shape of the xgenerator.
 
layout_type layout () const noexcept
 
bool is_contiguous () const noexcept
 
Data
template<class... Args>
auto operator() (Args... args) const -> const_reference
 Returns the evaluated element at the specified position in the function.
 
template<class... Args>
auto unchecked (Args... args) const -> const_reference
 Returns a constant reference to the element at the specified position in the expression.
 
template<class It >
auto element (It first, It last) const -> const_reference
 Returns a constant reference to the element at the specified position in the function.
 
- Public Member Functions inherited from xt::xexpression< D >
derived_typederived_cast () &noexcept
 Returns a reference to the actual derived type of the xexpression.
 
const derived_typederived_cast () const &noexcept
 Returns a constant reference to the actual derived type of the xexpression.
 
derived_type derived_cast () &&noexcept
 Returns a constant reference to the actual derived type of the xexpression.
 
- Public Member Functions inherited from xt::xconst_iterable< xgenerator< F, R, S > >
const_layout_iterator< Lbegin () const noexcept
 
const_broadcast_iterator< S, Lbegin (const S &shape) const noexcept
 
const_layout_iterator< Lend () const noexcept
 
const_broadcast_iterator< S, Lend (const S &shape) const noexcept
 
const_layout_iterator< Lcbegin () const noexcept
 
const_broadcast_iterator< S, Lcbegin (const S &shape) const noexcept
 
const_layout_iterator< Lcend () const noexcept
 
const_broadcast_iterator< S, Lcend (const S &shape) const noexcept
 
const_reverse_layout_iterator< Lrbegin () const noexcept
 
const_reverse_broadcast_iterator< S, Lrbegin (const S &shape) const noexcept
 
const_reverse_layout_iterator< Lrend () const noexcept
 
const_reverse_broadcast_iterator< S, Lrend (const S &shape) const noexcept
 
const_reverse_layout_iterator< Lcrbegin () const noexcept
 
const_reverse_broadcast_iterator< S, Lcrbegin (const S &shape) const noexcept
 
const_reverse_layout_iterator< Lcrend () const noexcept
 
const_reverse_broadcast_iterator< S, Lcrend (const S &shape) const noexcept
 
auto begin () const noexcept -> const_layout_iterator< L >
 Returns a constant iterator to the first element of the expression.
 
auto end () const noexcept -> const_layout_iterator< L >
 Returns a constant iterator to the element following the last element of the expression.
 
auto cbegin () const noexcept -> const_layout_iterator< L >
 Returns a constant iterator to the first element of the expression.
 
auto cend () const noexcept -> const_layout_iterator< L >
 Returns a constant iterator to the element following the last element of the expression.
 
auto begin (const S &shape) const noexcept -> const_broadcast_iterator< S, L >
 Returns a constant iterator to the first element of the expression.
 
auto end (const S &shape) const noexcept -> const_broadcast_iterator< S, L >
 Returns a constant iterator to the element following the last element of the expression.
 
auto cbegin (const S &shape) const noexcept -> const_broadcast_iterator< S, L >
 Returns a constant iterator to the first element of the expression.
 
auto cend (const S &shape) const noexcept -> const_broadcast_iterator< S, L >
 Returns a constant iterator to the element following the last element of the expression.
 
auto rbegin () const noexcept -> const_reverse_layout_iterator< L >
 Returns a constant iterator to the first element of the reversed expression.
 
auto rend () const noexcept -> const_reverse_layout_iterator< L >
 Returns a constant iterator to the element following the last element of the reversed expression.
 
auto crbegin () const noexcept -> const_reverse_layout_iterator< L >
 Returns a constant iterator to the first element of the reversed expression.
 
auto crend () const noexcept -> const_reverse_layout_iterator< L >
 Returns a constant iterator to the element following the last element of the reversed expression.
 
auto rbegin (const S &shape) const noexcept -> const_reverse_broadcast_iterator< S, L >
 Returns a constant iterator to the first element of the reversed expression.
 
auto rend (const S &shape) const noexcept -> const_reverse_broadcast_iterator< S, L >
 Returns a constant iterator to the element following the last element of the reversed expression.
 
auto crbegin (const S &shape) const noexcept -> const_reverse_broadcast_iterator< S, L >
 Returns a constant iterator to the first element of the reversed expression.
 
auto crend (const S &shape) const noexcept -> const_reverse_broadcast_iterator< S, L >
 Returns a constant iterator to the element following the last element of the reversed expression.
 
auto get_cbegin (bool end_index) const noexcept -> const_layout_iterator< L >
 
auto get_cbegin (const S &shape, bool end_index) const noexcept -> const_broadcast_iterator< S, L >
 
auto get_cend (bool end_index) const noexcept -> const_layout_iterator< L >
 
auto get_cend (const S &shape, bool end_index) const noexcept -> const_broadcast_iterator< S, L >
 
auto get_stepper_begin (const S &shape) const noexcept -> const_stepper
 
auto get_stepper_end (const S &shape, layout_type l) const noexcept -> const_stepper
 
- Public Member Functions inherited from xt::xconst_accessible< xgenerator< F, R, S > >
size_type size () const noexcept
 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
 
auto at (Args... args) const -> const_reference
 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
 
const_reference operator[] (std::initializer_list< I > index) const
 
const_reference operator[] (size_type i) const
 
auto operator[] (const S &index) const -> disable_integral_t< S, const_reference >
 Returns a constant reference to the element at the specified position in the expression.
 
auto operator[] (std::initializer_list< I > index) const -> const_reference
 
const_reference periodic (Args... args) const
 
auto periodic (Args... args) const -> const_reference
 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
 

Broadcasting

template<class O >
bool broadcast_shape (O &shape, bool reuse_cache=false) const
 Broadcast the shape of the function to the specified parameter.
 
template<class O >
bool has_linear_assign (const O &) const noexcept
 Checks whether the xgenerator can be linearly assigned to an expression with the specified strides.
 
template<class E , class FE = F, class = std::enable_if_t<has_assign_to<E, FE>::value>>
void assign_to (xexpression< E > &e) const noexcept
 
const functor_type & functor () const noexcept
 
template<class O = xt::dynamic_shape<typename shape_type::value_type>>
auto reshape (O &&shape) const &
 Reshapes the generator and keeps old elements.
 
template<class O = xt::dynamic_shape<typename shape_type::value_type>>
auto reshape (O &&shape) &&
 
template<class T >
auto reshape (std::initializer_list< T > shape) const &
 
template<class T >
auto reshape (std::initializer_list< T > shape) &&
 
template<class O >
auto stepper_begin (const O &shape) const noexcept -> const_stepper
 
template<class O >
auto stepper_end (const O &shape, layout_type) const noexcept -> const_stepper
 
template<class OR , class OF >
auto build_generator (OF &&func) const -> rebind_t< OR, OF >
 

Additional Inherited Members

- Protected Member Functions inherited from xt::xsharable_expression< xgenerator< F, R, S > >
 xsharable_expression (const xsharable_expression &)=default
 
 xsharable_expression (xsharable_expression &&)=default
 
xsharable_expressionoperator= (const xsharable_expression &)=default
 
xsharable_expressionoperator= (xsharable_expression &&)=default
 
- Protected Member Functions inherited from xt::xexpression< D >
 xexpression (const xexpression &)=default
 
xexpressionoperator= (const xexpression &)=default
 
 xexpression (xexpression &&)=default
 
xexpressionoperator= (xexpression &&)=default
 
- Protected Member Functions inherited from xt::xconst_iterable< xgenerator< F, R, S > >
const inner_shape_type & get_shape () const
 
- Protected Member Functions inherited from xt::xconst_accessible< xgenerator< F, R, S > >
 xconst_accessible (const xconst_accessible &)=default
 
 xconst_accessible (xconst_accessible &&)=default
 
xconst_accessibleoperator= (const xconst_accessible &)=default
 
xconst_accessibleoperator= (xconst_accessible &&)=default
 

Detailed Description

template<class F, class R, class S>
class xt::xgenerator< F, R, S >

Multidimensional function operating on indices.

The xgenerator class implements a multidimensional function, generating a value from the supplied indices.

Template Parameters
Fthe function type
Rthe return type of the function
Sthe shape type of the generator

Definition at line 106 of file xgenerator.hpp.

Member Typedef Documentation

◆ accessible_base

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::accessible_base = xconst_accessible<self_type>

Definition at line 116 of file xgenerator.hpp.

◆ bool_load_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::bool_load_type = xt::bool_load_type<R>

Definition at line 136 of file xgenerator.hpp.

◆ const_pointer

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::const_pointer = const value_type*

Definition at line 125 of file xgenerator.hpp.

◆ const_reference

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::const_reference = typename inner_types::const_reference

Definition at line 123 of file xgenerator.hpp.

◆ const_stepper

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::const_stepper = typename iterable_base::const_stepper

Definition at line 134 of file xgenerator.hpp.

◆ difference_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::difference_type = std::ptrdiff_t

Definition at line 127 of file xgenerator.hpp.

◆ expression_tag

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::expression_tag = typename extension_base::expression_tag

Definition at line 118 of file xgenerator.hpp.

◆ extension_base

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::extension_base = extension::xgenerator_base_t<F, R, S>

Definition at line 117 of file xgenerator.hpp.

◆ functor_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::functor_type = typename std::remove_reference<F>::type

Definition at line 114 of file xgenerator.hpp.

◆ inner_shape_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::inner_shape_type = typename iterable_base::inner_shape_type

Definition at line 130 of file xgenerator.hpp.

◆ inner_types

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::inner_types = xcontainer_inner_types<self_type>

Definition at line 120 of file xgenerator.hpp.

◆ iterable_base

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::iterable_base = xconst_iterable<self_type>

Definition at line 129 of file xgenerator.hpp.

◆ pointer

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::pointer = value_type*

Definition at line 124 of file xgenerator.hpp.

◆ rebind_t

template<class F , class R , class S >
template<class OR , class OF >
using xt::xgenerator< F, R, S >::rebind_t = xgenerator<OF, OR, S>

Definition at line 174 of file xgenerator.hpp.

◆ reference

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::reference = typename inner_types::reference

Definition at line 122 of file xgenerator.hpp.

◆ self_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::self_type = xgenerator<F, R, S>

Definition at line 113 of file xgenerator.hpp.

◆ shape_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::shape_type = inner_shape_type

Definition at line 131 of file xgenerator.hpp.

◆ size_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::size_type = typename inner_types::size_type

Definition at line 126 of file xgenerator.hpp.

◆ stepper

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::stepper = typename iterable_base::stepper

Definition at line 133 of file xgenerator.hpp.

◆ value_type

template<class F , class R , class S >
using xt::xgenerator< F, R, S >::value_type = R

Definition at line 121 of file xgenerator.hpp.

Constructor & Destructor Documentation

◆ xgenerator()

template<class F , class R , class S >
template<class Func >
xt::xgenerator< F, R, S >::xgenerator ( Func && f,
const S & shape )
inlinenoexcept

Constructs an xgenerator applying the specified function over the given shape.

Parameters
fthe function to apply
shapethe shape of the xgenerator

Definition at line 228 of file xgenerator.hpp.

Member Function Documentation

◆ assign_to()

template<class F , class R , class S >
template<class E , class , class >
void xt::xgenerator< F, R, S >::assign_to ( xexpression< E > & e) const
inlinenoexcept

Definition at line 375 of file xgenerator.hpp.

◆ broadcast_shape()

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

Broadcast the shape of the function 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 338 of file xgenerator.hpp.

◆ build_generator()

template<class F , class R , class S >
template<class OR , class OF >
auto xt::xgenerator< F, R, S >::build_generator ( OF && func) const -> rebind_t<OR, OF>
inline

Definition at line 389 of file xgenerator.hpp.

◆ element()

template<class F , class R , class S >
template<class It >
auto xt::xgenerator< F, R, S >::element ( It first,
It last ) const -> const_reference
inline

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

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 container.

Definition at line 317 of file xgenerator.hpp.

◆ functor()

template<class F , class R , class S >
auto xt::xgenerator< F, R, S >::functor ( ) const
inlinenoexcept

Definition at line 382 of file xgenerator.hpp.

◆ has_linear_assign()

template<class F , class R , class S >
template<class O >
bool xt::xgenerator< F, R, S >::has_linear_assign ( const O & ) const
inlinenoexcept

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

Returns
a boolean indicating whether a linear assign is possible

Definition at line 350 of file xgenerator.hpp.

◆ is_contiguous()

template<class F , class R , class S >
bool xt::xgenerator< F, R, S >::is_contiguous ( ) const
inlinenoexcept

Definition at line 256 of file xgenerator.hpp.

◆ layout()

template<class F , class R , class S >
layout_type xt::xgenerator< F, R, S >::layout ( ) const
inlinenoexcept

Definition at line 250 of file xgenerator.hpp.

◆ operator()()

template<class F , class R , class S >
template<class... Args>
auto xt::xgenerator< F, R, S >::operator() ( Args... args) const -> const_reference
inline

Returns the evaluated element at the specified position in the function.

Parameters
argsa list of indices specifying the position in the function. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the function.

Definition at line 275 of file xgenerator.hpp.

◆ reshape() [1/4]

template<class F , class R , class S >
template<class O >
auto xt::xgenerator< F, R, S >::reshape ( O && shape) &&
inline

Definition at line 413 of file xgenerator.hpp.

◆ reshape() [2/4]

template<class F , class R , class S >
template<class O >
auto xt::xgenerator< F, R, S >::reshape ( O && shape) const &
inline

Reshapes the generator and keeps old elements.

The shape argument can have one of its value equal to -1, in this case the value is inferred from the number of elements in the generator and the remaining values in the shape.

auto a = xt::arange<double>(50).reshape({-1, 10});
//a.shape() is {5, 10}
Parameters
shapethe new shape (has to have same number of elements as the original generator)

Definition at line 406 of file xgenerator.hpp.

◆ reshape() [3/4]

template<class F , class R , class S >
template<class T >
auto xt::xgenerator< F, R, S >::reshape ( std::initializer_list< T > shape) &&
inline

Definition at line 430 of file xgenerator.hpp.

◆ reshape() [4/4]

template<class F , class R , class S >
template<class T >
auto xt::xgenerator< F, R, S >::reshape ( std::initializer_list< T > shape) const &
inline

Definition at line 423 of file xgenerator.hpp.

◆ shape() [1/2]

template<class F , class R , class S >
auto xt::xgenerator< F, R, S >::shape ( ) const
inlinenoexcept

Returns the shape of the xgenerator.

Definition at line 244 of file xgenerator.hpp.

◆ shape() [2/2]

template<class F , class R , class S >
auto xt::xconst_accessible< D >::shape ( size_type index) const
inline

Returns the i-th dimension of the expression.

Definition at line 41 of file xaccessible.hpp.

◆ stepper_begin()

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

Definition at line 359 of file xgenerator.hpp.

◆ stepper_end()

template<class F , class R , class S >
template<class O >
auto xt::xgenerator< F, R, S >::stepper_end ( const O & shape,
layout_type  ) const -> const_stepper
inlinenoexcept

Definition at line 367 of file xgenerator.hpp.

◆ unchecked()

template<class F , class R , class S >
template<class... Args>
auto xt::xgenerator< F, R, S >::unchecked ( Args... args) const -> const_reference
inline

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

Parameters
argsa list of indices specifying the position in the expression. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the expression, 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);

Definition at line 303 of file xgenerator.hpp.

Member Data Documentation

◆ contiguous_layout

template<class F , class R , class S >
constexpr bool xt::xgenerator< F, R, S >::contiguous_layout = false
staticconstexpr

Definition at line 139 of file xgenerator.hpp.

◆ static_layout

template<class F , class R , class S >
constexpr layout_type xt::xgenerator< F, R, S >::static_layout = layout_type::dynamic
staticconstexpr

Definition at line 138 of file xgenerator.hpp.


The documentation for this class was generated from the following file: