libpnicore
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes
pni::core::mdarray< STORAGE, IMAP, IPA > Class Template Reference

template for a multi-dimensional array class More...

#include <mdarray.hpp>

Public Types

typedef STORAGE storage_type
 type of the buffer object
 
typedef storage_type::value_type value_type
 arrays element type
 
typedef IMAP map_type
 index map type
 
typedef mdarray< storage_type,
map_type, IPA > 
array_type
 type of the array
 
typedef storage_type::iterator iterator
 iterator type
 
typedef
storage_type::const_iterator 
const_iterator
 const iterator type
 
typedef
storage_type::reverse_iterator 
reverse_iterator
 reverse iterator
 
typedef
storage_type::const_reverse_iterator 
const_reverse_iterator
 const reverse iterator
 
typedef IPA inplace_arithmetic
 inplace arithmetics type
 
typedef array_view< array_typeview_type
 view type
 
typedef array_view< const
array_type
const_view_type
 const view type
 
typedef size_t size_type
 type used for size
 

Public Member Functions

 mdarray ()
 default constructor
 
 mdarray (const map_type &map, const storage_type &s)
 construct from map and storage More...
 
 mdarray (map_type &&map, storage_type &&s)
 move construct from map and storage More...
 
template<typename ATYPE >
 mdarray (const array_view< ATYPE > &view)
 constrcut from a view More...
 
template<typename... MDARGS>
 mdarray (const mdarray< MDARGS...> &array)
 construction from an other array More...
 
template<typename... MDARGS>
array_typeoperator= (const mdarray< MDARGS...> &array)
 assignment from a different array type More...
 
array_typeoperator= (const std::initializer_list< value_type > &l)
 assignment from an initializer list More...
 
const map_typemap () const
 get index map More...
 
template<typename CTYPE >
CTYPE shape () const
 shape to container More...
 
size_t size () const
 get size of array More...
 
size_t rank () const
 get number of dimensions More...
 
value_typeoperator[] (size_t i)
 get referece to element i More...
 
value_type operator[] (size_t i) const
 get value at i More...
 
value_typeat (size_t i)
 get value at i More...
 
value_type at (size_t i) const
 get value at i More...
 
void insert (size_t i, const value_type &value)
 insert value at index i More...
 
template<typename CTYPE , typename = typename enable_element_cont<CTYPE>::type>
value_typeoperator() (const CTYPE &index)
 return element reference More...
 
template<typename CTYPE , typename = typename enable_element_cont<CTYPE>::type>
value_type operator() (const CTYPE &index) const
 return element value More...
 
template<typename CTYPE , typename = typename enable_view_cont<CTYPE>::type>
array_view< const array_typeoperator() (const CTYPE &slices) const
 return array view More...
 
template<typename CTYPE , typename = typename enable_view_cont<CTYPE>::type>
array_view< array_typeoperator() (const CTYPE &slices)
 return array view More...
 
template<typename... ITYPES, typename = typename enable_valid_index<ITYPES...>::type>
view_type_trait< array_type,
ITYPES...>::type 
operator() (ITYPES...indexes)
 multiindex access More...
 
template<typename... ITYPES, typename = typename enable_valid_index<ITYPES...>::type>
view_type_trait< const
array_type, ITYPES...>
::const_type 
operator() (ITYPES...indexes) const
 multiindex access More...
 
const value_typedata () const
 return const pointer More...
 
value_typedata ()
 return pointer More...
 
value_typefront ()
 reference to first element More...
 
value_type front () const
 value of first element More...
 
value_typeback ()
 reference to last element More...
 
value_type back () const
 value of last element More...
 
iterator begin ()
 iterator to first element More...
 
iterator end ()
 iterator to last element More...
 
const_iterator begin () const
 const-iterator to first element More...
 
const_iterator end () const
 const-iterator to last element More...
 
reverse_iterator rbegin ()
 return reverse iterator to last element
 
const_reverse_iterator rbegin () const
 return const reverse iterator to last element
 
reverse_iterator rend ()
 return reverse iterator to 0-1 element
 
const_reverse_iterator rend () const
 return const reverse iterator to 0-1 element
 
array_typeoperator+= (value_type s)
 unary addition of a scalar More...
 
template<typename ATYPE >
array_typeoperator+= (const ATYPE &v)
 unary addition of an array More...
 
