AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::MDMapping< DIM, T > Class Template Reference

For indexing multidimensional arrays. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/main/src/axom/core/MDMapping.hpp>

Public Member Functions

AXOM_HOST_DEVICE MDMapping (const axom::StackArray< T, DIM > &shape, axom::ArrayStrideOrder arrayStrideOrder, int fastestStrideLength=1)
 Constructor for row- or column-major indexing. More...
 
template<typename DirType >
AXOM_HOST_DEVICE MDMapping (const axom::StackArray< T, DIM > &shape, const axom::StackArray< DirType, DIM > &slowestDirs, int fastestStrideLength=1)
 Constructor for a given order permutation. More...
 
AXOM_HOST_DEVICE MDMapping (const axom::StackArray< T, DIM > &shape, const axom::MDMapping< DIM, T > &orderSource)
 Constructor for a given shape with the ordering of an existing MDMapping. More...
 
AXOM_HOST_DEVICE MDMapping (const axom::StackArray< T, DIM > &strides)
 Constructor for arbitrary-stride indexing. More...
 
 MDMapping ()=default
 Default constructor. More...
 
AXOM_HOST_DEVICE MDMapping (ArrayStrideOrder arrayStrideOrder)
 Construct mapping for empty shape and the given stride order. More...
 
AXOM_HOST_DEVICE void initializeShape (const axom::StackArray< T, DIM > &shape, ArrayStrideOrder arrayStrideOrder, int fastestStrideLength=1)
 Initialize for row- or column-major indexing. More...
 
template<typename DirType >
AXOM_HOST_DEVICE void initializeShape (const axom::StackArray< T, DIM > &shape, const axom::StackArray< DirType, DIM > &slowestDirs, int fastestStrideLength=1)
 Initialize for a given order permutation. More...
 
AXOM_HOST_DEVICE void initializeShape (const axom::StackArray< T, DIM > &shape, const axom::MDMapping< DIM, T > &orderSource)
 Initialize for a given shape with the ordering of an existing MDMapping. More...
 
AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE void initializeStrides (const axom::StackArray< T, DIM > &strides)
 Initialize for arbitrary-stride indexing. More...
 
AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE void initializeStrides (const axom::StackArray< T, DIM > &strides, ArrayStrideOrder orderPref)
 Initialize for arbitrary-stride indexing, with ordering preference for non-unique strides. More...
 
AXOM_HOST_DEVICE bool operator== (const MDMapping &other) const
 
AXOM_HOST_DEVICE const axom::StackArray< std::uint16_t, DIM > & slowestDirs () const
 Index directions, ordered from slowest to fastest. More...
 
AXOM_HOST_DEVICE const axom::StackArray< axom::IndexType, DIM > & strides () const
 Strides. More...
 
AXOM_HOST_DEVICE axom::IndexType fastestStrideLength () const
 Stride length in fastest direction. More...
 
template<typename DirectionType >
AXOM_HOST_DEVICE bool isPermutation (const axom::StackArray< DirectionType, DIM > &v) const
 Whether a StackArray represents a permutation. More...
 
AXOM_HOST_DEVICE ArrayStrideOrder getStrideOrder () const
 Get the stride order (row- or column-major, or something else). More...
 
AXOM_HOST_DEVICEtoFlatIndex (const axom::StackArray< T, DIM > &multiIndex) const
 Convert multidimensional index to flat index. More...
 
AXOM_HOST_DEVICE axom::StackArray< T, DIM > toMultiIndex (T flatIndex) const
 Convert flat index to multidimensional index. More...
 

Static Public Member Functions

static AXOM_HOST_DEVICE bool stridesAreUnique (const axom::StackArray< T, DIM > &strides)
 

Friends

std::ostream & operator<< (std::ostream &os, const MDMapping &a)
 

Detailed Description

template<int DIM, typename T = axom::IndexType>
class axom::MDMapping< DIM, T >

For indexing multidimensional arrays.

Supports row-major and column-major ordering and arbitrary permutations of the ordering.

Constructor & Destructor Documentation

◆ MDMapping() [1/6]

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE axom::MDMapping< DIM, T >::MDMapping ( const axom::StackArray< T, DIM > &  shape,
axom::ArrayStrideOrder  arrayStrideOrder,
int  fastestStrideLength = 1 
)
inline

