xtensor
Loading...
Searching...
No Matches
Support functions swich between array indices and flat indices

Enumerations

enum class  xt::stride_type { xt::stride_type::internal = 0 , xt::stride_type::normal = 1 , xt::stride_type::bytes = 2 }
 Choose stride type. More...
 

Functions

template<class offset_type , class S , class Arg , class... Args>
offset_type xt::data_offset (const S &strides, Arg arg, Args... args) noexcept
 Return the flat index for an array index.
 
template<layout_type L = layout_type::dynamic, class shape_type , class strides_type >
std::size_t xt::compute_strides (const shape_type &shape, layout_type l, strides_type &strides)
 Compute the strides given the shape and the layout of an array.
 
template<class S , class... Args>
void xt::normalize_periodic (const S &shape, Args &... args)
 Normalise an index of a periodic array.
 
template<class E >
auto xt::strides (const E &e, stride_type type=stride_type::normal) noexcept
 Get strides of an object.
 
template<class E >
auto xt::strides (const E &e, std::size_t axis, stride_type type=stride_type::normal) noexcept
 Get stride of an object along an axis.
 

Detailed Description

Enumeration Type Documentation

◆ stride_type

Choose stride type.

Enumerator
internal 

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

normal 

Normal stride corresponding to storage.

bytes 

Normal stride in bytes.

Definition at line 233 of file xstrides.hpp.

Function Documentation

◆ compute_strides()

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

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

Parameters
shapeShape of the array.
lLayout type, see xt::layout_type().
strides(output) Strides of the array.
Returns
The size: the product of the shape.

Definition at line 566 of file xstrides.hpp.

◆ data_offset()

template<class offset_type , class S , class Arg , class... Args>
offset_type xt::data_offset ( const S & strides,
Arg arg,
Args... args )
inlinenoexcept

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
stridesStrides of the array.
argsArray index.
Returns
The flat index.

Definition at line 453 of file xstrides.hpp.

◆ normalize_periodic()

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

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
shapeShape of the array.
args(input/output) Array index.

Definition at line 909 of file xstrides.hpp.

◆ strides() [1/2]

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

Get stride of an object along an axis.

Parameters
aan array
Returns
integer

Definition at line 292 of file xstrides.hpp.

◆ strides() [2/2]

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

Get strides of an object.

Parameters
aan array
Returns
array

Definition at line 248 of file xstrides.hpp.