array_typeoperator-= (value_type s)
 unary subtraction of a scalar More...
 
template<typename ATYPE >
array_typeoperator-= (const ATYPE &v)
 unary subtraction of an array More...
 
array_typeoperator*= (value_type s)
 unary multiplication of a scalar More...
 
template<typename ATYPE >
array_typeoperator*= (const ATYPE &v)
 unary multiplication of an array More...
 
array_typeoperator/= (value_type s)
 unary division of a scalar More...
 
template<typename ATYPE >
array_typeoperator/= (const ATYPE &v)
 unary division of an array More...
 

Static Public Member Functions

template<typename... ARGS>
static array_type create (ARGS...arguments)
 generic construction function More...
 
template<typename T1 , typename T2 >
static array_type create (const std::initializer_list< T1 > &l1, const std::initializer_list< T2 > &l2)
 construction from initializer list More...
 

Static Public Attributes

static const type_id_t type_id
 type ID of the element type More...
 

Private Attributes

IMAP _imap
 Index map of the array.
 
STORAGE _data
 instance of STORAGE
 

Detailed Description

template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
class pni::core::mdarray< STORAGE, IMAP, IPA >

Template Parameters
STORAGEstorage object to use to keep the data
IMAPthe index map
IPAunary (inplace) arithmetics implementation
Examples:
example_array2.cpp, example_array3.cpp, and example_array4.cpp.

Constructor & Destructor Documentation

template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
pni::core::mdarray< STORAGE, IMAP, IPA >::mdarray ( const map_type map,
const storage_type s 
)
inlineexplicit

Construct an array from an index map and a storage.

Parameters
mapthe index map instance
sarray storage
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
pni::core::mdarray< STORAGE, IMAP, IPA >::mdarray ( map_type &&  map,
storage_type &&  s 
)
inlineexplicit

Move construct an array from rvalue refernces to an index map and a storage.

Parameters
maprvalue reference to the index map
srvalue reference to the storage
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename ATYPE >
pni::core::mdarray< STORAGE, IMAP, IPA >::mdarray ( const array_view< ATYPE > &  view)
inlineexplicit

This constructor creates a new array from an array view instance. The resulting array object has the same shape as the view.

Template Parameters
ATYPEstorage type of the view
Parameters
viewreference to the view
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename... MDARGS>
pni::core::mdarray< STORAGE, IMAP, IPA >::mdarray ( const mdarray< MDARGS...> &  array)
inlineexplicit

This constructor can be used for instance along with expression templates in order to construct an array from an expression.

Template Parameters
MDARGStemplate parameters of mdarray
Parameters
arrayreference to the source array

Member Function Documentation

template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type& pni::core::mdarray< STORAGE, IMAP, IPA >::at ( size_t  i)
inline

Return a reference to the value at linear index i. This method performs index checking.

Exceptions
index_errorif i exceeds array size
Parameters
ilinear index of element
Returns
reference to the value at i
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type pni::core::mdarray< STORAGE, IMAP, IPA >::at ( size_t  i) const
inline

Return the value of element i. This method performs index checking.

Exceptions
index_errorif i exceeds array size
Parameters
ilinear index of element
Returns
value at i
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type& pni::core::mdarray< STORAGE, IMAP, IPA >::back ( )
inline

Return a reference to the last element in the linear view of the array.

Returns
reference to last element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type pni::core::mdarray< STORAGE, IMAP, IPA >::back ( ) const
inline

Return the value of the last element in the linear view of the array.

Returns
value of last element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
iterator pni::core::mdarray< STORAGE, IMAP, IPA >::begin ( )
inline

Returns a non-const iterator to the first element in the array.

Returns
iterator to first element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
const_iterator pni::core::mdarray< STORAGE, IMAP, IPA >::begin ( ) const
inline

Returns a const-iterator to the first element in the array.

Returns
iterator to first element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename... ARGS>
static array_type pni::core::mdarray< STORAGE, IMAP, IPA >::create ( ARGS...  arguments)
inlinestatic

This function can be used for easy array construction. It uses the array_factory template in the background.

