xstrided_view

Defined in xtensor/xstrided_view.hpp

template <class CT, class S, class CD>
class xt::xstrided_view

View of an xexpression using strides.

The xstrided_view class implements a view utilizing an offset and strides into a multidimensional xcontainer. The xstridedview is currently used to implement transpose.

See
strided_view, transpose
Template Parameters
  • CT: the closure type of the xexpression type underlying this view
  • CD: the closure type of the underlying data container

Inherits from xt::xview_semantic< xstrided_view< CT, S, CD > >, xt::xiterable< xstrided_view< CT, S, CD > >

Extended copy semantic

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

The extended assignment operator.

Constructor

xstrided_view(CT e, S &&shape, S &&strides, std::size_t offset, layout_type layout)

Constructs an xstrided_view.

Parameters
  • e: the underlying xexpression for this view
  • shape: the shape of the view
  • strides: the strides of the view
  • offset: the offset of the first element in the underlying container
  • layout: the layout of the view

Size and shape

auto size() const

Returns the size of the xstrided_view.

auto dimension() const

Returns the number of dimensions of the xstrided_view.

auto shape() const

Returns the shape of the xstrided_view.

Data

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

Returns the element at the specified position in the xstrided_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 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 It>
auto element(It first, It last)

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

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 the number of dimensions of the container..

Broadcasting

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

Broadcast the shape of the xstrided_view to the specified parameter.

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

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

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

Return
a boolean indicating whether the broadcasting is trivial

template <class E, class I>
auto xt::strided_view(E &&e, I &&shape, I &&strides, std::size_t offset = 0, layout_type layout = layout_type::dynamic)

Construct a strided view from an xexpression, shape, strides and offset.

Return
the view
Parameters
  • e: xexpression
  • shape: the shape of the view
  • strides: the new strides of the view
  • offset: the offset of the first element in the underlying container
  • layout: the new layout of the expression
Template Parameters
  • E: type of xexpression
  • I: shape and strides type

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

Returns a transpose view by reversing the dimensions of xexpression e.

Parameters
  • e: the input expression

template <class E, class S, class Tag = check_policy::none>
auto xt::transpose(E &&e, S &&permutation, Tag check_policy = Tag())

Returns a transpose view by permuting the xexpression e with permutation.

Parameters
  • e: the input expression
  • permutation: the sequence containing permutation
  • check_policy: the check level (check_policy::full() or check_policy::none())
Template Parameters
  • Tag: selects the level of error checking on permutation vector defaults to check_policy::none.

class xt::slice_vector

The slice_vector is used as part of the dynamic_view interface.

It offers an interface to dynamically push_back or append slices to dynamically create a view into a xexpression.

This data structure is necessary as the slices of xview are compile-time static. If you do not know how many dimensions your expression has at compile-time, using dynamic_view can be useful.

Internally, the dynamic_view is implemented using the strided_view adapter, which is very fast for data structures in contigous memory (such as xarrays and xtensors).

Usage example:

xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}};
xt::slice_vector sv(a, xt::range(0, 1));
sv.push_back(xt::all());

Inherits from std::vector< std::array< long int, 3 > >

Public Functions

template <class E, class… Args>
slice_vector(const xexpression<E> &e, Args... args)

Constructor for slice vector.

Parameters
  • e: xexpression
  • args: xslices, integer, all or newaxis

template <class… Args>
slice_vector(const std::vector<std::size_t> &shape, Args... args)

Alternative constructor taking a shape.

Parameters
  • shape: the shape

template <class T, class… Args>
void append(const T &s, Args... args)

Convenience function to append one or multiple slices to the slice_vector.

xt::slice_vector sv(a, xt::range(0, 1));
sv.append(xt::all(), xt::newaxis(), 0, 12));

template <class T>
void push_back(const xslice<T> &s)

Push back a single slice, integer, all or newaxis.

Parameters
  • s: slice

template <class E, class S>
auto xt::dynamic_view(E &&e, S &&slices)

Function to create a dynamic view from a xexpression and a slice_vector.

xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}};
xt::slice_vector sv(a, xt::range(0, 1));
sv.push_back(xt::range(0, 3, 2));
auto v = xt::dynamic_view(a, sv);
// ==> {{1, 3}}
Return
initialized strided_view according to slices
Parameters
  • e: xexpression
  • slices: the slice vector