xstrided_view

Defined in xtensor/xstrided_view.hpp

template <class CT, class S, class FS = typename detail::flat_storage_type<CT>::type>
class xt::xstrided_view

View of an xexpression using strides.

The xstrided_view class implements a view utilizing an initial offset and strides.

See
strided_view, transpose
Template Parameters
  • CT: the closure type of the xexpression type underlying this view
  • S: the strides type of the strided view
  • FS: the flat storage type used for the strided view.

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

Extended copy semantic

template <class E>
auto xt::xstrided_viewoperator=(const xexpression<E> &e)

The extended assignment operator.

Constructor

template <class CTA>
xt::xstrided_viewxstrided_view(CTA &&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 xt::xstrided_viewsize() const

Returns the size of the xstrided_view.

auto xt::xstrided_viewdimension() const

Returns the number of dimensions of the xstrided_view.

auto xt::xstrided_viewshape() const

Returns the shape of the xstrided_view.

Data

template <class… Args>
auto xt::xstrided_viewoperator()(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 xt::xstrided_viewat(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 xt::xstrided_viewat(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 xt::xstrided_viewelement(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 xt::xstrided_viewbroadcast_shape(O &shape, bool reuse_cache = false) 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 xt::xstrided_viewis_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.

typedef xt::slice_vector

vector of slices used to build a xstrided_view

template <class E>
auto xt::dynamic_view(E &&e, const slice_vector &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({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

You can also achieve the same with the following short-hand syntax:

xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}};
auto v = xt::dynamic_view(a, {xt::range(0, 1), xt::range(0, 3, 2)});
// ==> {{1, 3}}

template <layout_type L, class E>
auto xt::ravel(E &&e)

Returns a flatten view of the given expression.

No copy is made.

Parameters
  • e: the input expression
Template Parameters
  • L: the layout used to read the elements of e
  • E: the type of the expression

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

Returns a flatten view of the given expression.

No copy is made. The layout used to read the elements is the one of e.

Parameters
  • e: the input expression
Template Parameters
  • E: the type of the expression

template <class E>
auto xt::trim_zeros(E &&e, const std::string &direction = "fb")

Trim zeros at beginning, end or both of 1D sequence.

Return
returns a view without zeros at the beginning and end
Parameters
  • e: input xexpression
  • direction: string of either ‘f’ for trim from beginning, ‘b’ for trim from end or ‘fb’ (default) for both.

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

Returns a squeeze view of the given expression.

No copy is made. Squeezing an expression removes dimensions of extent 1.

Parameters
  • e: the input expression
Template Parameters
  • E: the type of the expression

template <class E, class S, class Tag = check_policy::none, std::enable_if_t<!std::is_integral< S >::value, int > = 0>
auto xt::squeeze(E &&e, S &&axis, Tag check_policy = Tag())

Remove single-dimensional entries from the shape of an xexpression.

Parameters
  • e: input xexpression
  • axis: integer or container of integers, select a subset of single-dimensional entries of the shape.
  • check_policy: select check_policy. With check_policy::full(), selecting an axis which is greater than one will throw a runtime_error.

template <class E>
auto xt::expand_dims(E &&e, std::size_t axis)

Expand the shape of an xexpression.

Insert a new axis that will appear at the axis position in the expanded array shape. This will return a dynamic_view with a xt::newaxis() at the indicated axis.

Return
returns a dynamic_view with expanded dimension
Parameters
  • e: input xexpression
  • axis: axis to expand

template <class E>
auto xt::split(E &e, std::size_t n, std::size_t axis = 0)

Split xexpression along axis into subexpressions.

This splits an xexpression along the axis in n equal parts and returns a vector of dynamic_view. Calling split with axis > dimension of e or a n that does not result in an equal division of the xexpression will throw a runtime_error.

Parameters
  • e: input xexpression
  • n: number of elements to return
  • axis: axis along which to split the expression

template <std::size_t N, class E>
auto xt::atleast_Nd(E &&e)

Expand dimensions of xexpression to at least N

This adds newaxis() slices to a dynamic_view until the dimension of the view reaches at least N. Note: dimensions are added equally at the beginning and the end. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1).

Return
dynamic_view with expanded dimensions
Parameters
  • e: input xexpression
Template Parameters
  • N: the number of requested dimensions

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

Expand to at least 1D.

See
atleast_Nd

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

Expand to at least 2D.

See
atleast_Nd

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

Expand to at least 3D.

See
atleast_Nd