Template Parameters
ARGSvariadic argument types
Parameters
argumentsvariadic argument list
Returns
array instance
Examples:
example_array2.cpp, example_array3.cpp, and example_array4.cpp.
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename T1 , typename T2 >
static array_type pni::core::mdarray< STORAGE, IMAP, IPA >::create ( const std::initializer_list< T1 > &  l1,
const std::initializer_list< T2 > &  l2 
)
inlinestatic

This version of the static create function uses an initializer list. The first initializer list holds shape information while the second holds the data which will be stored in the array.

Template Parameters
T1element type of shape list
T2element type of data list
Parameters
l1instance of shape list
l2instance of data list
Returns
instance of array_type
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
const value_type* pni::core::mdarray< STORAGE, IMAP, IPA >::data ( ) const
inline

Return a const pointer to the data stored in the array.

Returns
pointer to data
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type* pni::core::mdarray< STORAGE, IMAP, IPA >::data ( )
inline

Return a pointer to the data stored in the array.

Returns
pointer to data
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
iterator pni::core::mdarray< STORAGE, IMAP, IPA >::end ( )
inline

Returns a non-const iterator to the last element in the array.

Returns
iterator to last element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
const_iterator pni::core::mdarray< STORAGE, IMAP, IPA >::end ( ) const
inline

Returns a const-iterator to the last element in the array.

Returns
iterator to last element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type& pni::core::mdarray< STORAGE, IMAP, IPA >::front ( )
inline

Return a reference to the first element in the linear view of the array.

Returns
reference to first element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type pni::core::mdarray< STORAGE, IMAP, IPA >::front ( ) const
inline

Return the value of the first element in the linear view of the array.

Returns
value of the first element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
void pni::core::mdarray< STORAGE, IMAP, IPA >::insert ( size_t  i,
const value_type value 
)
inline

Insert value at index i.

Exceptions
index_errorif i exceeds the size of the array
Parameters
ilinear index of the element
valuethe value to store at index i
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
const map_type& pni::core::mdarray< STORAGE, IMAP, IPA >::map ( ) const
inline

Returns a const reference to the index map of the array.

Returns
reference to index map
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename CTYPE , typename = typename enable_element_cont<CTYPE>::type>
value_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator() ( const CTYPE &  index)
inline

Returns the reference to a single elemnt of the array determined by a multidimensional index of unsigned integers stored in a container of type CTYPE. This method performs no range checking.

Template Parameters
CTYPEindex container type
Parameters
indexreference to index container
Returns
reference to the element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename CTYPE , typename = typename enable_element_cont<CTYPE>::type>
value_type pni::core::mdarray< STORAGE, IMAP, IPA >::operator() ( const CTYPE &  index) const
inline

Returns the value of a single elemnt of the array determined by a multidimensional index of unsigned integers stored in a container of type CTYPE. This method performs no range checking.

Template Parameters
CTYPEindex container type
Parameters
indexreference to index container
Returns
value of the element
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename CTYPE , typename = typename enable_view_cont<CTYPE>::type>
array_view<const array_type> pni::core::mdarray< STORAGE, IMAP, IPA >::operator() ( const CTYPE &  slices) const
inline

Return a view on the array determined by a set of slices stored in a container type CTYPE.

Template Parameters
CTYPEslice container type
Parameters
slicesreference to the container
Returns
array_view instance
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename CTYPE , typename = typename enable_view_cont<CTYPE>::type>
array_view<array_type> pni::core::mdarray< STORAGE, IMAP, IPA >::operator() ( const CTYPE &  slices)
inline

Return a view on the array determined by a set of slices stored in a container type CTYPE.

Template Parameters
CTYPEslice container type
Parameters
slicesreference to the container
Returns
array_view instance
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename... ITYPES, typename = typename enable_valid_index<ITYPES...>::type>
view_type_trait<array_type,ITYPES...>::type pni::core::mdarray< STORAGE, IMAP, IPA >::operator() ( ITYPES...  indexes)
inline

The () operator allows multindex access to the data stored in the array. Like the [] operator it does not perform any checks of index ranges and should thus be used with care. However, due to the missign checks it is extremely fast. If index checking is required have a look the corresponding at() member function.

Template Parameters
ITYPESindex types
Parameters
indexeslist of index values
Returns
reference to the value at the given index
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename... ITYPES, typename = typename enable_valid_index<ITYPES...>::type>
view_type_trait<const array_type,ITYPES...>::const_type pni::core::mdarray< STORAGE, IMAP, IPA >::operator() ( ITYPES...  indexes) const
inline

