Alexandria  2.14.1
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Euclid::NdArray::NdArray< T, Container > Class Template Reference

#include <NdArray.h>

Collaboration diagram for Euclid::NdArray::NdArray< T, Container >:
[legend]

Public Types

typedef Container< T >::iterator iterator
 
typedef Container< T >
::const_iterator 
const_iterator
 
typedef NdArray< T, Container > self_type
 

Public Member Functions

virtual ~NdArray ()=default
 
 NdArray (const std::vector< size_t > &shape)
 
 NdArray (const std::vector< size_t > &shape, const Container< T > &data)
 
 NdArray (const std::vector< size_t > &shape, Container< T > &&data)
 
 NdArray (const std::initializer_list< size_t > &shape)
 
 NdArray (self_type &&)=default
 
NdArrayoperator= (const NdArray &)=default
 
const std::vector< size_t > shape () const
 
T & at (const std::vector< size_t > &coords)
 
const T & at (const std::vector< size_t > &coords) const
 
template<typename... D>
T & at (size_t i, D...rest)
 
template<typename... D>
const T & at (size_t i, D...rest) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const Container< T > & data () const
 
size_t size () const
 
bool operator== (const self_type &b) const
 
bool operator!= (const self_type &b) const
 

Private Member Functions

size_t getOffset (const std::vector< size_t > &coords) const
 
template<typename... D>
T & at_helper (std::vector< size_t > &acc, size_t i, D...rest)
 
T & at_helper (std::vector< size_t > &acc)
 
template<typename... D>
const T & at_helper (std::vector< size_t > &acc, size_t i, D...rest) const
 
const T & at_helper (std::vector< size_t > &acc) const
 

Private Attributes

std::vector< size_t > m_shape
 
std::vector< size_t > m_stride_size
 
Container< T > m_container
 

Detailed Description

template<typename T, template< class...> class Container = std::vector>
class Euclid::NdArray::NdArray< T, Container >

Stores a multidimensional array in a contiguous piece of memory in row-major order

Template Parameters
TData type
ContainerWhich container to use, by default std::vector

Definition at line 45 of file NdArray.h.

Member Typedef Documentation

template<typename T , template< class...> class Container = std::vector>
typedef Container<T>::const_iterator Euclid::NdArray::NdArray< T, Container >::const_iterator

Definition at line 48 of file NdArray.h.

template<typename T , template< class...> class Container = std::vector>
typedef Container<T>::iterator Euclid::NdArray::NdArray< T, Container >::iterator

Definition at line 47 of file NdArray.h.

template<typename T , template< class...> class Container = std::vector>
typedef NdArray<T, Container> Euclid::NdArray::NdArray< T, Container >::self_type

Definition at line 49 of file NdArray.h.

Constructor & Destructor Documentation

template<typename T , template< class...> class Container = std::vector>
virtual Euclid::NdArray::NdArray< T, Container >::~NdArray ( )
virtualdefault

Destructor.

template<typename T , template< class...> class Container = std::vector>
Euclid::NdArray::NdArray< T, Container >::NdArray ( const std::vector< size_t > &  shape)
inline

Constructs a default-initialized matrix with the given shape.

Parameters
shapeThe shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size.

Definition at line 62 of file NdArray.h.

template<typename T , template< class...> class Container = std::vector>
Euclid::NdArray::NdArray< T, Container >::NdArray ( const std::vector< size_t > &  shape,
const Container< T > &  data 
)
inline

Constructs a matrix and initialize it with the given data.

Parameters
shapeThe shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size.
dataThe initial data. It must match exactly the matrix size (shape[0]*shape[1]...*shape[n]).
Exceptions
std::invalid_argumentIf the data size does not corresponds to the matrix size.

Definition at line 83 of file NdArray.h.

template<typename T , template< class...> class Container = std::vector>
Euclid::NdArray::NdArray< T, Container >::NdArray ( const std::vector< size_t > &  shape,
Container< T > &&  data 
)
inline

Constructs a matrix and initialize it with the given data.

