LvArray
Public Types | Static Public Attributes | Protected Attributes | List of all members
LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE > Class Template Reference

This class serves to provide a sliced multidimensional interface to the family of LvArray classes. More...

#include <ArraySlice.hpp>

Public Types

using ValueType = T
 The type of the value in the ArraySlice.
 
using IndexType = INDEX_TYPE
 The integer type used for indexing.
 

Public Member Functions

Constructors, destructor and assignment operators.
 ArraySlice ()=delete
 deleted default constructor
 
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK ArraySlice (T *const LVARRAY_RESTRICT inputData, INDEX_TYPE const *const LVARRAY_RESTRICT inputDimensions, INDEX_TYPE const *const LVARRAY_RESTRICT inputStrides) noexcept
 Construct a new ArraySlice. More...
 
ArraySlice creation methods and user defined conversions
LVARRAY_HOST_DEVICE constexpr ArraySlice< T const, NDIM, USD, INDEX_TYPE > toSliceConst () const noexcept
 
template<typename U = T>
LVARRAY_HOST_DEVICE constexpr operator std::enable_if_t< !std::is_const< U >::value, ArraySlice< T const, NDIM, USD, INDEX_TYPE > > () const noexcept
 
Attribute querying methods
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE size () const noexcept
 
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE size (int const dim) const noexcept
 
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE stride (int const dim) const noexcept
 
LVARRAY_HOST_DEVICE constexpr bool isContiguous () const
 Check if the slice is contiguous in memory. More...
 
template<typename ... INDICES>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE linearIndex (INDICES... indices) const
 
Methods that provide access to the data.
template<int NDIM_ = NDIM, int USD_ = USD>
LVARRAY_HOST_DEVICE constexpr operator std::enable_if_t< NDIM_==1 &&USD_==0, T *const LVARRAY_RESTRICT > () const noexcept
 
template<int U = NDIM>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK std::enable_if_t<(U > 1), ArraySlice< T, NDIM - 1, USD - 1, INDEX_TYPE > > operator[] (INDEX_TYPE const index) const noexcept
 
template<int U = NDIM>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK std::enable_if_t< U==1, T &> operator[] (INDEX_TYPE const index) const noexcept
 
template<typename ... INDICES>
LVARRAY_HOST_DEVICE constexpr T & operator() (INDICES... indices) const
 
template<int USD_ = USD>
LVARRAY_HOST_DEVICE T * dataIfContiguous () const
 
LVARRAY_HOST_DEVICE constexpr T * begin () const
 
LVARRAY_HOST_DEVICE constexpr T * end () const
 

Static Public Attributes

static constexpr int NDIM = NDIM_TPARAM
 The number of dimensions.
 
static constexpr int USD = USD_TPARAM
 The unit stride dimension.
 

Protected Attributes

T *const LVARRAY_RESTRICT m_data
 pointer to beginning of data for this array, or sub-array.
 
INDEX_TYPE const *const LVARRAY_RESTRICT m_dims
 pointer to array of length NDIM that contains the lengths of each array dimension
 
INDEX_TYPE const *const LVARRAY_RESTRICT m_strides
 pointer to array of length NDIM that contains the strides of each array dimension
 

Detailed Description

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
class LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >

This class serves to provide a sliced multidimensional interface to the family of LvArray classes.

Template Parameters
Ttype of data that is contained by the array
NDIM_TPARAMThe number of dimensions in array (e.g. NDIM=1->vector, NDIM=2->Matrix, etc. ).
USDThe dimension with a unit stride, in an Array with a standard layout this is the last dimension.
INDEX_TYPEThe integer to use for indexing the components of the array. This class serves as a sliced interface to an array. This is a lightweight class that contains only pointers, and provides an operator[] to create a lower dimensionsal slice and an operator() to access values given a multidimensional index. In general, instantiations of ArraySlice should only result either taking a slice of an an Array or an ArrayView via operator[] or from a direct creation via the toSlice/toSliceConst method.

Constructor & Destructor Documentation

◆ ArraySlice()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::ArraySlice ( T *const LVARRAY_RESTRICT  inputData,
INDEX_TYPE const *const LVARRAY_RESTRICT  inputDimensions,
INDEX_TYPE const *const LVARRAY_RESTRICT  inputStrides 
)
inlineexplicitnoexcept

