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/v0.5.0/src/axom/primal/geometry/NumericArray.hpp>

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

Public Types

enum  { NBYTES = SIZE * sizeof(T) }
 

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 NumericArray (const NumericArray &other)
 Copy constructor. More...
 
AXOM_HOST_DEVICE ~NumericArray ()
 Destructor. More...
 
AXOM_HOST_DEVICE NumericArrayoperator= (const NumericArray &rhs)
 Assignment operator. 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 ()
 
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...
 
NumericArray< T, SIZE > & operator+= (const NumericArray< T, SIZE > &arr)
 Component-wise addition assignment operator. More...
 
AXOM_HOST_DEVICE NumericArray< T, SIZE > & operator-= (const NumericArray< T, SIZE > &arr)
 Component-wise subtraction assignment operator. More...
 
AXOM_HOST_DEVICE NumericArray< T, SIZE > & operator*= (double scalar)
 Scalar multiplication on the NumericArray instance. More...
 
AXOM_HOST_DEVICE NumericArray< T, SIZE > & operator/= (double scalar)
 Scalar division on the NumericArray instance. More...
 
AXOM_HOST_DEVICE NumericArray< T, SIZE > & operator*= (const NumericArray< T, SIZE > &arr)
 Component-wise multiplication assignment operator. More...
 
NumericArray< T, SIZE > & operator/= (const NumericArray< T, SIZE > &arr)
 Component-wise division assignment operator. More...
 
NumericArray< T, SIZE > & clampUpper (const T &upperVal)
 Ensures that the highest value of the coordinates is at most upperVal. More...
 
NumericArray< T, SIZE > & clampLower (const T &lowerVal)
 Ensures that the lowest value of the coordinates is at least lowerVal. More...
 
NumericArray< T, SIZE > & clamp (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...
 

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

Member Enumeration Documentation

◆ anonymous enum

template<typename T, int SIZE>
anonymous enum
Enumerator
NBYTES 

Constructor & Destructor Documentation

◆ NumericArray() [1/4]

template<typename T, int SIZE>
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

◆ NumericArray() [2/4]

template<typename T, int SIZE>
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.

◆ NumericArray() [3/4]

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.

◆ NumericArray() [4/4]

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

Copy constructor.

Parameters
[in]otherThe numeric array to copy

◆ ~NumericArray()

template<typename T, int SIZE>
AXOM_HOST_DEVICE axom::primal::NumericArray< T, SIZE >::~NumericArray ( )
inline

Destructor.

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=()

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

Assignment operator.

Parameters
[in]rhsa numeric array instance on the right hand side.

◆ operator[]() [1/2]

template<typename T , int SIZE>
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>
T & axom::primal::NumericArray< T, SIZE >::operator[] ( int  i)
inline

◆ data() [1/2]

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

◆ data() [2/2]

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

◆ to_array()

template<typename T, int SIZE>
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.

Referenced by axom::primal::Point< IndexType, NDIMS >::to_array().

◆ 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>
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>
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>
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>
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.

◆ 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 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.

◆ 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

◆ 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

◆ 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

◆ max()

template<typename T , int SIZE>
T axom::primal::NumericArray< T, SIZE >::max ( ) const
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 ( ) const
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 ( ) const
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 ( ) const
inline

Find the index of the min component.

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

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: