Skip to content

LayoutPolicy

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

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

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:121

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:134

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:152

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.

The pointer to the next item in the array.

Parameter Type Description
data void * The pointer to the current position in the array.
axis ssize_t The current axis being traversed.
index ssize_t The current index along the traversed axis.

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:169

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.

The const pointer to the next item in the array.

Parameter Type Description
data const void * The pointer to the current position in the array.
axis ssize_t The current axis being traversed.
index ssize_t The current index along the traversed axis.

const inline

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

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

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.

The pointer to the specified item in the array.

Parameter Type Description
data void * The pointer to the current position in the array.
coords const Coords & The coordinates specifying the indices of all axes to traverse.

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:199

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.

The const pointer to the specified item in the array.

Parameter Type Description
data const void * The pointer to the current position in the array.
coords const Coords & The coordinates specifying the indices of all axes to traverse.

const inline

inline NCA_HD const ssize_t * shape() const

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

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:219

The shape of a given axis of an array.

The shape of that dimension.

Parameter Type Description
dim ssize_t A dimension to check the shape of.

const inline

inline NCA_HD ssize_t ndim() const

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

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:237

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:250

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:261

The strides along a given axis of an array.

The stride along that dimension.

Parameter Type Description
dim ssize_t A dimension to check the stride for.

const inline

inline NCA_HD const char * layout_repr() const

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

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:285

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

Parameter Type Description
new_axes [AxisDescr](api-ncarray-AxisDescr.md#axisdescr) * A set of AxisDescr struct length NCARRAY_MAX_NDIM to build the descriptions into.
indices const [IndexItem](api-ncarray-IndexItem.md#indexitem) * The indices, consisting of collections of integers, slices and ellipsis in any combination.
num_indices ssize_t 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:400

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.

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:416

Check whether another array’s layout matches my own.

When layout’s match perfectly, then certain optimizations can be done during expression evaluation.

Whether the Layout matches.

Parameter Type Description
other const [LayoutPolicy](#layoutpolicy-1)< Derived > & The other array Layout.
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:440


Metadata m_strides

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


Metadata::value_type m_pointer_axis { -1 }

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