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

Proxy class for efficiently constructing slice ArrayViews by using the generic ArrayBase constructor in ArrayView. This avoids the cost of looking up the correct allocator ID from the other ArrayView constructors. More...

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

Inheritance diagram for axom::detail::ArraySubslice< T, SliceDim, BaseArray >:

Public Types

using RealConstT = typename std::conditional< is_array_view, T, const T >::type
 
using ConstSliceType = typename std::conditional< DIM==IdxDim, RealConstT &, typename detail::SubsliceProxy< T, DIM - IdxDim, const ArraySubslice< T, SliceDim, BaseArray > >::type >::type
 

Public Member Functions

AXOM_HOST_DEVICE ArraySubslice (BaseArray *array, const StackArray< IndexType, NumIndices > &idxs)
 
AXOM_HOST_DEVICE IndexType size () const
 Return the number of elements stored in the data array. More...
 
IndexType spacing () const
 
AXOM_HOST_DEVICE int getAllocatorID () const
 Get the ID for the umpire allocator. More...
 
AXOM_HOST_DEVICE SliceType< sizeof...(Args)> operator() (Args... args)
 Dimension-aware accessor; with N=DIM indices, returns a reference to the given value at that index. Otherwise, returns a sub-array pointed to by the given sub-index. More...
 
AXOM_HOST_DEVICE ConstSliceType< sizeof...(Args)> operator() (Args... args) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
AXOM_HOST_DEVICE SliceType< 1 > operator[] (const IndexType idx)
 Scalar accessor; returns a sub-array referenced by the given sub- index, beginning at array(idx, 0...) More...
 
AXOM_HOST_DEVICE ConstSliceType< 1 > operator[] (const IndexType idx) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
AXOM_HOST_DEVICE SliceType< UDim > operator[] (const StackArray< IndexType, UDim > &idx)
 Dimension-aware accessor; with UDim=DIM indices, returns a reference to the given value at that index. Otherwise, returns a sub-array pointed to by the given sub-index. More...
 
AXOM_HOST_DEVICE ConstSliceType< UDim > operator[] (const StackArray< IndexType, UDim > &idx) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void swap (ArrayBase &other)
 Swaps two ArrayBases. More...
 
AXOM_HOST_DEVICE const StackArray< IndexType, DIM > & shape () const
 Returns the dimensions of the Array. More...
 
AXOM_HOST_DEVICE const MDMapping< DIM > & mapping () const
 Returns the multidimensional mapping for the Array. More...
 
AXOM_HOST_DEVICE const StackArray< IndexType, DIM > & strides () const
 Returns the memory strides of the Array. More...
 
AXOM_HOST_DEVICE IndexType minStride () const
 Returns the minimum stride between adjacent items. More...
 
AXOM_HOST_DEVICE T * data () const
 Return a pointer to the array of data. More...
 
AXOM_HOST_DEVICE T & flatIndex (const IndexType idx)
 Accessor, returns a reference to the given value. For multidimensional arrays, indexes into the (flat) raw data. More...
 
AXOM_HOST_DEVICE RealConstTflatIndex (const IndexType idx) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 

Static Public Attributes

constexpr static int Dims
 

Protected Member Functions

template<int UDim>
AXOM_HOST_DEVICE SliceType< UDim > sliceImpl (const StackArray< IndexType, UDim > &idx) const
 
AXOM_HOST_DEVICE void setShape (const StackArray< IndexType, DIM > &shape_)
 Set the shape. More...
 
AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE void setShapeAndStride (const StackArray< IndexType, DIM > &shape, const StackArray< IndexType, DIM > &stride)
 Set the shape and stride. More...
 
IndexType blockSize () const
 Returns the minimum "chunk size" that should be allocated For example, 2 would be the chunk size of a 2D array whose second dimension is of size 2. This is used when resizing/reallocating; it wouldn't make sense to have a capacity of 3 in the array described above. More...
 
AXOM_HOST_DEVICE void updateStrides (int min_stride=1)
 Updates the internal striding information to a row-major format Intended to be called after shape is updated. More...
 
void updateShapeOnInsert (const StackArray< IndexType, DIM > &range_shape)
 Updates the internal dimensions and striding based on the insertion of a range of elements. Intended to be called after the insertion of a multidimensional subslice. More...
 

