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

A simple statically sized array of data with component-wise operators. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/latest/src/axom/primal/geometry/NumericArray.hpp>

Inheritance diagram for axom::primal::NumericArray< T, SIZE >:

Public Member Functions

AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE NumericArray (T val=T(), int sz=SIZE)
 Fill the first sz coordinates with val and zeros the rest. More...
 
AXOM_SUPPRESS_HD_WARN AXOM_HOST_DEVICE NumericArray (const T *vals, int sz=SIZE)
 Creates a numeric array from the first sz values of the input array. More...
 
 NumericArray (std::initializer_list< T > values)
 Creates a numeric array from an initializer list. More...
 
AXOM_HOST_DEVICE const T & operator[] (int i) const
 Access operator for individual components. More...
 
AXOM_HOST_DEVICE T & operator[] (int i)
 
AXOM_HOST_DEVICE const T * data () const
 Returns a pointer to the underlying data. More...
 
AXOM_HOST_DEVICE T * data ()
 
AXOM_HOST_DEVICE void to_array (T *arr) const
 Copy the coordinate data to the provided array. More...
 
std::ostream & print (std::ostream &os) const
 Simple formatted print of a numeric array instance. More...
 
AXOM_HOST_DEVICE NumericArrayoperator+= (const NumericArray &arr)
 Component-wise addition assignment operator. More...
 
AXOM_HOST_DEVICE NumericArrayoperator-= (const NumericArray &arr)
 Component-wise subtraction assignment operator. More...
 
AXOM_HOST_DEVICE NumericArrayoperator*= (double scalar)
 Scalar multiplication on the NumericArray instance. More...
 
AXOM_HOST_DEVICE NumericArrayoperator/= (double scalar)
 Scalar division on the NumericArray instance. More...
 
AXOM_HOST_DEVICE NumericArrayoperator*= (const NumericArray &arr)
 Component-wise multiplication assignment operator. More...
 
NumericArrayoperator/= (const NumericArray &arr)
 Component-wise division assignment operator. More...
 
NumericArrayclampUpper (const T &upperVal)
 Ensures that the highest value of the coordinates is at most upperVal. More...
 
NumericArrayclampLower (const T &lowerVal)
 Ensures that the lowest value of the coordinates is at least lowerVal. More...
 
NumericArrayclamp (const T &lowerVal, const T &upperVal)
 Ensures that each coordinate's value is in range [lowerVal,upperVal]. More...
 
max () const
 Find the max component. More...
 
min () const
 Find the min component. More...
 
int argMax () const
 Find the index of the max component. More...
 
int argMin () const
 Find the index of the min component. More...
 
sum () const
 Computes the sum of the components. More...
 

Static Public Member Functions

static int size ()
 Returns the dimension of this numeric array instance. More...
 

Protected Attributes

m_components [SIZE]
 

Detailed Description

template<typename T, int SIZE>
class axom::primal::NumericArray< T, SIZE >

A simple statically sized array of data with component-wise operators.

Template Parameters
Tthe numeric type of the elements in the array, e.g., float, double.
SIZEthe size of the array

Constructor & Destructor Documentation

◆ NumericArray() [1/3]

template<typename T , int SIZE>
AXOM_HOST_DEVICE axom::primal::NumericArray< T, SIZE >::NumericArray ( val = T(),
int  sz = SIZE 
)
explicit

Fill the first sz coordinates with val and zeros the rest.

Parameters
[in]valThe value to set the coordinates to. Defaults to zero.
[in]szThe number of components to set to val. The rest will be set to zero. Defaults is SIZE. If sz is greater than SIZE, we set all coordinates to val

References axom::utilities::clampVal(), and SLIC_ASSERT.

◆ NumericArray() [2/3]

template<typename T , int SIZE>
AXOM_HOST_DEVICE axom::primal::NumericArray< T, SIZE >::NumericArray ( const T *  vals,
int  sz = SIZE 
)
explicit

Creates a numeric array from the first sz values of the input array.

Parameters
[in]valsAn array containing at least sz values
[in]sznumber of coordinates. Defaults to SIZE.
Note
If sz is greater than SIZE, we only take the first SIZE values.

References axom::utilities::clampVal(), and SLIC_ASSERT.

◆ NumericArray() [3/3]

template<typename T , int SIZE>
axom::primal::NumericArray< T, SIZE >::NumericArray ( std::initializer_list< T >  values)
inline

Creates a numeric array from an initializer list.

Parameters
[in]valuesan initializer list containing the values of the array. If the size is not the same as the size of this array, this behaves the same way as the constructor which takes a pointer and size.

Member Function Documentation

◆ size()

template<typename T , int SIZE>
static int axom::primal::NumericArray< T, SIZE >::size ( )
inlinestatic

Returns the dimension of this numeric array instance.

Returns
d the dimension (size) of the array
Postcondition
d >= 1.

◆ operator[]() [1/2]

template<typename T , int SIZE>
AXOM_HOST_DEVICE const T & axom::primal::NumericArray< T, SIZE >::operator[] ( int  i) const
inline

Access operator for individual components.

Parameters
[in]ithe component index to access
Returns
\( p_i \) the value at the given component index.
Precondition
\( 0 \le i < SIZE \)

◆ operator[]() [2/2]

template<typename T , int SIZE>
AXOM_HOST_DEVICE T & axom::primal::NumericArray< T, SIZE >::operator[] ( int  i)
inline

◆ data() [1/2]

template<typename T , int SIZE>
AXOM_HOST_DEVICE const T * axom::primal::NumericArray< T, SIZE >::data
inline

Returns a pointer to the underlying data.

