Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
#include <NdArray.h>
Classes | |
struct | ContainerInterface |
struct | ContainerWrapper |
struct | Details |
class | Iterator |
Public Types | |
using | self_type = NdArray< T > |
using | const_iterator = Iterator< true > |
using | iterator = Iterator< false > |
Public Member Functions | |
~NdArray ()=default | |
NdArray (std::vector< size_t > shape_) | |
template<template< class... > class Container = std::vector> | |
NdArray (std::vector< size_t > shape_, const Container< T > &data) | |
template<template< class... > class Container = std::vector> | |
NdArray (std::vector< size_t > shape_, Container< T > &&data) | |
template<template< class... > class Container = std::vector> | |
NdArray (std::vector< size_t > shape_, std::vector< size_t > strides_, Container< T > &&data) | |
template<typename Iterator > | |
NdArray (std::vector< size_t > shape_, Iterator begin, Iterator end) | |
template<typename... Args> | |
NdArray (const std::vector< size_t > &shape_, const std::vector< std::string > &attr_names, Args &&... args) | |
NdArray (const std::initializer_list< size_t > &shape_) | |
NdArray (const self_type &) | |
NdArray (self_type &&) noexcept=default | |
NdArray & | operator= (const NdArray &) |
NdArray | copy () const |
const std::vector< size_t > & | shape () const |
size_t | shape (std::size_t i) const |
const std::vector< std::size_t > & | strides () const |
std::size_t | strides (std::size_t i) const |
self_type & | reshape (const std::vector< size_t > &new_shape) |
template<typename... D> | |
self_type & | reshape (size_t i, D... rest) |
const T & | front () const |
T & | at (const std::vector< size_t > &coords) |
const T & | at (const std::vector< size_t > &coords) const |
T & | at (const std::vector< size_t > &coords, const std::string &attr) |
const T & | at (const std::vector< size_t > &coords, const std::string &attr) 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 |
size_t | size () const |
bool | operator== (const self_type &b) const |
bool | operator!= (const self_type &b) const |
self_type & | concatenate (const self_type &other) |
self_type | slice (size_t i) |
const self_type | slice (size_t i) const |
self_type | rslice (size_t i) |
const self_type | rslice (size_t i) const |
void | next_slice (void) |
const std::vector< std::string > & | attributes () const |
Private Member Functions | |
NdArray (const self_type *other) | |
NdArray (std::shared_ptr< ContainerInterface > container, size_t offset, std::vector< size_t > shape, std::vector< size_t > stride, std::vector< std::string > attr_names) | |
size_t | get_offset (const std::vector< size_t > &coords) const |
size_t | get_attr_offset (const std::string &attr) const |
void | update_strides () |
template<typename... D> | |
T & | at_helper (size_t offset_acc, size_t axis, size_t i, D... rest) |
T & | at_helper (size_t offset_acc, size_t axis) |
T & | at_helper (size_t offset_acc, size_t axis, const std::string &attr) |
template<typename... D> | |
const T & | at_helper (size_t offset_acc, size_t axis, size_t i, D... rest) const |
const T & | at_helper (size_t offset_acc, size_t axis) const |
const T & | at_helper (size_t offset_acc, size_t axis, const std::string &attr) const |
template<typename... D> | |
self_type & | reshape_helper (std::vector< size_t > &acc, size_t i, D... rest) |
self_type & | reshape_helper (std::vector< size_t > &acc) |
Private Attributes | |
std::unique_ptr< Details > | m_details_ptr |
Stores a multidimensional array in a contiguous piece of memory in row-major order
T | Data type |
Container | Which container to use, by default std::vector |
using Euclid::NdArray::NdArray< T >::const_iterator = Iterator<true> |
using Euclid::NdArray::NdArray< T >::iterator = Iterator<false> |
using Euclid::NdArray::NdArray< T >::self_type = NdArray<T> |
|
default |
Destructor.
|
explicit |
Constructs a default-initialized matrix with the given shape.
shape_ | The shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size. |
Euclid::NdArray::NdArray< T >::NdArray | ( | std::vector< size_t > | shape_, |
const Container< T > & | data | ||
) |
Constructs a matrix and initialize it with the given data.
shape_ | The shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size. |
data | The initial data. It must match exactly the matrix size (shape[0]*shape[1]...*shape[n]). |
std::invalid_argument | If the data size does not corresponds to the matrix size. |
Euclid::NdArray::NdArray< T >::NdArray | ( | std::vector< size_t > | shape_, |
Container< T > && | data | ||
) |
Constructs a matrix and initialize it with the given data.
Container | Owns the memory used by the NdArray. It must expose the methods size(), resize() and data(). |
shape_ | The shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size. |
data | The 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. |
std::invalid_argument | If the data size does not corresponds to the matrix size. |
Euclid::NdArray::NdArray< T >::NdArray | ( | std::vector< size_t > | shape_, |
std::vector< size_t > | strides_, | ||
Container< T > && | data | ||
) |
Construct a matrix with a custom container and strides.
Container | Owns the memory used by the NdArray. It must expose the methods size(), resize() and data(). |
shape_ | The shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size. |
strides_ | The number of bytes we need to jump between adjacent positions on a given dimension |
data | The initial data. The NdArray will move the data into its internal storage! This avoids a copy, but remember to not use data after this call. |
std::runtime_error | If the data is not in C order. |
std::invalid_argument | If the shape and strides dimension do not match. |
Euclid::NdArray::NdArray< T >::NdArray | ( | std::vector< size_t > | shape_, |
Iterator | begin, | ||
Iterator | end | ||
) |
Constructs a matrix and initialize it with from the given iterators
shape_ | The shape of the matrix. The number of elements in shape corresponds to the number of dimensions, the values to each dimension size. |
begin | The beginning of the data |
end | The end of the data |
std::invalid_argument | If the data size does not corresponds to the matrix size. |
Euclid::NdArray::NdArray< T >::NdArray | ( | const std::vector< size_t > & | shape_, |
const std::vector< std::string > & | attr_names, | ||
Args &&... | args | ||
) |
Constructs a matrix, giving a name to each of the items on the last dimension
attr_names | Names for the dimensions of the last axis |
shape_ | Shape for the matrix |
|
inlineexplicit |
Euclid::NdArray::NdArray< T >::NdArray | ( | const self_type & | ) |
Copy constructor
|
defaultnoexcept |
Move constructor
|
explicitprivate |
Private constructor used for deep copies
|
private |
Private constructor used for slices
T & Euclid::NdArray::NdArray< T >::at | ( | const std::vector< size_t > & | coords | ) |
Gets a reference to the value stored at the given coordinates.
coords | Elements coordinates. |
std::out_of_range | If the number of coordinates is invalid, or any of them is out of bounds. |
const T & Euclid::NdArray::NdArray< T >::at | ( | const std::vector< size_t > & | coords | ) | const |
Gets a constant reference to the value stored at the given coordinates
coords | Elements coordinates. |
std::out_of_range | If the number of coordinates is invalid, or any of them is out of bounds. |
T & Euclid::NdArray::NdArray< T >::at | ( | const std::vector< size_t > & | coords, |
const std::string & | attr | ||
) |
Gets a reference to the value stored at the given coordinates.
coords | Elements coordinates, except last one |
attr | Attribute name used to determine the last coordinate |
std::out_of_range | If the number of coordinates is invalid, or any of them is out of bounds. |
const T & Euclid::NdArray::NdArray< T >::at | ( | const std::vector< size_t > & | coords, |
const std::string & | attr | ||
) | const |
Gets a constant reference to the value stored at the given coordinates.
coords | Elements coordinates, except last one |
attr | Attribute name used to determine the last coordinate |
std::out_of_range | If the number of coordinates is invalid, or any of them is out of bounds. |
T & Euclid::NdArray::NdArray< T >::at | ( | size_t | i, |
D... | rest | ||
) |
Gets a reference to the value stored at the given coordinates.
coords | Elements coordinates. |
at(x, y, z)
instead of at(std::vector<size_t>{x, y, z})
). const T & Euclid::NdArray::NdArray< T >::at | ( | size_t | i, |
D... | rest | ||
) | const |
Gets a constant reference to the value stored at the given coordinates.
coords | Elements coordinates. |
at(x, y, z)
instead of at(std::vector<size_t>{x, y, z})
).
|
private |
Helper to expand at with a variable number of arguments (base case)
|
private |
Helper to expand constant at with a variable number of arguments (base case)
|
private |
Helper to expand at with a variable number of arguments, being the last an attribute name
|
private |
Helper to expand constant at with a variable number of arguments, being the last an attribute name
|
private |
Helper to expand at with a variable number of arguments
|
private |
Helper to expand constant at with a variable number of arguments
const std::vector< std::string > & Euclid::NdArray::NdArray< T >::attributes | ( | ) | const |
iterator Euclid::NdArray::NdArray< T >::begin | ( | ) |
const_iterator Euclid::NdArray::NdArray< T >::begin | ( | ) | const |
self_type & Euclid::NdArray::NdArray< T >::concatenate | ( | const self_type & | other | ) |
Concatenate to this array another one along the first axis
|
inline |
iterator Euclid::NdArray::NdArray< T >::end | ( | ) |
const_iterator Euclid::NdArray::NdArray< T >::end | ( | ) | const |
const T & Euclid::NdArray::NdArray< T >::front | ( | ) | const |
|
private |
Get the offset for the given attribute name
std::out_of_range | If the attribute is unknown. |
|
private |
Gets the total offset for the given coordinates.
std::out_of_range | If the number of coordinates is invalid, or any of them is out of bounds. |
void Euclid::NdArray::NdArray< T >::next_slice | ( | void | ) |
bool Euclid::NdArray::NdArray< T >::operator!= | ( | const self_type & | b | ) | const |
Two NdArrays are not equal if their shapes or their content are not equal
NdArray & Euclid::NdArray::NdArray< T >::operator= | ( | const NdArray< T > & | ) |
Assignment
bool Euclid::NdArray::NdArray< T >::operator== | ( | const self_type & | b | ) | const |
Two NdArrays are equal if their shapes and their content are equal
self_type & Euclid::NdArray::NdArray< T >::reshape | ( | const std::vector< size_t > & | new_shape | ) |
Reshape the NdArray.
new_shape | A vector with as many elements as number of dimensions, containing the size of each one. |
std::range_error | If the new shape does not match the number of elements already contained within the NdArray. |
std::invalid_argument | If the array has attribute names |
self_type & Euclid::NdArray::NdArray< T >::reshape | ( | size_t | i, |
D... | rest | ||
) |
Reshape the NdArray.
new_shape | A vector with as many elements as number of dimensions, containing the size of each one. |
std::range_error | If the new shape does not match the number of elements already contained within the NdArray. |
|
private |
|
private |
self_type Euclid::NdArray::NdArray< T >::rslice | ( | size_t | i | ) |
Return a slice of the array cutting along the last axis
const self_type Euclid::NdArray::NdArray< T >::rslice | ( | size_t | i | ) | const |
Return a slice of the array cutting along the last axis
|
inline |
Gets the shape of the matrix.
Definition at line 319 of file NdArray.h.
References Euclid::NdArray::NdArray< T >::m_details_ptr.
Referenced by Euclid::Table::ndArraySize(), and Euclid::NdArray::NdArray< T >::ContainerWrapper< Container >::resize().
|
inline |
i |
Definition at line 327 of file NdArray.h.
References Euclid::NdArray::NdArray< T >::m_details_ptr.
size_t Euclid::NdArray::NdArray< T >::size | ( | ) | const |
Size of the underlying container
self_type Euclid::NdArray::NdArray< T >::slice | ( | size_t | i | ) |
Return a slice of the array cutting along the first axis
const self_type Euclid::NdArray::NdArray< T >::slice | ( | size_t | i | ) | const |
Return a slice of the array cutting along the first axis
|
inline |
Definition at line 331 of file NdArray.h.
References Euclid::NdArray::NdArray< T >::m_details_ptr.
|
inline |
Definition at line 335 of file NdArray.h.
References Euclid::NdArray::NdArray< T >::m_details_ptr.
|
private |
Compute the stride size for each dimension
|
private |
Definition at line 619 of file NdArray.h.
Referenced by Euclid::NdArray::NdArray< T >::shape(), Euclid::NdArray::NdArray< T >::shape(), Euclid::NdArray::NdArray< T >::strides(), and Euclid::NdArray::NdArray< T >::strides().