#include <source/patchdata/array/array_access/MDA_Access.h>
Inheritance diagram for MDA_Access< MDA_TYPE, MDA_DIM, OrderType >:
Public Types | |
typedef MDA_TYPE | value_t |
Type of data. | |
typedef MDA_IndexRange< MDA_DIM > | range_t |
typedef range_t::dim_t | dim_t |
typedef range_t::index_t | index_t |
typedef OrderType | order_t |
typedef OrderType::reduced_order_t | reduced_order_t |
Public Member Functions | |
MDA_Access (value_t *p=((value_t *) 0), const size_t *sz=((size_t *) 0), const index_t *st=((index_t *) 0)) | |
Constructor for setting all data, with default values. | |
MDA_Access (value_t *p, const index_t *si, const index_t *sf) | |
Constructor for setting all data, with default values. | |
MDA_Access (value_t *p, const order_t &r) | |
Constructor for specifying pointer and ordering object. | |
MDA_Access (const MDA_Access &r) | |
Copy constructor. | |
virtual | ~MDA_Access () |
Virtual destructor to support inheritance. | |
operator bool () const | |
Conversion into boolean. | |
operator value_t * () const | |
Conversion into pointer. | |
void | setPointer (value_t *p) |
Set the data pointer. | |
void | setSizeAndStart (const size_t *sz=((size_t *) 0), const index_t *st=((index_t *) 0)) |
void | setInclusiveRange (const index_t first[MDA_DIM], const index_t final[MDA_DIM]) |
const range_t & | adjustDim (dim_t d, index_t first, index_t final) |
Adjust the dimensions. | |
Equivalence comparison | |
bool | operator== (const MDA_Access &r) const |
Inequivalence comparison | |
bool | operator!= (const MDA_Access &r) const |
Inequivalence comparison | |
const range_t & | range () const |
const index_t & | beg (size_t i) const |
const index_t & | end (size_t i) const |
const size_t & | size (size_t i) const |
value_t & | operator() (const index_t i[MDA_DIM]) const |
Grant general access to item in an arbitrary dimensional array. | |
value_t & | operator() (index_t i0) const |
Grant general access to item in a 1D array. | |
value_t & | operator() (index_t i0, index_t i1) const |
Grant general access to item in a 2D array. | |
value_t & | operator() (index_t i0, index_t i1, index_t i2) const |
Grant general access to item in a 3D array. | |
value_t & | operator() (index_t i0, index_t i1, index_t i2, index_t i3) const |
Grant general access to item in a 4D array. | |
value_t & | operator[] (index_t i0) const |
Special case for 1D arrays, identical to operator(index_t) , using pre-added fixed offsets. | |
MDA_Access< MDA_TYPE, OrderType::MDA_Reduced_DIM, typename OrderType::reduced_order_t > | reduce (index_t i) const |
Fix the index of the slowest dimension and return the corresponding sub-array. |
This class never allocates or deallocates data. It takes pointers to preallocated data and provides an interface to that data. Member functions are used to give that interface.
This class provides functions for explicit index checking, but it does NO implicit error checking on either the dimensionality of the array or it size. Such may be done through subclassing.
The member functions should all be inlined for better performance.
This template class is set up to work with either row-major or column-major data, depending on the third template argument, which should be one of
MDA_OrderRowMajor
(default if omitted)MDA_OrderColMajor
The reduce() function return a new array of smaller dimensional that require less integer arithmetic to access individual array members. This should help in optimizing code. (My preliminary performance tests using gcc and gprof on i686 Linux showed that the MDA_Access functions run at half to slightly faster than the speed of Fortran, depending on use of reduced arrays. However, note that gcc is not great at optimizing Fortran.)
typedef MDA_TYPE MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::value_t |
typedef MDA_IndexRange<MDA_DIM> MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::range_t |
Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.
typedef range_t::dim_t MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::dim_t |
Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.
typedef range_t::index_t MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::index_t |
Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.
typedef OrderType MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::order_t |
Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.
typedef OrderType::reduced_order_t MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::reduced_order_t |
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access | ( | value_t * | p = ((value_t*)0) , |
|
const size_t * | sz = ((size_t*)0) , |
|||
const index_t * | st = ((index_t*)0) | |||
) | [inline] |
Constructor for setting all data, with default values.
Any pointers that are NULL are not used. The resulting default settings are:
There is another constructor which accepts the first and final indices instead of the sizes and first indices. NOTE: the place of the initial indices is different than it is for the constructor taking final indices instead of sizes.
p | Pointer to data |
sz | Array sizes |
st | Array starting indices |
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access | ( | value_t * | p, | |
const index_t * | si, | |||
const index_t * | sf | |||
) | [inline] |
Constructor for setting all data, with default values.
Any pointers that are NULL are not used. The resulting default settings are:
This version takes two int*
arguments, for the initial and final indices. It does not support default arguments until after the indices argument. NOTE: the place of the initial indices is different than it is for the constructor taking sizes instead of final indices.
If si
is NULL
, starting indices are set to 0. If sf
is NULL
, sizes are set to zero.
p | Pointer to data |
si | Array of initial indices |
sf | Array of final indices |
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access | ( | value_t * | p, | |
const order_t & | r | |||
) | [inline] |
Constructor for specifying pointer and ordering object.
p | Pointer to data |
r | Array index object |
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access | ( | const MDA_Access< MDA_TYPE, MDA_DIM, OrderType > & | r | ) | [inline] |
Copy constructor.
r | Copyee object |
virtual MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::~MDA_Access | ( | ) | [inline, virtual] |
Virtual destructor to support inheritance.
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator bool | ( | ) | const [inline] |
Conversion into boolean.
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator value_t * | ( | ) | const [inline] |
Conversion into pointer.
void MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::setPointer | ( | value_t * | p | ) | [inline] |
Set the data pointer.
p | Pointer value |
void MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::setSizeAndStart | ( | const size_t * | sz = ((size_t*)0) , |
|
const index_t * | st = ((index_t*)0) | |||
) | [inline] |
Set size and starting indices.
sz | Array sizes (NULL for no change) |
st | Starting indices (NULL for no change) |
void MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::setInclusiveRange | ( | const index_t | first[MDA_DIM], | |
const index_t | final[MDA_DIM] | |||
) | [inline] |
Set first and final indices (inclusive).
first | First valid indices (NULL for no change) |
final | Final valid indices (NULL for no change) |
const range_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::adjustDim | ( | dim_t | d, | |
index_t | first, | |||
index_t | final | |||
) | [inline] |
Adjust the dimensions.
d | Dimension to adjust |
first | Increment to first index |
final | Increment to final index |
bool MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator== | ( | const MDA_Access< MDA_TYPE, MDA_DIM, OrderType > & | r | ) | const [inline] |
bool MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator!= | ( | const MDA_Access< MDA_TYPE, MDA_DIM, OrderType > & | r | ) | const [inline] |
const range_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::range | ( | ) | const [inline] |
const index_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::beg | ( | size_t | i | ) | const [inline] |
const index_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::end | ( | size_t | i | ) | const [inline] |
const size_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::size | ( | size_t | i | ) | const [inline] |
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() | ( | const index_t | i[MDA_DIM] | ) | const [inline] |
Grant general access to item in an arbitrary dimensional array.
This is flexible but not efficient! You should use dimension-specific accesses whenever possible.
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() | ( | index_t | i0 | ) | const [inline] |
Grant general access to item in a 1D array.
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() | ( | index_t | i0, | |
index_t | i1 | |||
) | const [inline] |
Grant general access to item in a 2D array.
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() | ( | index_t | i0, | |
index_t | i1, | |||
index_t | i2 | |||
) | const [inline] |
Grant general access to item in a 3D array.
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() | ( | index_t | i0, | |
index_t | i1, | |||
index_t | i2, | |||
index_t | i3 | |||
) | const [inline] |
Grant general access to item in a 4D array.
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator[] | ( | index_t | i0 | ) | const [inline] |
Special case for 1D arrays, identical to operator(index_t)
, using pre-added fixed offsets.
This may be more efficient than (i) but it only works in 1D. It is not guaranteed to work if the fixed offset is negative and has greater value than the pointer address, since the addition of the two gives a negative address, which the C standard leaves as undefined behavior.
MDA_Access<MDA_TYPE,OrderType::MDA_Reduced_DIM,typename OrderType::reduced_order_t> MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::reduce | ( | index_t | i | ) | const [inline] |
Fix the index of the slowest dimension and return the corresponding sub-array.
This function is meant to facilitate optimization when using this class. In nested loops, the inner loops executes many times with the indices corresponding to outer loops remaining constants. This leads to many many repeated integer arithmetics operations that could be removed from the inner loop (but may not be removed automatically by the compiler optimization). To do this, reduce the array dimensionality one dimension at a time, by fixing index corresponding to the slowest varying dimension. (If you code is written to maximize cache data, this will NOT be the index of the innermost loop.)
To reduce multiple dimensions, string these calls together, i.e. array.reduce(i)
.reduce(j). However, since reduction contains loops that cost O(MDA_DIM) and may be difficult for compilers to optimize, you may want to save array.reduce(i)
and reuse it.
i | Index in slowest dimension, which is the first dimension in a row-major array and the last dimension in a column-major array. |
MDA_DIM-1
, corresponding to the index given.