MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
maia::tensor::Tensor< T > Class Template Reference

Provides a lightweight and fast class for accessing 1D arrays as multi-dimensional tensors (up to 4D). More...

#include <tensor.h>

Inheritance diagram for maia::tensor::Tensor< T >:
[legend]

Public Types

typedef MLong size_type
 
typedef T value_type
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef value_typereference
 
typedef const value_typeconst_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 > &&copy)=default
 
 Tensor (const Tensor< T > &copy)=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...
 

Detailed Description

template<class T>
class maia::tensor::Tensor< T >
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Template Parameters
TScalar data type of the tensor elements.

Use with care when doing performance-sensitive work as this has not yet been sufficiently tested for speed.

Definition at line 41 of file tensor.h.

Member Typedef Documentation

◆ const_iterator

template<class T >
typedef const_pointer maia::tensor::Tensor< T >::const_iterator

Definition at line 51 of file tensor.h.

◆ const_pointer

template<class T >
typedef const value_type* maia::tensor::Tensor< T >::const_pointer

Definition at line 47 of file tensor.h.

◆ const_reference

template<class T >
typedef const value_type& maia::tensor::Tensor< T >::const_reference

Definition at line 49 of file tensor.h.

◆ DataStorage

template<class T >
typedef detail_::TensorStorage<T> maia::tensor::Tensor< T >::DataStorage
private

Definition at line 98 of file tensor.h.

◆ dim_type

template<class T >
typedef MInt maia::tensor::Tensor< T >::dim_type

Definition at line 52 of file tensor.h.

◆ iterator

template<class T >
typedef pointer maia::tensor::Tensor< T >::iterator

Definition at line 50 of file tensor.h.

◆ pointer

template<class T >
typedef value_type* maia::tensor::Tensor< T >::pointer

Definition at line 46 of file tensor.h.

◆ reference

template<class T >
typedef value_type& maia::tensor::Tensor< T >::reference

Definition at line 48 of file tensor.h.

◆ size_type

template<class T >
typedef MLong maia::tensor::Tensor< T >::size_type

Definition at line 44 of file tensor.h.

◆ value_type

template<class T >
typedef T maia::tensor::Tensor< T >::value_type

Definition at line 45 of file tensor.h.

Constructor & Destructor Documentation

◆ Tensor() [1/5]

template<class T >
maia::tensor::Tensor< T >::Tensor
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09

Definition at line 113 of file tensor.h.

113 : m_data(), m_size(0) {
114 m_dim[0] = 0;
115 m_dim[1] = 0;
116 m_dim[2] = 0;
117 m_dim[3] = 0;
118 m_dim[4] = 0;
119}
size_type m_dim[m_maxNoDims]
Definition: tensor.h:102
DataStorage m_data
Definition: tensor.h:100
size_type m_size
Definition: tensor.h:101

◆ Tensor() [2/5]

template<class T >
maia::tensor::Tensor< T >::Tensor ( size_type  n0,
size_type  n1 = 1,
size_type  n2 = 1,
size_type  n3 = 1,
size_type  n4 = 1 
)
inlineexplicit
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]dataPointer to previously allocated 1D array.
[in]n0Size of first dimension.
[in]n1Size of second dimension.
[in]n2Size of third dimension.
[in]n3Size of fourth dimension.
[in]n4Size of fifth dimension.

Definition at line 135 of file tensor.h.

135 {
136 ASSERT(n0 > 0, "Dimension n0 must be greater than zero");
137 ASSERT(n1 > 0, "Dimension n1 must be greater than zero");
138 ASSERT(n2 > 0, "Dimension n2 must be greater than zero");
139 ASSERT(n3 > 0, "Dimension n3 must be greater than zero");
140 ASSERT(n4 > 0, "Dimension n4 must be greater than zero");
141
142 m_dim[0] = n0;
143 m_dim[1] = n1;
144 m_dim[2] = n2;
145 m_dim[3] = n3;
146 m_dim[4] = n4;
147
148 m_size = n0 * n1 * n2 * n3 * n4;
150}
void resize(size_type n)
Resizes the container by first dropping all existing elements and then reallocating new memory.
Definition: tensor.h:924

◆ Tensor() [3/5]

template<class T >
maia::tensor::Tensor< T >::Tensor ( T *  data,
size_type  n0,
size_type  n1 = 1,
size_type  n2 = 1,
size_type  n3 = 1,
size_type  n4 = 1 
)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]dataPointer to previously allocated 1D array.
[in]n0Size of first dimension.
[in]n1Size of second dimension.
[in]n2Size of third dimension.
[in]n3Size of fourth dimension.
[in]n4Size of fifth dimension.

Definition at line 167 of file tensor.h.