Parameters
shapeThe shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size.
dataThe initial data. It must match exactly the matrix size (shape[0]*shape[1]...*shape[n]). The NdArray will move the data into its internal storage! This avoids a copy, but remember to not use data after this call.
Exceptions
std::invalid_argumentIf the data size does not corresponds to the matrix size.

Definition at line 110 of file NdArray.h.

template<typename T , template< class...> class Container = std::vector>
Euclid::NdArray::NdArray< T, Container >::NdArray ( const std::initializer_list< size_t > &  shape)
inline

Constructs a default-initialized matrix with the given shape (as an initializer list).

Parameters
shapeThe shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size.

Definition at line 131 of file NdArray.h.

template<typename T , template< class...> class Container = std::vector>
Euclid::NdArray::NdArray< T, Container >::NdArray ( self_type &&  )
default

Move constructor

Member Function Documentation

template<typename T , template< class...> class Container = std::vector>
T& Euclid::NdArray::NdArray< T, Container >::at ( const std::vector< size_t > &  coords)
inline

Gets a reference to the value stored at the given coordinates.

Parameters
coordsElements coordinates.
Exceptions
std::out_of_rangeIf the number of coordinates is invalid, or any of them is out of bounds.

Definition at line 164 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::getOffset(), and Euclid::NdArray::NdArray< T, Container >::m_container.

Referenced by Euclid::NdArray::NdArray< T, Container >::at_helper().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
const T& Euclid::NdArray::NdArray< T, Container >::at ( const std::vector< size_t > &  coords) const
inline

Gets a constant reference to the value stored at the given coordinates

Parameters
coordsElements coordinates.
Exceptions
std::out_of_rangeIf the number of coordinates is invalid, or any of them is out of bounds.

Definition at line 176 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::getOffset(), and Euclid::NdArray::NdArray< T, Container >::m_container.

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
template<typename... D>
T& Euclid::NdArray::NdArray< T, Container >::at ( size_t  i,
D...  rest 
)
inline

Gets a reference to the value stored at the given coordinates.

Parameters
coordsElements coordinates.
Exceptions
std::out_of_rangeIf the number of coordinates is invalid, or any of them is out of bounds.
Note
This is a convenience function that allows access without requiring a vector when the number of dimensions is known in advance (i.e. at(x, y, z) instead of at(std::vector<size_t>{x, y, z})).

Definition at line 192 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::at_helper().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
template<typename... D>
const T& Euclid::NdArray::NdArray< T, Container >::at ( size_t  i,
D...  rest 
) const
inline

Gets a constant reference to the value stored at the given coordinates.

Parameters
coordsElements coordinates.
Exceptions
std::out_of_rangeIf the number of coordinates is invalid, or any of them is out of bounds.
Note
This is a convenience function that allows access without requiring a vector when the number of dimensions is known in advance (i.e. at(x, y, z) instead of at(std::vector<size_t>{x, y, z})).

Definition at line 208 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::at_helper().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
template<typename... D>
T& Euclid::NdArray::NdArray< T, Container >::at_helper ( std::vector< size_t > &  acc,
size_t  i,
D...  rest 
)
inlineprivate

Helper to expand at with a variable number of arguments

Definition at line 307 of file NdArray.h.

References std::vector< T >::push_back().

Referenced by Euclid::NdArray::NdArray< T, Container >::at(), and Euclid::NdArray::NdArray< T, Container >::at_helper().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
T& Euclid::NdArray::NdArray< T, Container >::at_helper ( std::vector< size_t > &  acc)
inlineprivate

Helper to expand at with a variable number of arguments (base case)

Definition at line 315 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::at().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
template<typename... D>
const T& Euclid::NdArray::NdArray< T, Container >::at_helper ( std::vector< size_t > &  acc,
size_t  i,
D...  rest 
) const
inlineprivate

Helper to expand constant at with a variable number of arguments

Definition at line 323 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::at_helper(), and std::vector< T >::push_back().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
const T& Euclid::NdArray::NdArray< T, Container >::at_helper ( std::vector< size_t > &  acc) const
inlineprivate

Helper to expand constant at with a variable number of arguments (base case)