The () operator allows multindex access to the data stored in the array. Like the [] operator it does not perform any checks of index ranges and should thus be used with care. However, due to the missign checks it is extremely fast. If index checking is required have a look the corresponding at() member function.

Template Parameters
ITYPESindex types
Parameters
indexeslist of index values
Returns
value at the given index
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator*= ( value_type  s)
inline
array_type a = ...;
a *= s;

!

Parameters
sthe scalar value to multiply with
Returns
array reference
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename ATYPE >
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator*= ( const ATYPE &  v)
inline
array_type1 a = ...;
array_tyep2 b = ...;
a *= b;

!

Template Parameters
ATYPEtype of the array to multiply
Parameters
vreference to the array to multiply
Returns
reference to the original array
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator+= ( value_type  s)
inline
array_type a = ...;
a += s;

!

Parameters
sthe scalar value to add
Returns
array reference
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename ATYPE >
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator+= ( const ATYPE &  v)
inline
array_type1 a = ...;
array_tyep2 b = ...;
a += b;

!

Template Parameters
ATYPEtype of the array to add
Parameters
vreference to the array to add
Returns
reference to the original array
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator-= ( value_type  s)
inline
array_type a = ...;
a -= s;

!

Parameters
sthe scalar value to subtract
Returns
array reference
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename ATYPE >
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator-= ( const ATYPE &  v)
inline
array_type1 a = ...;
array_tyep2 b = ...;
a -= b;

!

Template Parameters
ATYPEtype of the array to subtract
Parameters
vreference to the array to subtract
Returns
reference to the original array
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator/= ( value_type  s)
inline
array_type a = ...;
a /= s;

!

Parameters
sthe scalar value to divide by
Returns
array reference
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename ATYPE >
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator/= ( const ATYPE &  v)
inline
array_type1 a = ...;
array_tyep2 b = ...;
a /= b;

!

Template Parameters
ATYPEtype of the array to divide by
Parameters
vreference to the array to divide by
Returns
reference to the original array
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename... MDARGS>
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator= ( const mdarray< MDARGS...> &  array)
inline

Assign the data from a different array type to this one.

Exceptions
size_mismatch_errorif array sizes do not match
shape_mismatch_errorif shapes do not match
Template Parameters
MDARGStemplate parameters of the source type
Parameters
arrayreference to the source array
Returns
reference to the updated array
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
array_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator= ( const std::initializer_list< value_type > &  l)
inline

Assigns the values given by an initializer list to an allocated array. If the number of elements in the list does not match the number of elements in the array an exception is thrown.

Exceptions
size_mismatch_errorif list size and array size do not match
Parameters
lreference to an initializer list
Returns
reference to the array
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type& pni::core::mdarray< STORAGE, IMAP, IPA >::operator[] ( size_t  i)
inline

Returns a reference to the element at linear index i. No index checking is done! Thus use this operator with care.

Parameters
ilinear index
Returns
reference to the element at linear index i
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
value_type pni::core::mdarray< STORAGE, IMAP, IPA >::operator[] ( size_t  i) const
inline

Returns the value of the element at the linar array index i. No index checking is done! Thus use this operator with care.

Parameters
ilinear index of the element
Returns
value of the element at linear index i
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
size_t pni::core::mdarray< STORAGE, IMAP, IPA >::rank ( ) const
inline

Returns the number of dimensions of the array.

Returns
number of dimensions
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
template<typename CTYPE >
CTYPE pni::core::mdarray< STORAGE, IMAP, IPA >::shape ( ) const
inline

This returns a container of type CTYPE with the number of elements stored in the array.

Template Parameters
CTYPEcontainer type
Returns
instance of CTYPE with shape data
Examples:
example_array3.cpp, and example_array4.cpp.
template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
size_t pni::core::mdarray< STORAGE, IMAP, IPA >::size ( ) const
inline

Returns the total number of elements stored in the array.

Returns
total number of elements

Field Documentation

template<typename STORAGE, typename IMAP = dynamic_cindex_map, typename IPA = inplace_arithmetics>
const type_id_t pni::core::mdarray< STORAGE, IMAP, IPA >::type_id
static

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