167 {
168 ASSERT(n0 > 0, "Dimension n0 must be greater than zero");
169 ASSERT(n1 > 0, "Dimension n1 must be greater than zero");
170 ASSERT(n2 > 0, "Dimension n2 must be greater than zero");
171 ASSERT(n3 > 0, "Dimension n3 must be greater than zero");
172 ASSERT(n4 > 0, "Dimension n4 must be greater than zero");
173
174 m_dim[0] = n0;
175 m_dim[1] = n1;
176 m_dim[2] = n2;
177 m_dim[3] = n3;
178 m_dim[4] = n4;
179
180 m_size = n0 * n1 * n2 * n3 * n4;
181 m_data.resize(m_size, data);
182}

◆ ~Tensor()

template<class T >
maia::tensor::Tensor< T >::~Tensor
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09

Definition at line 191 of file tensor.h.

191 {
192 clear();
193}
void clear()
Deletes the data (if internal storage was used) and resets dimensions to zero.
Definition: tensor.h:283

◆ Tensor() [4/5]

template<class T >
maia::tensor::Tensor< T >::Tensor ( Tensor< T > &&  copy)
default

◆ Tensor() [5/5]

template<class T >
maia::tensor::Tensor< T >::Tensor ( const Tensor< T > &  copy)
default

Member Function Documentation

◆ assign()

template<class T >
void maia::tensor::Tensor< T >::assign ( size_type  n,
const T &  value 
)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-13
Template Parameters
T
Parameters
[in]n
[in]value

Definition at line 256 of file tensor.h.

256 {
257 resize(n);
258 set(value);
259}
void set(const T &value)
Initializes tensor to constant value.
Definition: tensor.h:271
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.
Definition: tensor.h:230

◆ clear()

template<class T >
void maia::tensor::Tensor< T >::clear
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-13

Definition at line 283 of file tensor.h.

283 {
284 m_dim[0] = 0;
285 m_dim[1] = 0;
286 m_dim[2] = 0;
287 m_dim[3] = 0;
288 m_dim[4] = 0;
289
290 m_size = 0;
291 m_data.clear();
292}
void clear()
Clears the data storage by deallocating any previously allocated memory and setting the size to zero.
Definition: tensor.h:959

◆ dim()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::dim ( size_type  d) const
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]dThe requested dimension.
Returns
Size of dimension d.

Definition at line 349 of file tensor.h.

349 {
350 ASSERT(d >= 0, "Dimension d must be greater than or equal to zero!");
351 ASSERT(d < m_maxNoDims, "Dimension d must be less than m_maxNoDims!");
352
353 return m_dim[d];
354}
static const dim_type m_maxNoDims
Definition: tensor.h:97

◆ dim0()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::dim0
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Returns
Size of dimension 0.

Definition at line 366 of file tensor.h.

366 {
367 return m_dim[0];
368}

◆ dim1()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::dim1
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Returns
Size of dimension 1.

Definition at line 380 of file tensor.h.

380 {
381 return m_dim[1];
382}

◆ dim2()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::dim2
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Returns
Size of dimension 2.

Definition at line 394 of file tensor.h.

394 {
395 return m_dim[2];
396}

◆ dim3()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::dim3
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Returns
Size of dimension 3.

Definition at line 408 of file tensor.h.

408 {
409 return m_dim[3];
410}

◆ dim4()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::dim4
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Returns
Size of dimension 4.

Definition at line 422 of file tensor.h.

422 {
423 return m_dim[4];
424}

◆ operator()() [1/10]

template<class T >
T & maia::tensor::Tensor< T >::operator() ( size_type  i0)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
Returns
The array element at the specified index.

Definition at line 498 of file tensor.h.

498 {
499 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
500
501 return m_data[i0];
502}
size_type dim0() const
Return the size of dimension 0.
Definition: tensor.h:366

◆ operator()() [2/10]

template<class T >
const T & maia::tensor::Tensor< T >::operator() ( size_type  i0) const
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
Returns
The array element at the specified index.

Definition at line 516 of file tensor.h.

516 {
517 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
518
519 return m_data[i0];
520}

◆ operator()() [3/10]

template<class T >
T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1 
)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
Returns
The array element at the specified index.

Definition at line 535 of file tensor.h.

535 {
536 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
537 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
538
539 return m_data[i0 * dim1() + i1];
540}
size_type dim1() const
Return the size of dimension 1.
Definition: tensor.h:380

◆ operator()() [4/10]

template<class T >
const T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1 
) const
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
Returns
The array element at the specified index.

Definition at line 555 of file tensor.h.

555 {
556 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
557 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
558
559 return m_data[i0 * dim1() + i1];
560}

◆ operator()() [5/10]

template<class T >
T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1,
size_type  i2 
)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
[in]i2Index of third dimension.
Returns
The array element at the specified index.

