xview

Defined in xtensor/xview.hpp

template <class CT, class… S>
class xt::xview

Multidimensional view with tensor semantic.

The xview class implements a multidimensional view with tensor semantic. It is used to adapt the shape of an xexpression without changing it. xview is not meant to be used directly, but only with the view helper functions.

See
view, range, all, newaxis
Template Parameters
  • CT: the closure type of the xexpression to adapt
  • S: the slices type describing the shape adaptation

Inherits from xt::xview_semantic< xview< CT, S… > >, xt::xiterable< xview< CT, S… > >

Extended copy semantic

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

The extended assignment operator.

Constructor

template <class CTA, class FSL, class… SL>
xview(CTA &&e, FSL &&first_slice, SL&&... slices)

Constructs a view on the specified xexpression.

Users should not call directly this constructor but use the view function instead.

See
view
Parameters
  • e: the xexpression to adapt
  • first_slice: the first slice describing the view
  • slices: the slices list describing the view

Size and shape

auto dimension() const

Returns the number of dimensions of the view.

auto size() const

Returns the size of the expression.

auto shape() const

Returns the shape of the view.

auto slices() const

Returns the slices of the view.

layout_type layout() const

Returns the slices of the view.

Data

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

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

Parameters
  • args: a list of indices specifying the position in the view. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the view.

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 operator()(Args... args) const

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

Parameters
  • args: a list of indices specifying the position in the view. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the view.

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 T>
auto data() const

Returns the data holder of the underlying container (only if the view is on a realized container).

xt::eval will make sure that the underlying xexpression is on a realized container.

template <class T>
auto strides() const

Return the strides for the underlying container of the view.

template <class T>
auto raw_data() const

Return the pointer to the underlying buffer.

template <class T>
auto raw_data_offset() const

Return the offset to the first element of the view in the underlying container.

Broadcasting

template <class ST>
bool broadcast_shape(ST &shape) const

Broadcast the shape of the view to the specified parameter.

Return
a boolean indicating whether the broadcasting is trivial
Parameters
  • shape: the result shape

template <class ST>
bool is_trivial_broadcast(const ST &strides) const

Compares the specified strides with those of the view to see whether the broadcasting is trivial.

Return
a boolean indicating whether the broadcasting is trivial

template <class E, class… S>
auto xt::view(E &&e, S&&... slices)

Constructs and returns a view on the specified xexpression.

Users should not directly construct the slices but call helper functions instead.

See
range, all, newaxis
Parameters
  • e: the xexpression to adapt
  • slices: the slices list describing the view

Defined in xtensor/xslice.hpp

template <class T, class E = std::enable_if_t<!std::is_same<T, placeholders::xtuph>::value>>
auto xt::range(T min_val, T max_val)

Returns a slice representing an interval, to be used as an argument of view function.

See
view
Parameters
  • min_val: the first index of the interval
  • max_val: the last index of the interval

template <class T, class E = std::enable_if_t<!std::is_same<T, placeholders::xtuph>::value>>
auto xt::range(T min_val, T max_val, T step)

Returns a slice representing an interval, to be used as an argument of view function.

See
view
Parameters
  • min_val: the first index of the interval
  • max_val: the last index of the interval
  • step: the space between two indices

auto xt::all()

Returns a slice representing a full dimension, to be used as an argument of view function.

See
view

auto xt::newaxis()

Returns a slice representing a new axis of length one, to be used as an argument of view function.

See
view