◆ data() [2/2]

template<typename T , int SIZE>
AXOM_HOST_DEVICE T * axom::primal::NumericArray< T, SIZE >::data
inline

◆ to_array()

template<typename T , int SIZE>
AXOM_HOST_DEVICE void axom::primal::NumericArray< T, SIZE >::to_array ( T *  arr) const

Copy the coordinate data to the provided array.

Parameters
[in]arrThe array to which we are copying.
Precondition
The user needs to make sure that the provided array has been allocated and has sufficient space for SIZE coordinates.

References SLIC_ASSERT.

◆ print()

template<typename T , int SIZE>
std::ostream & axom::primal::NumericArray< T, SIZE >::print ( std::ostream &  os) const

Simple formatted print of a numeric array instance.

Parameters
osThe output stream to write to
Returns
A reference to the modified ostream

◆ operator+=()

template<typename T , int SIZE>
AXOM_HOST_DEVICE NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::operator+= ( const NumericArray< T, SIZE > &  arr)
inline

Component-wise addition assignment operator.

Parameters
[in]arrthe array to add. Adds the numeric array arr to this instance (component-wise).
Returns
A reference to the NumericArray instance after addition.

◆ operator-=()

template<typename T , int SIZE>
AXOM_HOST_DEVICE NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::operator-= ( const NumericArray< T, SIZE > &  arr)
inline

Component-wise subtraction assignment operator.

Parameters
[in]arrthe array to subtract. Subtracts the numeric array arr from this instance (component-wise).
Returns
A reference to the NumericArray instance after subtraction.

◆ operator*=() [1/2]

template<typename T , int SIZE>
AXOM_HOST_DEVICE NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::operator*= ( double  scalar)
inline

Scalar multiplication on the NumericArray instance.

Parameters
[in]scalarthe scalar value with which to multiply. Each element of the numeric array is multiplied by scalar
Returns
A reference to the NumericArray instance after scalar multiplication.

◆ operator/=() [1/2]

template<typename T , int SIZE>
AXOM_HOST_DEVICE NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::operator/= ( double  scalar)
inline

Scalar division on the NumericArray instance.

Parameters
[in]scalarthe scalar value with which to divide .
Precondition
scalar != 0 Each element of the numeric array is divided by scalar
Returns
A reference to the NumericArray instance after scalar division.

References SLIC_ASSERT.

◆ operator*=() [2/2]

template<typename T , int SIZE>
AXOM_HOST_DEVICE NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::operator*= ( const NumericArray< T, SIZE > &  arr)
inline

Component-wise multiplication assignment operator.

Parameters
[in]arrthe array to multiply (component-wise). Multiplies the numeric array arr with this instance (component-wise).
Returns
A reference to the NumericArray instance after cwise multiplication.

◆ operator/=() [2/2]

template<typename T , int SIZE>
NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::operator/= ( const NumericArray< T, SIZE > &  arr)
inline

Component-wise division assignment operator.

Parameters
[in]arrthe array to divide (component-wise). Divides the numeric array arr with this instance (component-wise).
Precondition
forall i, arr[i] != 0
Returns
A reference to the NumericArray instance after cwise division.

References SLIC_ASSERT.

◆ clampUpper()

template<typename T , int SIZE>
NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::clampUpper ( const T &  upperVal)
inline

Ensures that the highest value of the coordinates is at most upperVal.

Parameters
[in]upperValThe highest possible value
Postcondition
forall i, arr[i] <= upperVal
Returns
A reference to the NumericArray instance after clamping upper

References axom::utilities::min().

◆ clampLower()

template<typename T , int SIZE>
NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::clampLower ( const T &  lowerVal)
inline

Ensures that the lowest value of the coordinates is at least lowerVal.

Parameters
[in]lowerValThe lowest possible value
Postcondition
forall i, arr[i] >= lowerVal
Returns
A reference to the NumericArray instance after clamping lower

References axom::utilities::max().

◆ clamp()

template<typename T , int SIZE>
NumericArray< T, SIZE > & axom::primal::NumericArray< T, SIZE >::clamp ( const T &  lowerVal,
const T &  upperVal 
)
inline

Ensures that each coordinate's value is in range [lowerVal,upperVal].

Parameters
[in]lowerValThe lowest possible value
[in]upperValThe highest possible value
Precondition
lowerVal <= upperVal
Postcondition
forall i, lowerVal <= arr[i] <= upperVal
Returns
A reference to the NumericArray instance after clamping

References axom::utilities::clampVal(), and SLIC_ASSERT.

◆ max()

template<typename T , int SIZE>
T axom::primal::NumericArray< T, SIZE >::max
inline

Find the max component.

Returns
The value of the largest component.

◆ min()

template<typename T , int SIZE>
T axom::primal::NumericArray< T, SIZE >::min
inline

Find the min component.

Returns
The value of the smallest component.

◆ argMax()

template<typename T , int SIZE>
int axom::primal::NumericArray< T, SIZE >::argMax
inline

Find the index of the max component.

Returns
The index of the largest component ( \( 0 \le ret < SIZE \))

◆ argMin()

template<typename T , int SIZE>
int axom::primal::NumericArray< T, SIZE >::argMin
inline

Find the index of the min component.

Returns
The index of the smallest component ( \( 0 \le ret < SIZE \))

◆ sum()

template<typename T , int SIZE>
T axom::primal::NumericArray< T, SIZE >::sum
inline

Computes the sum of the components.

Member Data Documentation

◆ m_components

template<typename T , int SIZE>
T axom::primal::NumericArray< T, SIZE >::m_components[SIZE]
protected

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