Definition at line 576 of file tensor.h.

576 {
577 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
578 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
579 ASSERT(i2 >= 0 && i2 < dim2(), "Index i2 out of bounds");
580
581 return m_data[i0 * dim1() * dim2() + i1 * dim2() + i2];
582}
size_type dim2() const
Return the size of dimension 2.
Definition: tensor.h:394

◆ operator()() [6/10]

template<class T >
const T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1,
size_type  i2 
) const
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
[in]i2Index of third dimension.
Returns
The array element at the specified index.

Definition at line 598 of file tensor.h.

598 {
599 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
600 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
601 ASSERT(i2 >= 0 && i2 < dim2(), "Index i2 out of bounds");
602
603 return m_data[i0 * dim1() * dim2() + i1 * dim2() + i2];
604}

◆ operator()() [7/10]

template<class T >
T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1,
size_type  i2,
size_type  i3 
)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
[in]i2Index of third dimension.
[in]i3Index of fourth dimension.
Returns
The array element at the specified index.

Definition at line 621 of file tensor.h.

621 {
622 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
623 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
624 ASSERT(i2 >= 0 && i2 < dim2(), "Index i2 out of bounds");
625 ASSERT(i3 >= 0 && i3 < dim3(), "Index i3 out of bounds");
626
627 return m_data[i0 * dim1() * dim2() * dim3() + i1 * dim2() * dim3() + i2 * dim3() + i3];
628}
size_type dim3() const
Return the size of dimension 3.
Definition: tensor.h:408

◆ operator()() [8/10]

template<class T >
const T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1,
size_type  i2,
size_type  i3 
) const
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
[in]i2Index of third dimension.
[in]i3Index of fourth dimension.
Returns
The array element at the specified index.

Definition at line 645 of file tensor.h.

645 {
646 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
647 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
648 ASSERT(i2 >= 0 && i2 < dim2(), "Index i2 out of bounds");
649 ASSERT(i3 >= 0 && i3 < dim3(), "Index i3 out of bounds");
650
651 return m_data[i0 * dim1() * dim2() * dim3() + i1 * dim2() * dim3() + i2 * dim3() + i3];
652}

◆ operator()() [9/10]

template<class T >
T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1,
size_type  i2,
size_type  i3,
size_type  i4 
)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
[in]i2Index of third dimension.
[in]i3Index of fourth dimension.
[in]i4Index of fifth dimension.
Returns
The array element at the specified index.

Definition at line 670 of file tensor.h.

670 {
671 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
672 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
673 ASSERT(i2 >= 0 && i2 < dim2(), "Index i2 out of bounds");
674 ASSERT(i3 >= 0 && i3 < dim3(), "Index i3 out of bounds");
675 ASSERT(i4 >= 0 && i4 < dim4(), "Index i4 out of bounds");
676
677 return m_data[i0 * dim1() * dim2() * dim3() * dim4() + i1 * dim2() * dim3() * dim4() + i2 * dim3() * dim4()
678 + i3 * dim4() + i4];
679}
size_type dim4() const
Return the size of dimension 4.
Definition: tensor.h:422

◆ operator()() [10/10]

template<class T >
const T & maia::tensor::Tensor< T >::operator() ( size_type  i0,
size_type  i1,
size_type  i2,
size_type  i3,
size_type  i4 
) const
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Parameters
[in]i0Index of first dimension.
[in]i1Index of second dimension.
[in]i2Index of third dimension.
[in]i3Index of fourth dimension.
[in]i4Index of fifth dimension.
Returns
The array element at the specified index.

Definition at line 697 of file tensor.h.

697 {
698 ASSERT(i0 >= 0 && i0 < dim0(), "Index i0 out of bounds");
699 ASSERT(i1 >= 0 && i1 < dim1(), "Index i1 out of bounds");
700 ASSERT(i2 >= 0 && i2 < dim2(), "Index i2 out of bounds");
701 ASSERT(i3 >= 0 && i3 < dim3(), "Index i3 out of bounds");
702 ASSERT(i4 >= 0 && i4 < dim4(), "Index i4 out of bounds");
703
704 return m_data[i0 * dim1() * dim2() * dim3() * dim4() + i1 * dim2() * dim3() * dim4() + i2 * dim3() * dim4()
705 + i3 * dim4() + i4];
706}

◆ operator=()

template<class T >
Tensor< T > & maia::tensor::Tensor< T >::operator= ( Tensor< T >  copy)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-13
Parameters
[in]copyThe tensor that is assigned from.
Returns
This tensor with the new data.

Definition at line 438 of file tensor.h.

438 {
439 swap(copy);
440
441 return *this;
442}
friend void swap(Tensor< TT > &a, Tensor< TT > &b)
Non-member swap exchanges the contents of two Tensors.
Definition: tensor.h:752