Protected Attributes

friend BaseClass
 
StackArray< IndexType, DIM > m_shape
 The extent in each direction. More...
 
MDMapping< DIM > m_mapping
 For converting between multidim indices and offset. More...
 
IndexType m_minStride
 Cached value for optimization. More...
 

Detailed Description

template<typename T, int SliceDim, typename BaseArray>
class axom::detail::ArraySubslice< T, SliceDim, BaseArray >

Proxy class for efficiently constructing slice ArrayViews by using the generic ArrayBase constructor in ArrayView. This avoids the cost of looking up the correct allocator ID from the other ArrayView constructors.

Member Typedef Documentation

◆ RealConstT

using axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::RealConstT = typename std::conditional<is_array_view, T, const T>::type
inherited

◆ ConstSliceType

using axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::ConstSliceType = typename std::conditional<DIM == IdxDim, RealConstT&, typename detail::SubsliceProxy<T, DIM - IdxDim, const ArraySubslice< T, SliceDim, BaseArray > >::type>::type
inherited

Constructor & Destructor Documentation

◆ ArraySubslice()

template<typename T , int SliceDim, typename BaseArray >
AXOM_HOST_DEVICE axom::detail::ArraySubslice< T, SliceDim, BaseArray >::ArraySubslice ( BaseArray *  array,
const StackArray< IndexType, NumIndices > &  idxs 
)
inline

Member Function Documentation

◆ size()

template<typename T , int SliceDim, typename BaseArray >
AXOM_HOST_DEVICE IndexType axom::detail::ArraySubslice< T, SliceDim, BaseArray >::size ( ) const
inline

Return the number of elements stored in the data array.

◆ data()

template<typename T , int SliceDim, typename BaseArray >
AXOM_HOST_DEVICE T* axom::detail::ArraySubslice< T, SliceDim, BaseArray >::data ( ) const
inline

Return a pointer to the array of data.

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

◆ spacing()

template<typename T , int SliceDim, typename BaseArray >
IndexType axom::detail::ArraySubslice< T, SliceDim, BaseArray >::spacing ( ) const
inline

◆ getAllocatorID()

template<typename T , int SliceDim, typename BaseArray >
AXOM_HOST_DEVICE int axom::detail::ArraySubslice< T, SliceDim, BaseArray >::getAllocatorID ( ) const
inline

Get the ID for the umpire allocator.

◆ sliceImpl()

template<typename T , int SliceDim, typename BaseArray >
template<int UDim>
AXOM_HOST_DEVICE SliceType<UDim> axom::detail::ArraySubslice< T, SliceDim, BaseArray >::sliceImpl ( const StackArray< IndexType, UDim > &  idx) const
inlineprotected

◆ operator()() [1/2]

AXOM_HOST_DEVICE SliceType<sizeof...(Args)> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::operator() ( Args...  args)
inlineinherited

Dimension-aware accessor; with N=DIM indices, returns a reference to the given value at that index. Otherwise, returns a sub-array pointed to by the given sub-index.

Parameters
[in]argsthe parameter pack of indices in each dimension.
Note
equivalent to *(array.data() + idx).
Precondition
sizeof...(Args) <= DIM
0 <= args[i] < shape()[i] for i in [0, sizeof...(Args))

◆ operator()() [2/2]

AXOM_HOST_DEVICE ConstSliceType<sizeof...(Args)> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::operator() ( Args...  args) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator[]() [1/4]

AXOM_HOST_DEVICE SliceType<1> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::operator[] ( const IndexType  idx)
inlineinherited

Scalar accessor; returns a sub-array referenced by the given sub- index, beginning at array(idx, 0...)

Parameters
[in]idxthe index of the first dimension.
Precondition
0 <= idx < shape()[0]

◆ operator[]() [2/4]

AXOM_HOST_DEVICE ConstSliceType<1> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::operator[] ( const IndexType  idx) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator[]() [3/4]

AXOM_HOST_DEVICE SliceType<UDim> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::operator[] ( const StackArray< IndexType, UDim > &  idx)
inlineinherited

