HOPS
HOPS class reference
Classes | Public Member Functions | Static Public Member Functions | List of all members
hops::MHO_NDArrayMath Class Reference

utility functions for multidimensional array access More...

#include <MHO_NDArrayMath.hh>

Classes

struct  Divide
 enum Divide - compute integer division at compile time More...
 
struct  Divide< numerator, 1 >
 enum MHO_NDArrayMath::Divide<numerator, 1> specialization for base case of divide More...
 
struct  PowerOfTwo
 enum PowerOfTwo - compute 2^N at compile time More...
 
struct  PowerOfTwo< 0 >
 enum MHO_NDArrayMath::PowerOfTwo<0> specialization for base case of power of two More...
 

Public Member Functions

 MHO_NDArrayMath ()
 
virtual ~MHO_NDArrayMath ()
 

Static Public Member Functions

template<std::size_t RANK>
static bool CheckIndexValidity (const std::size_t *DimSize, const std::size_t *Index)
 Checks if all indices in Index are within valid range for a multidimensional array. More...
 
template<std::size_t RANK>
static bool DecrementIndices (const std::size_t *DimSize, std::size_t *Index)
 Decrements indices in a multidimensional by one, array using row major indexing. More...
 
template<std::size_t RANK>
static bool DecrementIndices (const std::size_t *DimSize, std::size_t *Index, std::size_t diff)
 Decrements indices in a multidimensional array by amount specified in diff, or until an underflow is reached. More...
 
template<std::size_t RANK>
static bool IncrementIndices (const std::size_t *DimSize, std::size_t *Index)
 Increment multi-dimensional indices by one in row-major order, accounting for roll-over. More...
 
template<std::size_t RANK>
static bool IncrementIndices (const std::size_t *DimSize, std::size_t *Index, std::size_t diff)
 Increment multi-dimensional indices by the amount in diff (accounting for roll-over) and return true if successful, false otherwise. More...
 
static std::size_t Modulus (std::size_t arg, std::size_t n)
 Calculates the modulus of two integers. More...
 
template<std::size_t RANK>
static std::size_t OffsetFromRowMajorIndex (const std::size_t *DimSize, const std::size_t *Index)
 Calculates offset into a multidimensional array using row-major indexing. More...
 
template<std::size_t RANK>
static std::size_t OffsetFromStrideIndex (const std::size_t *Strides, const std::size_t *Index)
 Calculates offset for a given index into a multidimensional array using row-major indexing/strides. More...
 
template<std::size_t RANK>
static void OffsetsForReversedIndices (const std::size_t *DimSize, std::size_t *ReversedIndex)
 Calculates reversed indices offsets for the given dimensions. More...
 
template<std::size_t RANK>
static void RowMajorIndexFromOffset (std::size_t offset, const std::size_t *DimSize, std::size_t *Index)
 Function RowMajorIndexFromOffset. More...
 
template<std::size_t RANK>
static std::size_t StrideFromRowMajorIndex (std::size_t selected_dim, const std::size_t *DimSize)
 Calculates stride for a given dimension in a row-major indexed multidimensional array. More...
 
template<std::size_t RANK>
static std::size_t TotalArraySize (const std::size_t *DimSize)
 Calculates total size of an array given its dimensions. More...
 

Detailed Description

utility functions for multidimensional array access

Date
Sun Jan 24 14:53:01 2021 -0500
Author
J. Barrett - barre.nosp@m.ttj@.nosp@m.mit.e.nosp@m.du

Constructor & Destructor Documentation

◆ MHO_NDArrayMath()

hops::MHO_NDArrayMath::MHO_NDArrayMath ( )
inline

◆ ~MHO_NDArrayMath()

virtual hops::MHO_NDArrayMath::~MHO_NDArrayMath ( )
inlinevirtual

Member Function Documentation

◆ CheckIndexValidity()

template<std::size_t RANK>
static bool hops::MHO_NDArrayMath::CheckIndexValidity ( const std::size_t *  DimSize,
const std::size_t *  Index 
)
inlinestatic

Checks if all indices in Index are within valid range for a multidimensional array.

Parameters
DimSizePointer to an array containing the dimensions of the multidimensional array.
IndexPointer to an array containing the indices of the element being accessed.
Returns
Boolean indicating whether all indices are valid (true if valid, false otherwise).
Note
This is a static function.

◆ DecrementIndices() [1/2]

template<std::size_t RANK>
static bool hops::MHO_NDArrayMath::DecrementIndices ( const std::size_t *  DimSize,
std::size_t *  Index 
)
inlinestatic

Decrements indices in a multidimensional by one, array using row major indexing.

Parameters
DimSizePointer to an array containing the dimensions of the multidimensional array.
IndexPointer to an array containing the current indices.
Returns
True if successful decrement, false if underflowed the 0-th dimension.
Note
This is a static function.

◆ DecrementIndices() [2/2]

template<std::size_t RANK>
static bool hops::MHO_NDArrayMath::DecrementIndices ( const std::size_t *  DimSize,
std::size_t *  Index,
std::size_t  diff 
)
inlinestatic

Decrements indices in a multidimensional array by amount specified in diff, or until an underflow is reached.