◆ operator[]() [1/2]

template<class T >
T & maia::tensor::Tensor< T >::operator[] ( size_type  index)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-14
Parameters
[in]indexPosition of the element in the data storage.
Returns
The element at the specified position.

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.

459 {
460 ASSERT(index >= 0 && index < size(), "Index out of bounds");
461
462 return m_data[index];
463}
size_type size() const
Returns the size of the array as product of all five dimensions (i.e. not the actual array size but t...
Definition: tensor.h:206
IdType index(const FloatType *const x, const IdType level)
Return Hilbert index for given location and level in 2D or 3D.
Definition: hilbert.h:165

◆ operator[]() [2/2]

template<class T >
const T & maia::tensor::Tensor< T >::operator[] ( size_type  index) const
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-14
Parameters
[in]indexPosition of the element in the data storage.
Returns
The element at the specified position.

This provides an array-like access to the tensor, which is especially useful if the tensor is used as a vector.

Definition at line 480 of file tensor.h.

480 {
481 ASSERT(index >= 0 && index < size(), "Index out of bounds");
482
483 return m_data[index];
484}

◆ resize()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::resize ( size_type  n0,
size_type  n1 = 1,
size_type  n2 = 1,
size_type  n3 = 1,
size_type  n4 = 1 
)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-12
Template Parameters
T
Parameters
[in]n0
[in]n1
[in]n2
[in]n3
[in]n4
Returns
The new size of the data structure, i.e. the number of elements in the tensor.

Note: After a call to resize the tensor uses an internal storage, even if it was constructed with an external data pointer.

Definition at line 230 of file tensor.h.

231 {
232 m_dim[0] = n0;
233 m_dim[1] = n1;
234 m_dim[2] = n2;
235 m_dim[3] = n3;
236 m_dim[4] = n4;
237
238 m_size = n0 * n1 * n2 * n3 * n4;
239 m_data.resize(size());
240
241 return size();
242}

◆ set()

template<class T >
void maia::tensor::Tensor< T >::set ( const T &  value)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-13
Parameters
[in]valueConstant value that is assigned to all elements.

Definition at line 271 of file tensor.h.

271 {
272 std::fill_n(&m_data[0], size(), value);
273}

◆ size()

template<class T >
Tensor< T >::size_type maia::tensor::Tensor< T >::size
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-09
Returns
Total size of the data array as seen by the Tensor object.

Definition at line 206 of file tensor.h.

206 {
207 return m_size;
208}

◆ swap()

template<class T >
void maia::tensor::Tensor< T >::swap ( Tensor< T > &  other)
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-13
Template Parameters
TScalar dat atype of the tensor elements.
Parameters
[]other The tensor that should be swapped with.

Definition at line 329 of file tensor.h.

329 {
330 using std::swap;
331 swap(m_data, other.m_data);
332 swap(m_size, other.m_size);
333 for(dim_type i = 0; i < m_maxNoDims; ++i)
334 swap(m_dim[i], other.m_dim[i]);
335}

◆ transpose()

template<class T >
void maia::tensor::Tensor< T >::transpose
inline
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-13

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.

Definition at line 306 of file tensor.h.

306 {
307 Tensor<T> tmp(*this);
308
309 std::swap(m_dim[0], m_dim[1]);
310
311 for(MInt i = 0; i < tmp.dim0(); i++) {
312 for(MInt j = 0; j < tmp.dim1(); j++) {
313 (*this)(j, i) = tmp(i, j);
314 }
315 }
316}
int32_t MInt
Definition: maiatypes.h:62

Friends And Related Function Documentation

◆ swap

template<class T >
template<class TT >
void swap ( Tensor< TT > &  a,
Tensor< TT > &  b 
)
friend
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2012-11-13
Template Parameters
TTScalar data type of the tensor elements.
Parameters
[in]aThe first tensor to be swapped.
[in]bThe second tensor to be swapped.

Definition at line 752 of file tensor.h.

752 {
753 a.swap(b);
754}
Definition: contexttypes.h:19

Member Data Documentation

◆ m_data

template<class T >
DataStorage maia::tensor::Tensor< T >::m_data
private

Definition at line 100 of file tensor.h.

◆ m_dim

template<class T >
size_type maia::tensor::Tensor< T >::m_dim[m_maxNoDims] {}
private

Definition at line 102 of file tensor.h.

◆ m_maxNoDims

template<class T >
const dim_type maia::tensor::Tensor< T >::m_maxNoDims = 5
staticprivate

Definition at line 97 of file tensor.h.

◆ m_size

template<class T >
size_type maia::tensor::Tensor< T >::m_size
private

Definition at line 101 of file tensor.h.


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