LayoutPolicy
LayoutPolicy
Section titled “LayoutPolicy”#include <layout.hh>template<typename Derived>struct LayoutPolicyDefined in src/lib/ncarray/layout.hh:139
The LayoutPolicy dictates the overall organization of an array object. E.g. if it has offsets or suboffsets.
Currently, all types of arrays inherit from the base LayoutPolicy which gives them a shape and stride. Specializations can provide additional features.
All subclasses must implement the advance function which is the key mechanism dictating how the array’s layout can be traversed.
Parameters
Section titled “Parameters”DerivedCRTP-template parameter.
List of all members
Section titled “List of all members”| Name | Kind | Owner |
|---|---|---|
is_pointer_axis |
function |
Declared here |
is_contiguous_impl |
function |
Declared here |
advance |
function |
Declared here |
advance |
function |
Declared here |
advance |
function |
Declared here |
advance |
function |
Declared here |
shape |
function |
Declared here |
shape |
function |
Declared here |
ndim |
function |
Declared here |
size |
function |
Declared here |
strides |
function |
Declared here |
stride |
function |
Declared here |
layout_repr |
function |
Declared here |
build_new_axes |
function |
Declared here |
get_offset |
function |
Declared here |
layout_matches |
function |
Declared here |
m_shape |
variable |
Declared here |
m_strides |
variable |
Declared here |
m_pointer_axis |
variable |
Declared here |
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
NCA_HD bool |
is_pointer_axis const inline |
Helper function to determine whether a given axis contains pointers. If true, this axis is a “double pointer” or involves suboffsets, etc. depending on the specialization. |
NCA_HD bool |
is_contiguous_impl const inline |
Check if any pointer axes exist. |
NCA_HD void * |
advance const inline |
The advance function takes a pointer to the current position in the array as well as an axis and index. Using this information, and the knowledge of the array layout it will move the pointer forward one data unit, accounting for strides, offsets, pointer jumps and so on. |
NCA_HD const void * |
advance const inline |
The advance function takes a pointer to the current position in the array as well as an axis and index. Using this information, and the knowledge of the array layout it will move the pointer forward one data unit, accounting for strides, offsets, pointer jumps and so on. |
NCA_HD void * |
advance const inline |
The advance function overload takes a pointer to the current position in the array as well as a Coords (StaticCoords) object. The coords object provides multiple indices for multiple axes to traverse at once. |
NCA_HD const void * |
advance const inline |
The advance function overload takes a pointer to the current position in the array as well as a Coords (StaticCoords) object. The coords object provides multiple indices for multiple axes to traverse at once. |
NCA_HD const ssize_t * |
shape const inline |
The pointer to the underlying shape metadata. |
NCA_HD ssize_t |
shape const inline |
The shape of a given axis of an array. |
NCA_HD ssize_t |
ndim const inline |
The total number of dimensions. |
NCA_HD ssize_t |
size const inline |
The total number of elements in the array. |
NCA_HD const ssize_t * |
strides const inline |
The pointer to the underlying strides metadata. |
NCA_HD ssize_t |
stride const inline |
The strides along a given axis of an array. |
NCA_HD const char * |
layout_repr const inline |
The repr functions return a string to identify the layout policy when writing out string representations of the array. |
NCA_HD void |
build_new_axes const inline |
Provided a set of indexing arguments construct the description of the new axes given the layout specification. |
NCA_HDMetadata::value_type |
get_offset const inline |
The offset/suboffset along a given axis of an array. |
NCA_HD bool |
layout_matches const inline |
Check whether another array’s layout matches my own. |
is_pointer_axis
Section titled “is_pointer_axis”const inline
inline NCA_HD bool is_pointer_axis(ssize_t axis) constDefined in src/lib/ncarray/layout.hh:145
Helper function to determine whether a given axis contains pointers. If true, this axis is a “double pointer” or involves suboffsets, etc. depending on the specialization.
is_contiguous_impl
Section titled “is_contiguous_impl”const inline
inline NCA_HD bool is_contiguous_impl() constDefined in src/lib/ncarray/layout.hh:158
Check if any pointer axes exist.
For simplicity a loop is used here. NCOffsets could optimize, but its a fairly fast operation anyway.
advance
Section titled “advance”const inline
inline NCA_HD void * advance(void * data, ssize_t axis, ssize_t index) constDefined in src/lib/ncarray/layout.hh:176
The advance function takes a pointer to the current position in the array as well as an axis and index. Using this information, and the knowledge of the array layout it will move the pointer forward one data unit, accounting for strides, offsets, pointer jumps and so on.
Parameters
Section titled “Parameters”-
dataThe pointer to the current position in the array. -
axisThe current axis being traversed. -
indexThe current index along the traversed axis.
Returns
Section titled “Returns”The pointer to the next item in the array.
advance
Section titled “advance”const inline
inline NCA_HD const void * advance(const void * data, ssize_t axis, ssize_t index) constDefined in src/lib/ncarray/layout.hh:193
The advance function takes a pointer to the current position in the array as well as an axis and index. Using this information, and the knowledge of the array layout it will move the pointer forward one data unit, accounting for strides, offsets, pointer jumps and so on.
This is the const overload.
Parameters
Section titled “Parameters”-
dataThe pointer to the current position in the array. -
axisThe current axis being traversed. -
indexThe current index along the traversed axis.
Returns
Section titled “Returns”The const pointer to the next item in the array.
advance
Section titled “advance”const inline
template<typename Coords> inline NCA_HD void * advance(void * data, const Coords & coords) constDefined in src/lib/ncarray/layout.hh:207
The advance function overload takes a pointer to the current position in the array as well as a Coords (StaticCoords) object. The coords object provides multiple indices for multiple axes to traverse at once.
Parameters
Section titled “Parameters”-
dataThe pointer to the current position in the array. -
coordsThe coordinates specifying the indices of all axes to traverse.
Returns
Section titled “Returns”The pointer to the specified item in the array.
advance
Section titled “advance”const inline
template<typename Coords> inline NCA_HD const void * advance(const void * data, const Coords & coords) constDefined in src/lib/ncarray/layout.hh:223
The advance function overload takes a pointer to the current position in the array as well as a Coords (StaticCoords) object. The coords object provides multiple indices for multiple axes to traverse at once.
This is the const overload.
Parameters
Section titled “Parameters”-
dataThe pointer to the current position in the array. -
coordsThe coordinates specifying the indices of all axes to traverse.
Returns
Section titled “Returns”The const pointer to the specified item in the array.
const inline
inline NCA_HD const ssize_t * shape() constDefined in src/lib/ncarray/layout.hh:232
The pointer to the underlying shape metadata.
Returns
Section titled “Returns”The pointer to the underlying shape metadata.
const inline
inline NCA_HD ssize_t shape(ssize_t dim) constDefined in src/lib/ncarray/layout.hh:243
The shape of a given axis of an array.
Parameters
Section titled “Parameters”dimA dimension to check the shape of.
Returns
Section titled “Returns”The shape of that dimension.
const inline
inline NCA_HD ssize_t ndim() constDefined in src/lib/ncarray/layout.hh:252
The total number of dimensions.
Returns
Section titled “Returns”The total number of dimensions.
const inline
inline NCA_HD ssize_t size() constDefined in src/lib/ncarray/layout.hh:261
The total number of elements in the array.
Returns
Section titled “Returns”The total number of elements in the array.
strides
Section titled “strides”const inline
inline NCA_HD const ssize_t * strides() constDefined in src/lib/ncarray/layout.hh:274
The pointer to the underlying strides metadata.
Returns
Section titled “Returns”The pointer to the underlying strides metadata.
stride
Section titled “stride”const inline
inline NCA_HD ssize_t stride(ssize_t dim) constDefined in src/lib/ncarray/layout.hh:285
The strides along a given axis of an array.
Parameters
Section titled “Parameters”dimA dimension to check the stride for.
Returns
Section titled “Returns”The stride along that dimension.
layout_repr
Section titled “layout_repr”const inline
inline NCA_HD const char * layout_repr() constDefined in src/lib/ncarray/layout.hh:295
The repr functions return a string to identify the layout policy when writing out string representations of the array.
Returns
Section titled “Returns”A C-style string for representing the Layout type.
build_new_axes
Section titled “build_new_axes”const inline
inline NCA_HD void build_new_axes(AxisDescr * new_axes, const IndexItem * indices, ssize_t num_indices) constDefined in src/lib/ncarray/layout.hh:309
Provided a set of indexing arguments construct the description of the new axes given the layout specification.
Parameters
Section titled “Parameters”-
new_axesA set of AxisDescr struct length NCARRAY_MAX_NDIM to build the descriptions into. -
indicesThe indices, consisting of collections of integers, slices and ellipsis in any combination. -
num_indicesThe total number of indices provided.
get_offset
Section titled “get_offset”const inline
inline NCA_HDMetadata::value_type get_offset(ssize_t axis) constDefined in src/lib/ncarray/layout.hh:424
The offset/suboffset along a given axis of an array.
This function can be used to retrieve offsets or suboffsets without knowledge of which one is implemented by the Derived layout type.
Parameters
Section titled “Parameters”dimA dimension to check the stride for.
Returns
Section titled “Returns”The offset/suboffset along that dimension.
layout_matches
Section titled “layout_matches”const inline
inline NCA_HD bool layout_matches(const LayoutPolicy< Derived > & other) constDefined in src/lib/ncarray/layout.hh:440
Check whether another array’s layout matches my own.
When layout’s match perfectly, then certain optimizations can be done during expression evaluation.
Parameters
Section titled “Parameters”otherThe other array Layout.
Returns
Section titled “Returns”Whether the Layout matches.
Protected Attributes
Section titled “Protected Attributes”| Return | Name | Description |
|---|---|---|
Metadata |
m_shape |
|
Metadata |
m_strides |
|
Metadata::value_type |
m_pointer_axis |
m_shape
Section titled “m_shape”Metadata m_shapeDefined in src/lib/ncarray/layout.hh:464
m_strides
Section titled “m_strides”Metadata m_stridesDefined in src/lib/ncarray/layout.hh:465
m_pointer_axis
Section titled “m_pointer_axis”Metadata::value_type m_pointer_axis { -1 }Defined in src/lib/ncarray/layout.hh:468