Constructor for row- or column-major indexing.

Parameters
[in]shapeShape of the array
[in]arrayStrideOrderAn order indicator, either ROW or COLUMN or if DIM == 1, BOTH.
[in]fastestStrideLengthStride in the fastest-changing direction.

References axom::MDMapping< DIM, T >::fastestStrideLength(), and axom::MDMapping< DIM, T >::initializeShape().

◆ MDMapping() [2/6]

template<int DIM, typename T = axom::IndexType>
template<typename DirType >
AXOM_HOST_DEVICE axom::MDMapping< DIM, T >::MDMapping ( const axom::StackArray< T, DIM > &  shape,
const axom::StackArray< DirType, DIM > &  slowestDirs,
int  fastestStrideLength = 1 
)
inline

Constructor for a given order permutation.

Parameters
[in]shapeShape of the array
[in]slowestDirspermutation vector, where slowestDirs[0] is the slowest direction and slowestDirs[DIM-1] is the fastest.
[in]fastestStrideLengthStride in the fastest-changing direction.

References axom::MDMapping< DIM, T >::fastestStrideLength(), axom::MDMapping< DIM, T >::initializeShape(), and axom::MDMapping< DIM, T >::slowestDirs().

◆ MDMapping() [3/6]

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE axom::MDMapping< DIM, T >::MDMapping ( const axom::StackArray< T, DIM > &  shape,
const axom::MDMapping< DIM, T > &  orderSource 
)
inline

Constructor for a given shape with the ordering of an existing MDMapping.

Parameters
[in]shapeShape of the array
[in]orderSourceArrayIndex to copy stride order from.

References axom::MDMapping< DIM, T >::initializeShape().

◆ MDMapping() [4/6]

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE axom::MDMapping< DIM, T >::MDMapping ( const axom::StackArray< T, DIM > &  strides)
inline

Constructor for arbitrary-stride indexing.

Parameters
[i]strides Strides. Must be unique when DIM > 1. If not unique, use default constructor and initializeStrides().

References axom::MDMapping< DIM, T >::initializeStrides(), and axom::MDMapping< DIM, T >::strides().

◆ MDMapping() [5/6]

template<int DIM, typename T = axom::IndexType>
axom::MDMapping< DIM, T >::MDMapping ( )
default

Default constructor.

Object must be initialized before use.

◆ MDMapping() [6/6]

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE axom::MDMapping< DIM, T >::MDMapping ( ArrayStrideOrder  arrayStrideOrder)
inline

Construct mapping for empty shape and the given stride order.

The expected use case is when a stride order is known but the shape is to be determined. Initialize the mapping with its own slowestDirs() to preserve stride order as its shape changes.

References axom::MDMapping< DIM, T >::initializeShape().

Member Function Documentation

◆ initializeShape() [1/3]

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE void axom::MDMapping< DIM, T >::initializeShape ( const axom::StackArray< T, DIM > &  shape,
ArrayStrideOrder  arrayStrideOrder,
int  fastestStrideLength = 1 
)
inline

Initialize for row- or column-major indexing.

Parameters
[in]shapeShape of the array
[in]arrayStrideOrderAn order indicator other than ArrayStrideOrder::ARBITRARY.
[in]fastestStrideLengthStride in the fastest-changing direction.

References axom::BOTH, axom::COLUMN, axom::MDMapping< DIM, T >::fastestStrideLength(), and axom::ROW.

◆ initializeShape() [2/3]

template<int DIM, typename T = axom::IndexType>
template<typename DirType >
AXOM_HOST_DEVICE void axom::MDMapping< DIM, T >::initializeShape ( const axom::StackArray< T, DIM > &  shape,
const axom::StackArray< DirType, DIM > &  slowestDirs,
int  fastestStrideLength = 1 
)
inline

Initialize for a given order permutation.

Parameters
[in]shapeShape of the array
[in]slowestDirspermutation vector, where slowestDirs[0] is the slowest direction and slowestDirs[DIM-1] is the fastest.
[in]fastestStrideLengthStride in the fastest-changing direction.

References axom::MDMapping< DIM, T >::fastestStrideLength(), axom::MDMapping< DIM, T >::isPermutation(), and axom::MDMapping< DIM, T >::slowestDirs().

