MAIA bb96820c
Multiphysics at AIA
|
Provides a lightweight and fast class for accessing 1D arrays as multi-dimensional tensors (up to 4D). More...
#include <tensor.h>
Public Types | |
typedef MLong | size_type |
typedef T | value_type |
typedef value_type * | pointer |
typedef const value_type * | const_pointer |
typedef value_type & | reference |
typedef const value_type & | const_reference |
typedef pointer | iterator |
typedef const_pointer | const_iterator |
typedef MInt | dim_type |
Public Member Functions | |
Tensor () | |
Default constructor does nothing but setting all internal member variables to zero. More... | |
Tensor (size_type n0, size_type n1=1, size_type n2=1, size_type n3=1, size_type n4=1) | |
Initializes the Tensor object by setting the data pointer and the internal dimensions. More... | |
Tensor (T *data, size_type n0, size_type n1=1, size_type n2=1, size_type n3=1, size_type n4=1) | |
Initializes the Tensor object by setting the data pointer and the internal dimensions. More... | |
~Tensor () | |
Resets all internal pointers and variables to zero. More... | |
size_type | size () const |
Returns the size of the array as product of all five dimensions (i.e. not the actual array size but the size as seen by the Tensor object). More... | |
size_type | resize (size_type n0, size_type n1=1, size_type n2=1, size_type n3=1, size_type n4=1) |
Deletes the old data structure and creates a new one with the requested dimensions. More... | |
void | assign (size_type n, const T &newValue) |
Resizes the tensor to a 1D vector of length 'n' and with initial value 'value'. More... | |
void | set (const T &value) |
Initializes tensor to constant value. More... | |
void | clear () |
Deletes the data (if internal storage was used) and resets dimensions to zero. More... | |
void | transpose () |
Transposes the first two dimensions (i.e. acting as if the tensor is a matrix). More... | |
void | swap (Tensor< T > &other) |
Efficiently swap this tensor with another one (uses copying of pointers, no data is moved). More... | |
size_type | dim (size_type d) const |
Return the size of dimension d. More... | |
size_type | dim0 () const |
Return the size of dimension 0. More... | |
size_type | dim1 () const |
Return the size of dimension 1. More... | |
size_type | dim2 () const |
Return the size of dimension 2. More... | |
size_type | dim3 () const |
Return the size of dimension 3. More... | |
size_type | dim4 () const |
Return the size of dimension 4. More... | |
Tensor< T > & | operator= (Tensor< T > copy) |
Assignment operator. More... | |
Tensor (Tensor< T > &©)=default | |
Tensor (const Tensor< T > ©)=default | |
T & | operator[] (size_type index) |
Returns a reference to the element at position index (non-const version). More... | |
const T & | operator[] (size_type index) const |
Returns a reference to the element at position index (const version). More... | |
T & | operator() (size_type i0) |
Provides tensor access element using index notation (1D, non-const version). More... | |
const T & | operator() (size_type i0) const |
Provides tensor element access using index notation (1D, const version). More... | |
T & | operator() (size_type i0, size_type i1) |
Provides tensor access element using index notation (2D, non-const version). More... | |
const T & | operator() (size_type i0, size_type i1) const |
Provides tensor element access using index notation (2D, const version). More... | |
T & | operator() (size_type i0, size_type i1, size_type i2) |
Provides tensor access element using index notation (3D, non-const version). More... | |
const T & | operator() (size_type i0, size_type i1, size_type i2) const |
Provides tensor element access using index notation (3D, const version). More... | |
T & | operator() (size_type i0, size_type i1, size_type i2, size_type i3) |
Provides tensor access element using index notation (4D, non-const version). More... | |
const T & | operator() (size_type i0, size_type i1, size_type i2, size_type i3) const |
Provides tensor element access using index notation (4D, const version). More... | |
T & | operator() (size_type i0, size_type i1, size_type i2, size_type i3, size_type i4) |
Provides tensor access element using index notation (5D, non-const version). More... | |
const T & | operator() (size_type i0, size_type i1, size_type i2, size_type i3, size_type i4) const |
Provides tensor element access using index notation (5D, const version). More... | |
Private Types | |
typedef detail_::TensorStorage< T > | DataStorage |
Private Attributes | |
DataStorage | m_data |
size_type | m_size |
size_type | m_dim [m_maxNoDims] {} |
Static Private Attributes | |
static const dim_type | m_maxNoDims = 5 |
Friends | |
template<class TT > | |
void | swap (Tensor< TT > &a, Tensor< TT > &b) |
Non-member swap exchanges the contents of two Tensors. More... | |
T | Scalar data type of the tensor elements. |
Use with care when doing performance-sensitive work as this has not yet been sufficiently tested for speed.
typedef const_pointer maia::tensor::Tensor< T >::const_iterator |
typedef const value_type* maia::tensor::Tensor< T >::const_pointer |
typedef const value_type& maia::tensor::Tensor< T >::const_reference |
|
private |
typedef MInt maia::tensor::Tensor< T >::dim_type |
typedef pointer maia::tensor::Tensor< T >::iterator |
typedef value_type* maia::tensor::Tensor< T >::pointer |
typedef value_type& maia::tensor::Tensor< T >::reference |
typedef MLong maia::tensor::Tensor< T >::size_type |
typedef T maia::tensor::Tensor< T >::value_type |
|
inline |
|
inlineexplicit |
[in] | data | Pointer to previously allocated 1D array. |
[in] | n0 | Size of first dimension. |
[in] | n1 | Size of second dimension. |
[in] | n2 | Size of third dimension. |
[in] | n3 | Size of fourth dimension. |
[in] | n4 | Size of fifth dimension. |
Definition at line 135 of file tensor.h.
|
inline |
[in] | data | Pointer to previously allocated 1D array. |
[in] | n0 | Size of first dimension. |
[in] | n1 | Size of second dimension. |
[in] | n2 | Size of third dimension. |
[in] | n3 | Size of fourth dimension. |
[in] | n4 | Size of fifth dimension. |
Definition at line 167 of file tensor.h.
|
inline |
Definition at line 191 of file tensor.h.
|
default |
|
default |
|
inline |
T |
[in] | n | |
[in] | value |
Definition at line 256 of file tensor.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
[in] | i0 | Index of first dimension. |
|
inline |
|
inline |
[in] | i0 | Index of first dimension. |
[in] | i1 | Index of second dimension. |
|
inline |
[in] | i0 | Index of first dimension. |
[in] | i1 | Index of second dimension. |
|
inline |
[in] | i0 | Index of first dimension. |
[in] | i1 | Index of second dimension. |
[in] | i2 | Index of third dimension. |
|
inline |
[in] | i0 | Index of first dimension. |
[in] | i1 | Index of second dimension. |
[in] | i2 | Index of third dimension. |
|
inline |
[in] | i0 | Index of first dimension. |
[in] | i1 | Index of second dimension. |
[in] | i2 | Index of third dimension. |
[in] | i3 | Index of fourth dimension. |
|
inline |
|
inline |
[in] | i0 | Index of first dimension. |
[in] | i1 | Index of second dimension. |
[in] | i2 | Index of third dimension. |
[in] | i3 | Index of fourth dimension. |
[in] | i4 | Index of fifth dimension. |
|
inline |
[in] | i0 | Index of first dimension. |
[in] | i1 | Index of second dimension. |
[in] | i2 | Index of third dimension. |
[in] | i3 | Index of fourth dimension. |
[in] | i4 | Index of fifth dimension. |
|
inline |
[in] | copy | The tensor that is assigned from. |
Definition at line 438 of file tensor.h.
|
inline |
[in] | index | Position of the element in the data storage. |
This provides an array-like access to the tensor, which is especially useful if the tensor is used as a vector.
Definition at line 459 of file tensor.h.
|
inline |
[in] | index | Position of the element in the data storage. |
This provides an array-like access to the tensor, which is especially useful if the tensor is used as a vector.
|
inline |
T |
[in] | n0 | |
[in] | n1 | |
[in] | n2 | |
[in] | n3 | |
[in] | n4 |
Note: After a call to resize the tensor uses an internal storage, even if it was constructed with an external data pointer.
|
inline |
|
inline |
|
inline |
|
inline |
Note: This creates a temporary copy of the WHOLE tensor, even though only a copy of the first to dimensions would be needed. Thus this very expensive if transposing a higher- order tensor.
TT | Scalar data type of the tensor elements. |
[in] | a | The first tensor to be swapped. |
[in] | b | The second tensor to be swapped. |
|
private |
|
private |
|
staticprivate |
|
private |