Order and layout¶
How the axes of a tensor are laid out in memory: orders, and the index to offset mappings.
Concepts¶
| Name | Description |
|---|---|
concrete_order | An Order<...> with its axes spelled out. |
order_for_rank | Whether O can lay out Rank axes: always for RowMajor / ColumnMajor, for an Order only of that rank. |
order_like | Anything that names a layout: a concrete Order, or RowMajor / ColumnMajor for any rank. |
same_order | Whether two orders lay out Rank axes the same way, however they are spelled. |
symbolic_order | RowMajor or ColumnMajor, which stand for an order of any rank. |
Types¶
| Name | Description |
|---|---|
ColumnMajor | Column-major order: the first axis varies fastest, as in Eigen and Fortran. |
Dense | A dense layout policy: Dense<> (column-major), Dense<RowMajor>, Dense<Order<2, 0, 1>>. |
DenseMapping | The index to offset map of a dense layout. |
Order | How the axes of a dense tensor are laid out in memory, fastest-varying axis first. |
RowMajor | Row-major order: the last axis varies fastest, as in C and NumPy. |
Strided | A strided layout policy, one stride per axis. |
StridedMapping | The index to offset map for arbitrary strides, one per axis. |
Functions¶
permute_mapping¶
template <std::size_t... Permutation, shape_like S, order_like O>
constexpr auto permute_mapping(const DenseMapping<S, O> &mapping) noexcept
The dense mapping with its axes permuted: new axis k is old axis Permutation[k].
template <std::size_t... Permutation, shape_like S, Extent... Strides>
constexpr auto permute_mapping(const StridedMapping<S, Strides...> &mapping) noexcept
The strided mapping with its axes permuted: new axis k is old axis Permutation[k].
drop_axis_mapping¶
template <std::size_t Axis, typename Mapping>
constexpr auto drop_axis_mapping(const Mapping &mapping) noexcept
The mapping without axis Axis.
Dense memory sliced along its slowest axis is still dense; along any other axis the remaining elements are spread out, so the result is strided.
block_mapping¶
template <typename Mapping, shape_like BlockShape>
constexpr auto block_mapping(const Mapping &mapping, const BlockShape &sizes) noexcept
The mapping of a sub-box of shape sizes, with the same strides.
The view moves its pointer to the corner of the box.
expand_mapping¶
template <std::size_t... Inserted, typename Mapping, shape_like Space>
constexpr auto expand_mapping(const Mapping &mapping, const Space &space) noexcept
The mapping of the same memory read in a shape with new axes: the operand's axes keep their strides, the new ones Inserted have stride 0, so that each position along them is the same element.
An element is then at many positions: only for a view that reads.
diagonal_mapping¶
template <std::size_t... Axes, typename Mapping>
constexpr auto diagonal_mapping(const Mapping &mapping) noexcept
The mapping of the diagonal over Axes: one axis, at the place of the first, which moves by the strides of all of them.
Never dense, since the memory it skips is not contiguous.
Aliases¶
concrete_order_t¶
template <typename O, std::size_t Rank>
using strata::concrete_order_t = detail::resolve_order<O, Rank>::type
The concrete Order that O means for Rank axes.
concrete_order_t<ColumnMajor, 3> is Order<0, 1, 2>.
canonical_order_t¶
The shortest spelling of O: ColumnMajor or RowMajor where O is one of them at its rank (ColumnMajor for rank 0 or 1), otherwise O itself.
permute_order_t¶
template <typename O, std::size_t... Permutation>
using strata::permute_order_t = canonical_order_t<typename detail::order_of_axes<
detail::permuted_axes<concrete_order_t<O, sizeof...(Permutation)>, Permutation...>()>::type>
The order of the same memory after permuting the axes: new axis k is old axis Permutation[k].
drop_axis_order_t¶
template <typename O, std::size_t Rank, std::size_t Axis>
using strata::drop_axis_order_t =
canonical_order_t<typename detail::order_of_axes<detail::dropped_axes<concrete_order_t<O, Rank>, Axis>()>::type>
The order of the same memory with axis Axis dropped: the axes after it move down by one.
permute_layout_t¶
template <typename Layout, std::size_t... Permutation>
using strata::permute_layout_t = detail::permute_layout<Layout, Permutation...>::type
The layout of the same memory after permuting the axes; defined for layouts that support it.
memory_order_t¶
template <typename Mapping>
using strata::memory_order_t = detail::order_of_axes<detail::memory_axes<Mapping>()>::type
The order a mapping's memory is best walked in, as an Order, fastest axis first.
Order<1, 0> for a row-major matrix, and for Strided<Dyn, 1> too.