xfunctor_view

Defined in xtensor/xfunctor_view.hpp

template <class F, class CT>
class xfunctor_view : public xt::xview_semantic<xfunctor_view<F, CT>>, public extension::xfunctor_view_base_t<F, CT>

View of an xexpression .

The xfunctor_view class is an expression addressing its elements by applying a functor to the corresponding element of an underlying expression. Unlike e.g. xgenerator, an xfunctor_view is an lvalue. It is used e.g. to access real and imaginary parts of complex expressions.

xfunctor_view is not meant to be used directly, but through helper functions such as real or imag.

See
real, imag
Template Parameters
  • F: the functor type to be applied to the elements of specified expression.
  • CT: the closure type of the xexpression type underlying this view

Constructors

xfunctor_view(CT e)

Constructs an xfunctor_view expression wrappering the specified xexpression.

Parameters
  • e: the underlying expression

template <class Func, class E>
xfunctor_view(Func &&func, E &&e)

Constructs an xfunctor_view expression wrappering the specified xexpression.

Parameters
  • func: the functor to be applied to the elements of the underlying expression.
  • e: the underlying expression

Extended copy semantic

template <class E>
auto operator=(const xexpression<E> &e)

The extended assignment operator.

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 layout_type of the expression.

Data

auto expression()

Returns a reference to the underlying expression of the view.

auto expression() const

Returns a consttant reference to the underlying expression of the view.

template <class... Args>
auto operator()(Args... args)

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

Parameters
  • args: a 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 expression.

template <class... Args>
auto at(Args... args)

Returns a 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>
auto unchecked(Args... args)

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

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

template <class S>
auto operator[](const S &index)

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

Parameters
  • index: a sequence of indices specifying the position in the function. Indices must be unsigned integers, the number of indices in the sequence should be equal or greater than the number of dimensions of the container.

template <class IT>
auto element(IT first, IT last)

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

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

template <class... Args>
auto operator()(Args... args) const

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

Parameters
  • args: a 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 expression.

template <class... Args>
auto at(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>
auto unchecked(Args... args) const

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

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

template <class S>
auto operator[](const S &index) const

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

Parameters
  • index: a sequence of indices specifying the position in the function. Indices must be unsigned integers, the number of indices in the sequence should be equal or greater than the number of dimensions of the container.

template <class IT>
auto element(IT first, IT last) const

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

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

Broadcasting

template <class S>
bool broadcast_shape(S &shape, bool reuse_cache = false) const

Broadcast the shape of the function to the specified parameter.

Return
a boolean indicating whether the broadcasting is trivial
Parameters
  • shape: the result shape
  • reuse_cache: boolean for reusing a previously computed shape

template <class S>
bool has_linear_assign(const S &strides) const

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

Return
a boolean indicating whether a linear assign is possible

Iterators

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto begin()

Returns an iterator to the first element of the expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto end()

Returns an iterator to the element following the last element of the expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto begin() const

Returns a constant iterator to the first element of the expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto end() const

Returns a constant iterator to the element following the last element of the expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto cbegin() const

Returns a constant iterator to the first element of the expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto cend() const

Returns a constant iterator to the element following the last element of the expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

Broadcast iterators

template <class S, layout_type L>
auto begin(const S &shape)

Returns a constant iterator to the first element of the expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto end(const S &shape)

Returns a constant iterator to the element following the last element of the expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto begin(const S &shape) const

Returns a constant iterator to the first element of the expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto end(const S &shape) const

Returns a constant iterator to the element following the last element of the expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto cbegin(const S &shape) const

Returns a constant iterator to the first element of the expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto cend(const S &shape) const

Returns a constant iterator to the element following the last element of the expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

Reverse iterators

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto rbegin()

Returns an iterator to the first element of the reversed expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto rend()

Returns an iterator to the element following the last element of the reversed expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto rbegin() const

Returns a constant iterator to the first element of the reversed expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto rend() const

Returns a constant iterator to the element following the last element of the reversed expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto crbegin() const

Returns a constant iterator to the first element of the reversed expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <layout_type L = XTENSOR_DEFAULT_LAYOUT>
auto crend() const

Returns a constant iterator to the element following the last element of the reversed expression.

Template Parameters
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

Reverse broadcast iterators

template <class S, layout_type L>
auto rbegin(const S &shape)

Returns an iterator to the first element of the expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto rend(const S &shape)

Returns an iterator to the element following the last element of the reversed expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto rbegin(const S &shape) const

Returns a constant iterator to the first element of the reversed expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto rend(const S&) const

Returns a constant iterator to the element following the last element of the reversed expression.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto crbegin(const S&) const

Returns a constant iterator to the first element of the reversed expression.

The iteration is broadcasted to the specified shape.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

template <class S, layout_type L>
auto crend(const S &shape) const

Returns a constant iterator to the element following the last element of the reversed expression.

Parameters
  • shape: the shape used for broadcasting
Template Parameters
  • S: type of the shape parameter.
  • L: layout used for the traversal. Default value is XTENSOR_DEFAULT_LAYOUT.

Defined in xtensor/xcomplex.hpp

template <class E>
decltype(auto) xt::real(E &&e)

Returns an xexpression representing the real part of the given expression.

The returned expression either hold a const reference to

e or a copy depending on whether e is an lvalue or an rvalue.
Template Parameters

template <class E>
decltype(auto) xt::imag(E &&e)

Returns an xexpression representing the imaginary part of the given expression.

The returned expression either hold a const reference to

e or a copy depending on whether e is an lvalue or an rvalue.
Template Parameters