◆ initializeShape() [3/3]

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE void axom::MDMapping< DIM, T >::initializeShape ( const axom::StackArray< T, DIM > &  shape,
const axom::MDMapping< DIM, T > &  orderSource 
)
inline

Initialize for a given shape with the ordering of an existing MDMapping.

Parameters
[in]shapeShape of the array
[in]orderSourceArrayIndex to copy stride order from.

References axom::MDMapping< DIM, T >::initializeShape(), and axom::MDMapping< DIM, T >::slowestDirs().

◆ initializeStrides() [1/2]

template<int DIM, typename T = axom::IndexType>
AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE void axom::MDMapping< DIM, T >::initializeStrides ( const axom::StackArray< T, DIM > &  strides)
inline

Initialize for arbitrary-stride indexing.

Parameters
[i]strides Strides. Values must be unique. If not unique, use one of the other initializers.

References axom::utilities::processAbort(), axom::ROW, axom::MDMapping< DIM, T >::strides(), and axom::MDMapping< DIM, T >::stridesAreUnique().

◆ initializeStrides() [2/2]

template<int DIM, typename T = axom::IndexType>
AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE void axom::MDMapping< DIM, T >::initializeStrides ( const axom::StackArray< T, DIM > &  strides,
ArrayStrideOrder  orderPref 
)
inline

Initialize for arbitrary-stride indexing, with ordering preference for non-unique strides.

Parameters
[i]strides Strides.
[i]orderPref ArrayStrideOrder::ROW or ArrayStrideOrder::COLUMN, to use where strides are non-unique.

References axom::COLUMN, axom::ROW, axom::MDMapping< DIM, T >::strides(), and axom::utilities::swap().

◆ stridesAreUnique()

template<int DIM, typename T = axom::IndexType>
static AXOM_HOST_DEVICE bool axom::MDMapping< DIM, T >::stridesAreUnique ( const axom::StackArray< T, DIM > &  strides)
inlinestatic

◆ operator==()

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE bool axom::MDMapping< DIM, T >::operator== ( const MDMapping< DIM, T > &  other) const
inline

◆ slowestDirs()

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE const axom::StackArray<std::uint16_t, DIM>& axom::MDMapping< DIM, T >::slowestDirs ( ) const
inline

Index directions, ordered from slowest to fastest.

◆ strides()

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE const axom::StackArray<axom::IndexType, DIM>& axom::MDMapping< DIM, T >::strides ( ) const
inline

Strides.

◆ fastestStrideLength()

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE axom::IndexType axom::MDMapping< DIM, T >::fastestStrideLength ( ) const
inline

Stride length in fastest direction.

◆ isPermutation()

template<int DIM, typename T = axom::IndexType>
template<typename DirectionType >
AXOM_HOST_DEVICE bool axom::MDMapping< DIM, T >::isPermutation ( const axom::StackArray< DirectionType, DIM > &  v) const
inline

Whether a StackArray represents a permutation.

References axom::utilities::insertionSort().

◆ getStrideOrder()

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE ArrayStrideOrder axom::MDMapping< DIM, T >::getStrideOrder ( ) const
inline

Get the stride order (row- or column-major, or something else).

Returns
Value from ArrayStrideOrder, indicating column order, row order, both column and row (1D only) or arbitrary order.

References axom::ARBITRARY, axom::BOTH, axom::COLUMN, and axom::ROW.

◆ toFlatIndex()

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE T axom::MDMapping< DIM, T >::toFlatIndex ( const axom::StackArray< T, DIM > &  multiIndex) const
inline

Convert multidimensional index to flat index.

References axom::StackArray< T, N >::begin(), and axom::numerics::dot_product().

◆ toMultiIndex()

template<int DIM, typename T = axom::IndexType>
AXOM_HOST_DEVICE axom::StackArray<T, DIM> axom::MDMapping< DIM, T >::toMultiIndex ( flatIndex) const
inline

Convert flat index to multidimensional index.

Friends And Related Function Documentation

◆ operator<<

template<int DIM, typename T = axom::IndexType>
std::ostream& operator<< ( std::ostream &  os,
const MDMapping< DIM, T > &  a 
)
friend

The documentation for this class was generated from the following file: