Skip to content

LayoutPolicy

#include <layout.hh>
template<typename Derived>
struct LayoutPolicy

Defined 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.

  • Derived CRTP-template parameter.
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
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.

const inline

inline NCA_HD bool is_pointer_axis(ssize_t axis) const

Defined 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.


const inline

inline NCA_HD bool is_contiguous_impl() const

Defined 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.


const inline

inline NCA_HD void * advance(void * data, ssize_t axis, ssize_t index) const

Defined 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.

  • data The pointer to the current position in the array.

  • axis The current axis being traversed.

  • index The current index along the traversed axis.

The pointer to the next item in the array.


const inline

inline NCA_HD const void * advance(const void * data, ssize_t axis, ssize_t index) const

Defined 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.

  • data The pointer to the current position in the array.

  • axis The current axis being traversed.

  • index The current index along the traversed axis.

The const pointer to the next item in the array.


const inline

template<typename Coords> inline NCA_HD void * advance(void * data, const Coords & coords) const

Defined 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.

  • data The pointer to the current position in the array.

  • coords The coordinates specifying the indices of all axes to traverse.

The pointer to the specified item in the array.


const inline

template<typename Coords> inline NCA_HD const void * advance(const void * data, const Coords & coords) const

Defined 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.

  • data The pointer to the current position in the array.

  • coords The coordinates specifying the indices of all axes to traverse.

The const pointer to the specified item in the array.


const inline

inline NCA_HD const ssize_t * shape() const

Defined in src/lib/ncarray/layout.hh:232

The pointer to the underlying shape metadata.

The pointer to the underlying shape metadata.


const inline

inline NCA_HD ssize_t shape(ssize_t dim) const

Defined in src/lib/ncarray/layout.hh:243

The shape of a given axis of an array.

  • dim A dimension to check the shape of.

The shape of that dimension.


const inline

inline NCA_HD ssize_t ndim() const

Defined in src/lib/ncarray/layout.hh:252

The total number of dimensions.

The total number of dimensions.


const inline

inline NCA_HD ssize_t size() const

Defined in src/lib/ncarray/layout.hh:261

The total number of elements in the array.

The total number of elements in the array.


const inline

inline NCA_HD const ssize_t * strides() const

Defined in src/lib/ncarray/layout.hh:274

The pointer to the underlying strides metadata.

The pointer to the underlying strides metadata.


const inline

inline NCA_HD ssize_t stride(ssize_t dim) const

Defined in src/lib/ncarray/layout.hh:285

The strides along a given axis of an array.

  • dim A dimension to check the stride for.

The stride along that dimension.


const inline

inline NCA_HD const char * layout_repr() const

Defined 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.

A C-style string for representing the Layout type.


const inline

inline NCA_HD void build_new_axes(AxisDescr * new_axes, const IndexItem * indices, ssize_t num_indices) const

Defined in src/lib/ncarray/layout.hh:309

Provided a set of indexing arguments construct the description of the new axes given the layout specification.

  • new_axes A set of AxisDescr struct length NCARRAY_MAX_NDIM to build the descriptions into.

  • indices The indices, consisting of collections of integers, slices and ellipsis in any combination.

  • num_indices The total number of indices provided.


const inline

inline NCA_HDMetadata::value_type get_offset(ssize_t axis) const

Defined 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.

  • dim A dimension to check the stride for.

The offset/suboffset along that dimension.


const inline

inline NCA_HD bool layout_matches(const LayoutPolicy< Derived > & other) const

Defined 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.

  • other The other array Layout.

Whether the Layout matches.

Return Name Description
Metadata m_shape
Metadata m_strides
Metadata::value_type m_pointer_axis

Metadata m_shape

Defined in src/lib/ncarray/layout.hh:464


Metadata m_strides

Defined in src/lib/ncarray/layout.hh:465


Metadata::value_type m_pointer_axis { -1 }

Defined in src/lib/ncarray/layout.hh:468