Construct a new ArraySlice.

Parameters
inputDatapointer to the beginning of the data for this slice of the array
inputDimensionspointer to the beginning of the dimensions for this slice.
inputStridespointer to the beginning of the strides for this slice

Member Function Documentation

◆ begin()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE constexpr T* LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::begin ( ) const
inline
Returns
Return a pointer to the values.
Precondition
The slice must be contiguous.

◆ dataIfContiguous()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
template<int USD_ = USD>
LVARRAY_HOST_DEVICE T* LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::dataIfContiguous ( ) const
inline
Returns
Return a pointer to the values.
Template Parameters
USD_Dummy template parameter, do not specify.
Precondition
The slice must be contiguous.

◆ end()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE constexpr T* LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::end ( ) const
inline
Returns
Return a pointer to the end values.
Precondition
The slice must be contiguous.

◆ isContiguous()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE constexpr bool LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::isContiguous ( ) const
inline

Check if the slice is contiguous in memory.

Returns
true if represented slice is contiguous in memory

◆ linearIndex()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
template<typename ... INDICES>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::linearIndex ( INDICES...  indices) const
inline
Template Parameters
INDICESA variadic pack of integral types.
Returns
Return the linear index from a multidimensional index.
Parameters
indicesThe indices of the value to get the linear index of.

◆ operator std::enable_if_t< !std::is_const< U >::value, ArraySlice< T const, NDIM, USD, INDEX_TYPE > >()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
template<typename U = T>
LVARRAY_HOST_DEVICE constexpr LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::operator std::enable_if_t< !std::is_const< U >::value, ArraySlice< T const, NDIM, USD, INDEX_TYPE > > ( ) const
inlinenoexcept
Returns
Return a new immutable slice.

◆ operator std::enable_if_t< NDIM_==1 &&USD_==0, T *const LVARRAY_RESTRICT >()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
template<int NDIM_ = NDIM, int USD_ = USD>
LVARRAY_HOST_DEVICE constexpr LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::operator std::enable_if_t< NDIM_==1 &&USD_==0, T *const LVARRAY_RESTRICT > ( ) const
inlinenoexcept
Returns
A raw pointer.
Note
This method is only active when NDIM == 1 and USD == 0.

◆ operator()()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
template<typename ... INDICES>
LVARRAY_HOST_DEVICE constexpr T& LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::operator() ( INDICES...  indices) const
inline
Template Parameters
INDICESA variadic pack of integral types.
Returns
Return a reference to the value at the given multidimensional index.
Parameters
indicesThe indices of the value to access.

◆ operator[]() [1/2]

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
template<int U = NDIM>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK std::enable_if_t< (U > 1), ArraySlice< T, NDIM - 1, USD - 1, INDEX_TYPE > > LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::operator[] ( INDEX_TYPE const  index) const
inlinenoexcept
Returns
Return a lower dimensionsal slice of this ArrayView.
Parameters
indexThe index of the slice to create.
Note
This method is only active when NDIM > 1.

◆ operator[]() [2/2]

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
template<int U = NDIM>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK std::enable_if_t< U == 1, T & > LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::operator[] ( INDEX_TYPE const  index) const
inlinenoexcept
Returns
Return a reference to the value at the given index.
Parameters
indexThe index of the value to access.
Note
This method is only active when NDIM == 1.

◆ size() [1/2]

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::size ( ) const
inlinenoexcept
Returns
Return the total size of the slice.

◆ size() [2/2]

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::size ( int const  dim) const
inlinenoexcept
Returns
Return the length of the given dimension.
Parameters
dimthe dimension to get the length of.

◆ stride()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::stride ( int const  dim) const
inlinenoexcept
Returns
Return the stride of the given dimension.
Parameters
dimthe dimension to get the stride of.

◆ toSliceConst()

template<typename T, int NDIM_TPARAM, int USD_TPARAM, typename INDEX_TYPE>
LVARRAY_HOST_DEVICE constexpr ArraySlice< T const, NDIM, USD, INDEX_TYPE > LvArray::ArraySlice< T, NDIM_TPARAM, USD_TPARAM, INDEX_TYPE >::toSliceConst ( ) const
inlinenoexcept
Returns
Return a new immutable slice.

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