Alexandria  2.16
Please provide a description of the project.
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)
 
template<typename Iterator >
 NdArray (const std::vector< size_t > &shape, Iterator begin, Iterator end)
 
 NdArray (const std::initializer_list< size_t > &shape)
 
 NdArray (const self_type &)=default
 
 NdArray (self_type &&)=default
 
NdArrayoperator= (const NdArray &)=default
 
const std::vector< size_t > shape () const
 
self_typereshape (const std::vector< size_t > new_shape)
 
template<typename ... D>
self_typereshape (size_t i, D... rest)
 
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 get_offset (const std::vector< size_t > &coords) const
 
void update_strides ()
 
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
 
template<typename ... D>
self_typereshape_helper (std::vector< size_t > &acc, size_t i, D... rest)
 
self_typereshape_helper (std::vector< size_t > &acc)
 

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

◆ const_iterator

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.

◆ iterator

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.

◆ self_type

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

◆ ~NdArray()

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

Destructor.

◆ NdArray() [1/7]

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

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.

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

Here is the call graph for this function:

◆ NdArray() [2/7]

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 77 of file NdArray.h.

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

Here is the call graph for this function:

◆ NdArray() [3/7]

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 97 of file NdArray.h.

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

Here is the call graph for this function:

◆ NdArray() [4/7]

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

Constructs a matrix and initialize it with from the given iterators

Parameters
shapeThe shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size.
beginThe beginning of the data
endThe end of the data
Exceptions
std::invalid_argumentIf the data size does not corresponds to the matrix size.

Definition at line 118 of file NdArray.h.

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

Here is the call graph for this function:

◆ NdArray() [5/7]

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 132 of file NdArray.h.

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

Here is the call graph for this function:

◆ NdArray() [6/7]

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

Copy constructor

◆ NdArray() [7/7]

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

Move constructor

Member Function Documentation

◆ at() [1/4]

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 201 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::get_offset(), 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:

◆ at() [2/4]

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 213 of file NdArray.h.

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

Here is the call graph for this function:

◆ at() [3/4]

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 229 of file NdArray.h.

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

Here is the call graph for this function:

◆ at() [4/4]

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 245 of file NdArray.h.

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

Here is the call graph for this function:

◆ at_helper() [1/4]

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 357 of file NdArray.h.

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

◆ at_helper() [2/4]

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 365 of file NdArray.h.

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

Here is the call graph for this function:

◆ at_helper() [3/4]

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 373 of file NdArray.h.

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

Here is the call graph for this function:

◆ at_helper() [4/4]

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 381 of file NdArray.h.

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

Here is the call graph for this function:

◆ begin() [1/2]

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 254 of file NdArray.h.

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

◆ begin() [2/2]

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 270 of file NdArray.h.

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

◆ data()

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 285 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==().

◆ end() [1/2]

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 262 of file NdArray.h.

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

◆ end() [2/2]

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 278 of file NdArray.h.

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

◆ get_offset()

template<typename T, template< class... > class Container = std::vector>
size_t Euclid::NdArray::NdArray< T, Container >::get_offset ( 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 319 of file NdArray.h.

References Euclid::NdArray::NdArray< T, Container >::m_container, Euclid::NdArray::NdArray< T, Container >::m_shape, and Euclid::NdArray::NdArray< T, Container >::m_stride_size.

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

◆ operator!=()

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 306 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:

◆ operator=()

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

Assignment

◆ operator==()

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 299 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:

◆ reshape() [1/2]

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

Reshape the NdArray.

Note
This modifies the object
Parameters
new_shapeA vector with as many elements as number of dimensions, containing the size of each one.
Exceptions
std::range_errorIf the new shape does not match the number of elements already contained within the NdArray.
Returns
*this

Definition at line 168 of file NdArray.h.

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

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

Here is the call graph for this function:

◆ reshape() [2/2]

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

Reshape the NdArray.

Note
This modifies the object
Parameters
new_shapeA vector with as many elements as number of dimensions, containing the size of each one.
Exceptions
std::range_errorIf the new shape does not match the number of elements already contained within the NdArray.
Returns
*this

Definition at line 189 of file NdArray.h.

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

Here is the call graph for this function:

◆ reshape_helper() [1/2]

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

Definition at line 386 of file NdArray.h.

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

◆ reshape_helper() [2/2]

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

Definition at line 391 of file NdArray.h.

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

Here is the call graph for this function:

◆ shape()

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 154 of file NdArray.h.

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

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

◆ size()

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 292 of file NdArray.h.

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

◆ update_strides()

template<typename T, template< class... > class Container = std::vector>
void Euclid::NdArray::NdArray< T, Container >::update_strides ( )
inlineprivate

Member Data Documentation

◆ m_container

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

◆ m_shape

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

◆ m_stride_size

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

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