xstrides

Defined in xtensor/xstrides.hpp

group xt_xstrides

Enums

enum class stride_type

Choose stride type.

Values:

enumerator internal

As used internally (with stride(axis) == 0 if shape(axis) == 1)

enumerator normal

Normal stride corresponding to storage.

enumerator bytes

Normal stride in bytes.

Functions

template<class offset_type, class S, class Arg, class ...Args>
inline offset_type data_offset(const S &strides, Arg arg, Args... args) noexcept

Return the flat index for an array index.

Given m arguments, and dimension nof the array (n == strides.size()).

  • If m == n, the index is strides[0] * index[0] + ... + strides[n - 1] * index[n - 1].

  • If m < n and the last argument is xt::missing the indices are zero-padded at the end to match the dimension of the array. The index is then strides[0] * index[0] + ... + strides[m - 1] * index[m - 1].

  • If m < n (and the last argument is not xt::missing), the index is strides[n - m - 1] * index[0] + ... + strides[n - 1] * index[m - 1].

  • If m > n, then the first m - n arguments are ignored. The index is then strides[0] * index[m - n] + ... + strides[n - 1] * index[m - 1].

Parameters:
  • strides – Strides of the array.

  • args – Array index.

Returns:

The flat index.

template<layout_type L = layout_type::dynamic, class shape_type, class strides_type>
inline std::size_t compute_strides(const shape_type &shape, layout_type l, strides_type &strides)

Compute the strides given the shape and the layout of an array.

Parameters:
  • shape – Shape of the array.

  • l – Layout type, see xt::layout_type().

  • strides – (output) Strides of the array.

Returns:

The size: the product of the shape.

template<class S, class ...Args>
inline void normalize_periodic(const S &shape, Args&... args)

Normalise an index of a periodic array.

For example if the shape is (3, 4) and the index is (3, -4) the result is (0, 0).

Parameters:
  • shape – Shape of the array.

  • args – (input/output) Array index.

template<class E>
inline auto strides(const E &e, stride_type type = stride_type::normal) noexcept

Get strides of an object.

Parameters:

a – an array

Returns:

array

template<class E>
inline auto strides(const E &e, std::size_t axis, stride_type type = stride_type::normal) noexcept

Get stride of an object along an axis.

Parameters:

a – an array

Returns:

integer