Definition at line 331 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::at().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
iterator Euclid::NdArray::NdArray< T, Container >::begin ( )
inline
Returns
An iterator pointing to the first element (which corresponds to the one with the coordinates set to 0).

Definition at line 217 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container.

template<typename T , template< class...> class Container = std::vector>
const_iterator Euclid::NdArray::NdArray< T, Container >::begin ( ) const
inline
Returns
A constant iterator pointing to the first element (which corresponds to the one with the coordinates set to 0).

Definition at line 233 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container.

template<typename T , template< class...> class Container = std::vector>
const Container<T>& Euclid::NdArray::NdArray< T, Container >::data ( ) const
inline
Returns
A const reference to the underlying container

Definition at line 248 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container.

Referenced by Euclid::NdArray::NdArray< T, Container >::operator!=(), and Euclid::NdArray::NdArray< T, Container >::operator==().

template<typename T , template< class...> class Container = std::vector>
iterator Euclid::NdArray::NdArray< T, Container >::end ( )
inline
Returns
An iterator pointing just after the last element (which correspond to the one with the coordinates set to (shape[0]-1, shape[1]-1, ... shape[n]-1).

Definition at line 225 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container.

template<typename T , template< class...> class Container = std::vector>
const_iterator Euclid::NdArray::NdArray< T, Container >::end ( ) const
inline
Returns
A constant iterator pointing just after the last element (which correspond to the one with the coordinates set to (shape[0]-1, shape[1]-1, ... shape[n]-1).

Definition at line 241 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container.

template<typename T , template< class...> class Container = std::vector>
size_t Euclid::NdArray::NdArray< T, Container >::getOffset ( const std::vector< size_t > &  coords) const
inlineprivate

Gets the total offset for the given coordinates.

Exceptions
std::out_of_rangeIf the number of coordinates is invalid, or any of them is out of bounds.

Definition at line 282 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container, Euclid::NdArray::NdArray< T, Container >::m_shape, Euclid::NdArray::NdArray< T, Container >::m_stride_size, std::vector< T >::size(), and std::to_string().

Referenced by Euclid::NdArray::NdArray< T, Container >::at().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
bool Euclid::NdArray::NdArray< T, Container >::operator!= ( const self_type b) const
inline

Two NdArrays are not equal if their shapes or their content are not equal

Definition at line 269 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::data(), and Euclid::NdArray::NdArray< T, Container >::shape().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
NdArray& Euclid::NdArray::NdArray< T, Container >::operator= ( const NdArray< T, Container > &  )
default

Assignment

template<typename T , template< class...> class Container = std::vector>
bool Euclid::NdArray::NdArray< T, Container >::operator== ( const self_type b) const
inline

Two NdArrays are equal if their shapes and their content are equal

Definition at line 262 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::data(), and Euclid::NdArray::NdArray< T, Container >::shape().

Here is the call graph for this function:

template<typename T , template< class...> class Container = std::vector>
const std::vector<size_t> Euclid::NdArray::NdArray< T, Container >::shape ( ) const
inline

Gets the shape of the matrix.

Returns
A vector with as many elements as number of dimensions, containing the size of each one.

Definition at line 153 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_shape.

Referenced by Euclid::NdArray::NdArray< T, Container >::operator!=(), and Euclid::NdArray::NdArray< T, Container >::operator==().

template<typename T , template< class...> class Container = std::vector>
size_t Euclid::NdArray::NdArray< T, Container >::size ( ) const
inline

Size of the underlying container

Definition at line 255 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container.

Member Data Documentation

template<typename T , template< class...> class Container = std::vector>
Container<T> Euclid::NdArray::NdArray< T, Container >::m_container
private
template<typename T , template< class...> class Container = std::vector>
std::vector<size_t> Euclid::NdArray::NdArray< T, Container >::m_shape
private
template<typename T , template< class...> class Container = std::vector>
std::vector<size_t> Euclid::NdArray::NdArray< T, Container >::m_stride_size
private

Definition at line 274 of file NdArray.h.

Referenced by Euclid::NdArray::NdArray< T, Container >::getOffset().


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