echelon  0.8.0
Public Types | Public Member Functions | List of all members
echelon::multi_array< T > Class Template Reference

Multidimensional array with runtime rank and shape. More...

#include <multi_array.hpp>

Public Types

typedef T value_type
 value type of the array
 

Public Member Functions

 multi_array ()=default
 Creates an empty array.
 
 multi_array (const std::vector< std::size_t > &shape_, const T &value_=T())
 Creates an array with a given shape. More...
 
template<typename... Indices, typename Enabler = typename std::enable_if< detail::all_integral<Indices...>::value>::type>
const T & operator() (Indices...indices) const
 Accesses a specified element. More...
 
template<typename... Indices, typename Enabler = typename std::enable_if< detail::all_integral<Indices...>::value>::type>
T & operator() (Indices...indices)
 Accesses a specified element. More...
 
template<typename... Args, typename Enabler = typename std::enable_if< !detail::all_integral<Args...>::value>::type>
echelon::hdf5::array_slice< T > operator() (Args...args)
 Slice the array. More...
 
const T * data () const
 Direct access to the underlying array. More...
 
T * data ()
 Direct access to the underlying array. More...
 
std::vector< T >::iterator begin ()
 Returns an iterator, which points to the first element of the flattened array. More...
 
std::vector< T >::iterator end ()
 Returns an iterator, which points to the last element of the flattened array. More...
 
std::vector< T >::const_iterator begin () const
 Returns an iterator, which points to the first element of the flattened array. More...
 
std::vector< T >::const_iterator end () const
 Returns an iterator, which points to the last element of the flattened array. More...
 
const std::vector< std::size_t > & shape () const
 The shape of the array.
 
void reshape (const std::vector< std::size_t > &new_shape)
 Reshapes the array. More...
 

Detailed Description

template<typename T>
class echelon::multi_array< T >

Multidimensional array with runtime rank and shape.

Template Parameters
Tvalue type of the array

Constructor & Destructor Documentation

template<typename T >
echelon::multi_array< T >::multi_array ( const std::vector< std::size_t > &  shape_,
const T &  value_ = T() 
)
inlineexplicit

Creates an array with a given shape.

Parameters
shape_the shape of the array
value_value, which is used to initialize every element. By default this is the default constructed value.

Member Function Documentation

template<typename T >
std::vector<T>::iterator echelon::multi_array< T >::begin ( )
inline

Returns an iterator, which points to the first element of the flattened array.

Note
The order, in which the elements appear in the flattened sequence, is not specified.
template<typename T >
std::vector<T>::const_iterator echelon::multi_array< T >::begin ( ) const
inline

Returns an iterator, which points to the first element of the flattened array.

Note
The order, in which the elements appear in the flattened sequence, is not specified.
template<typename T >
const T* echelon::multi_array< T >::data ( ) const
inline

Direct access to the underlying array.

Returns
a pointer to the underlying array.
template<typename T >
T* echelon::multi_array< T >::data ( )
inline

Direct access to the underlying array.

Returns
a pointer to the underlying array.
template<typename T >
std::vector<T>::iterator echelon::multi_array< T >::end ( )
inline

Returns an iterator, which points to the last element of the flattened array.

Note
The order, in which the elements appear in the flattened sequence, is not specified.
template<typename T >
std::vector<T>::const_iterator echelon::multi_array< T >::end ( ) const
inline

Returns an iterator, which points to the last element of the flattened array.

Note
The order, in which the elements appear in the flattened sequence, is not specified.
template<typename T >
template<typename... Indices, typename Enabler = typename std::enable_if< detail::all_integral<Indices...>::value>::type>
const T& echelon::multi_array< T >::operator() ( Indices...  indices) const
inline

Accesses a specified element.

Template Parameters
IndicesTypes of the indices. All indices should have integral type.
Precondition
Let $ \left(s_1,...s_{rank}\right) $ be the shape of the array and let $ \left(i_1,...i_{rank_2}\right) $ be the tuple of indices, then $ rank = rank_2 $ and $ i_{i} < s_{i} $ for every $ i \in \left\{ 0,...,rank-1 \right\} $ should hold.
Parameters
indicesIndices of the requested element
Returns
the specified element
template<typename T >
template<typename... Indices, typename Enabler = typename std::enable_if< detail::all_integral<Indices...>::value>::type>
T& echelon::multi_array< T >::operator() ( Indices...  indices)
inline

Accesses a specified element.

Template Parameters
IndicesTypes of the indices. All indices should have integral type.
Precondition
Let $ \left(s_1,...s_{rank}\right) $ be the shape of the array and let $ \left(i_1,...i_{rank_2}\right) $ be the tuple of indices, then $ rank = rank_2 $ and $ i_{i} < s_{i} $ for every $ i \in \left\{ 0,...,rank-1 \right\} $ should hold.
Parameters
indicesIndices of the requested element
Returns
the specified element
template<typename T >
template<typename... Args, typename Enabler = typename std::enable_if< !detail::all_integral<Args...>::value>::type>
echelon::hdf5::array_slice<T> echelon::multi_array< T >::operator() ( Args...  args)
inline

Slice the array.

Template Parameters
Argstypes of the index range specifiers
Parameters
argsindex range specifiers
Returns
the specified slice.
template<typename T >
void echelon::multi_array< T >::reshape ( const std::vector< std::size_t > &  new_shape)
inline

Reshapes the array.

Parameters
new_shapenew shape of the array

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