PARTONS  
PARtonic Tomography Of Nucleon Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PARTONS::MDArray< T > Class Template Reference

Multidimensional optimized array. More...

Public Member Functions

 MDArray ()
 Default constructor. More...
 
 MDArray (std::vector< size_t > _dims, const T &initValue=T())
 Constructor. More...
 
 ~MDArray ()
 Destructor. More...
 
void push_back (T value)
 Push back one element. More...
 
const size_t getSize ()
 Get size of the data array. More...
 
T & operator() (size_t coordValue,...)
 () accessor for setting value at target index. More...
 
T const & operator() (size_t coordValue,...) const
 () accessor for getting value at target index. More...
 
std::string toString () const
 Get string representing the array data. More...
 

Private Member Functions

size_t indexOf (size_t coordValue, va_list ap) const
 Return index of specifics coordinates. More...
 
size_t computeIntermediateIndex (size_t coordValue, unsigned int numDim) const
 Compute intermediate index value. More...
 

Private Attributes

std::vector< size_t > dims
 Vector containing array dimension sizes. More...
 
std::vector< T > data
 Array data. More...
 

Detailed Description

template<typename T>
class PARTONS::MDArray< T >

Multidimensional optimized array.

This class acts as a STL-like container to store multidimensional data in a single vector only (here, std::vector). The usage of this class is illustrated by the following example:

//initialize MDArray object
//in this example it will store 4x4x4 array
//initial value for all elements will be 1.
std::vector<size_t> dims;
dims.push_back(4);
dims.push_back(4);
dims.push_back(4);
MDArray<double> myArray(dims, 1.);
//set value at (1, 2, 3) coordinate
myArray(1, 2, 3) = 5.2;
//access values at (1, 2, 3) coordinate
double value = myArray(1, 2, 3);
//print
Partons::getInstance()->getLoggerManager()->info("example", __func__, ElemUtils::Formatter() << "Value at (1, 2, 3) is: " << value);
std::vector< size_t > dims
Vector containing array dimension sizes.
Definition: MDArray.h:150
ElemUtils::LoggerManager * getLoggerManager() const
Definition: Partons.cpp:191
static Partons * getInstance()
Share a unique pointer of this class.
Definition: Partons.cpp:27

which gives via Logger:

07-06-2017 08:37:42 [INFO] (example::main) Value at (1, 2, 3) is: 5.2

Constructor & Destructor Documentation

◆ MDArray() [1/2]

template<typename T >
PARTONS::MDArray< T >::MDArray ( )
inline

Default constructor.

◆ MDArray() [2/2]

template<typename T >
PARTONS::MDArray< T >::MDArray ( std::vector< size_t >  _dims,
const T &  initValue = T() 
)
inline

Constructor.

Parameters
_dimsVector containing array dimension sizes.
initValueInitialization element to be used to fill this array.

◆ ~MDArray()

template<typename T >
PARTONS::MDArray< T >::~MDArray ( )
inline

Destructor.

Member Function Documentation

◆ computeIntermediateIndex()

template<typename T >
size_t PARTONS::MDArray< T >::computeIntermediateIndex ( size_t  coordValue,
unsigned int  numDim 
) const
inlineprivate

Compute intermediate index value.

◆ getSize()

template<typename T >
const size_t PARTONS::MDArray< T >::getSize ( )
inline

Get size of the data array.

◆ indexOf()

template<typename T >
size_t PARTONS::MDArray< T >::indexOf ( size_t  coordValue,
va_list  ap 
) const
inlineprivate

Return index of specifics coordinates.

Transform x,y,z,... coordinates to index x.

◆ operator()() [1/2]

template<typename T >
T& PARTONS::MDArray< T >::operator() ( size_t  coordValue,
  ... 
)
inline

() accessor for setting value at target index.

◆ operator()() [2/2]

template<typename T >
T const& PARTONS::MDArray< T >::operator() ( size_t  coordValue,
  ... 
) const
inline

() accessor for getting value at target index.

◆ push_back()

template<typename T >
void PARTONS::MDArray< T >::push_back ( value)
inline

Push back one element.

To be used only with one dimensional arrays.

Parameters
valueElement to be pushed back.

◆ toString()

template<typename T >
std::string PARTONS::MDArray< T >::toString ( ) const
inline

Get string representing the array data.

Returns

Member Data Documentation

◆ data

template<typename T >
std::vector<T> PARTONS::MDArray< T >::data
private

Array data.

◆ dims

template<typename T >
std::vector<size_t> PARTONS::MDArray< T >::dims
private

Vector containing array dimension sizes.


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