Dimension-aware accessor; with UDim=DIM indices, returns a reference to the given value at that index. Otherwise, returns a sub-array pointed to by the given sub-index.

Parameters
[in]argsa stack array of indices in each dimension.
Note
equivalent to *(array.data() + idx).
Precondition
UDim <= DIM
0 <= args[i] < shape()[i] for i in [0, UDim)

◆ operator[]() [4/4]

AXOM_HOST_DEVICE ConstSliceType<UDim> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::operator[] ( const StackArray< IndexType, UDim > &  idx) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ flatIndex() [1/2]

AXOM_HOST_DEVICE T& axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::flatIndex ( const IndexType  idx)
inlineinherited

Accessor, returns a reference to the given value. For multidimensional arrays, indexes into the (flat) raw data.

Parameters
[in]idxthe position of the value to return.
Note
equivalent to *(array.data() + idx * minStride()).
Precondition
0 <= idx < asDerived().size()

◆ flatIndex() [2/2]

AXOM_HOST_DEVICE RealConstT& axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::flatIndex ( const IndexType  idx) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ swap()

void axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::swap ( ArrayBase< T, SliceDim, ArraySubslice< T, SliceDim, BaseArray > > &  other)
inlineinherited

Swaps two ArrayBases.

◆ shape()

AXOM_HOST_DEVICE const StackArray<IndexType, DIM>& axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::shape ( ) const
inlineinherited

Returns the dimensions of the Array.

◆ mapping()

AXOM_HOST_DEVICE const MDMapping<DIM>& axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::mapping ( ) const
inlineinherited

Returns the multidimensional mapping for the Array.

◆ strides()

AXOM_HOST_DEVICE const StackArray<IndexType, DIM>& axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::strides ( ) const
inlineinherited

Returns the memory strides of the Array.

◆ minStride()

AXOM_HOST_DEVICE IndexType axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::minStride ( ) const
inlineinherited

Returns the minimum stride between adjacent items.

◆ setShape()

AXOM_HOST_DEVICE void axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::setShape ( const StackArray< IndexType, DIM > &  shape_)
inlineprotectedinherited

Set the shape.

◆ setShapeAndStride()

AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE void axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::setShapeAndStride ( const StackArray< IndexType, DIM > &  shape,
const StackArray< IndexType, DIM > &  stride 
)
inlineprotectedinherited

Set the shape and stride.

◆ blockSize()

IndexType axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::blockSize ( ) const
inlineprotectedinherited

Returns the minimum "chunk size" that should be allocated For example, 2 would be the chunk size of a 2D array whose second dimension is of size 2. This is used when resizing/reallocating; it wouldn't make sense to have a capacity of 3 in the array described above.

◆ updateStrides()

AXOM_HOST_DEVICE void axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::updateStrides ( int  min_stride = 1)
inlineprotectedinherited

Updates the internal striding information to a row-major format Intended to be called after shape is updated.

◆ updateShapeOnInsert()

void axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::updateShapeOnInsert ( const StackArray< IndexType, DIM > &  range_shape)
inlineprotectedinherited

Updates the internal dimensions and striding based on the insertion of a range of elements. Intended to be called after the insertion of a multidimensional subslice.

Member Data Documentation

◆ BaseClass

template<typename T , int SliceDim, typename BaseArray >
friend axom::detail::ArraySubslice< T, SliceDim, BaseArray >::BaseClass
protected

◆ Dims

constexpr static int axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::Dims
staticconstexprinherited

◆ m_shape

StackArray<IndexType, DIM> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::m_shape
protectedinherited

The extent in each direction.

◆ m_mapping

MDMapping<DIM> axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::m_mapping
protectedinherited

For converting between multidim indices and offset.

◆ m_minStride

IndexType axom::ArrayBase< T, DIM, ArraySubslice< T, SliceDim, BaseArray > >::m_minStride
protectedinherited

Cached value for optimization.

See also
minStride()

For some reason, computing min stride in minStride() slows down flatIndex() for CUDA and HIP, even though it doesn't seem tricky to optimize. As a work around, we cache the value in m_minStrides and update it when m_mapping changes. BTNG, March 2024.


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