Template Parameters
RANKTemplate parameter RANK
Parameters
DimSizePointer to an array containing the dimensions of the multidimensional array.
IndexPointer to an array containing the current indices of the multidimensional array.
diff(std::size_t)
Returns
True if decrementing was successful, false if all dimensions have underflowed.
Note
This is a static function.

◆ IncrementIndices() [1/2]

template<std::size_t RANK>
static bool hops::MHO_NDArrayMath::IncrementIndices ( const std::size_t *  DimSize,
std::size_t *  Index 
)
inlinestatic

Increment multi-dimensional indices by one in row-major order, accounting for roll-over.

Parameters
DimSizePointer to an array containing dimension sizes
IndexPointer to an array containing current indices
Returns
True if increment was successful, false if overflow occurred
Note
This is a static function.

◆ IncrementIndices() [2/2]

template<std::size_t RANK>
static bool hops::MHO_NDArrayMath::IncrementIndices ( const std::size_t *  DimSize,
std::size_t *  Index,
std::size_t  diff 
)
inlinestatic

Increment multi-dimensional indices by the amount in diff (accounting for roll-over) and return true if successful, false otherwise.

Template Parameters
RANKTemplate parameter RANK
Parameters
DimSizePointer to an array containing dimension sizes
IndexPointer to an array of indices to increment
diff(std::size_t)
Returns
Boolean indicating success (true) or failure (false)
Note
This is a static function.

◆ Modulus()

static std::size_t hops::MHO_NDArrayMath::Modulus ( std::size_t  arg,
std::size_t  n 
)
inlinestatic

Calculates the modulus of two integers.

Parameters
argFirst integer operand
nSecond integer operand (modulus)
Returns
Result of arg modulo n
Note
This is a static function.

◆ OffsetFromRowMajorIndex()

template<std::size_t RANK>
static std::size_t hops::MHO_NDArrayMath::OffsetFromRowMajorIndex ( const std::size_t *  DimSize,
const std::size_t *  Index 
)
inlinestatic

Calculates offset into a multidimensional array using row-major indexing.

for a multidimensional array (using row major indexing) which has the dimensions specified in DimSize, this function computes the offset from the first element given the indices in the array Index

Template Parameters
RANKTemplate parameter RANK
Parameters
DimSizePointer to an array containing dimension sizes.
IndexPointer to an array of indices.
Returns
Offset from the first element (given the input indices).
Note
This is a static function.

◆ OffsetFromStrideIndex()

template<std::size_t RANK>
static std::size_t hops::MHO_NDArrayMath::OffsetFromStrideIndex ( const std::size_t *  Strides,
const std::size_t *  Index 
)
inlinestatic

Calculates offset for a given index into a multidimensional array using row-major indexing/strides.

for a multidimensional array (using row major indexing) which has the strides specified in Strides, this function computes the offset from the first element given the indices in the array Index

Template Parameters
RANKTemplate parameter RANK
Parameters
StridesArray of strides for each dimension
IndexIndices for each dimension
Returns
Offset from the first element (given the indices)
Note
This is a static function.

◆ OffsetsForReversedIndices()

template<std::size_t RANK>
static void hops::MHO_NDArrayMath::OffsetsForReversedIndices ( const std::size_t *  DimSize,
std::size_t *  ReversedIndex 
)
inlinestatic

Calculates reversed indices offsets for the given dimensions.

Template Parameters
RANKTemplate parameter RANK
Parameters
DimSizeInput array of dimension sizes
ReversedIndexOutput array to store reversed index offsets
Note
This is a static function.

◆ RowMajorIndexFromOffset()

template<std::size_t RANK>
static void hops::MHO_NDArrayMath::RowMajorIndexFromOffset ( std::size_t  offset,
const std::size_t *  DimSize,
std::size_t *  Index 
)
inlinestatic

Function RowMajorIndexFromOffset.

for a multidimensional array (using row major indexing) which has the dimensions specified in DimSize, this function computes the indices of the elements which has the given offset from the first element

Template Parameters
RANKTemplate parameter RANK
Parameters
offset(std::size_t)
DimSize(const std::size_t*)
Index(std::size_t*)
Note
This is a static function.

◆ StrideFromRowMajorIndex()

template<std::size_t RANK>
static std::size_t hops::MHO_NDArrayMath::StrideFromRowMajorIndex ( std::size_t  selected_dim,
const std::size_t *  DimSize 
)
inlinestatic

Calculates stride for a given dimension in a row-major indexed multidimensional array.

for a multidimensional array (using row major indexing) which has the dimensions specified in DimSize, this function computes the stride between consecutive elements in the selected dimension given that the other indices are fixed the first element given the indices in the array Index

Template Parameters
RANKTemplate parameter RANK
Parameters
selected_dimSelected dimension index
DimSizeArray containing dimensions sizes
Returns
Stride value as std::size_t
Note
This is a static function.

◆ TotalArraySize()

template<std::size_t RANK>
static std::size_t hops::MHO_NDArrayMath::TotalArraySize ( const std::size_t *  DimSize)
inlinestatic

Calculates total size of an array given its dimensions.

Parameters
DimSizePointer to an array of dimension sizes.
Returns
Total size of the array as a std::size_t.
Note
This is a static function.

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