KASKADE 7 development version
Public Member Functions | Static Public Attributes | Related Functions | List of all members
Kaskade::Tensor< Entry, Size0, Sizes > Class Template Reference

A class for representing tensors of arbitrary static rank and extents. More...

#include <tensor.hh>

Detailed Description

template<class Entry, int Size0, int ... Sizes>
class Kaskade::Tensor< Entry, Size0, Sizes >

A class for representing tensors of arbitrary static rank and extents.

Template Parameters
Entrythe type of tensor entries
Size0the extent of the first dimension (must be >0)
Sizesthe extents of the remaining dimensions

Definition at line 85 of file tensor.hh.

Inheritance diagram for Kaskade::Tensor< Entry, Size0, Sizes >:
Dune::FieldVector< Tensor< Entry, Sizes... >, Size0 >

Public Member Functions

 operator std::conditional_t< rank==2, Dune::FieldMatrix< Entry, Size0, Base::block_type::dimension >, Base & > () const
 Implicit conversion of rank 2 tensors to Dune::FieldMatrix. More...
 
Constructors
 Tensor ()=default
 
 Tensor (Entry const &e)
 
Assignment
Tensoroperator= (Entry const &e)
 Assignment from a scalar. More...
 
Tensoroperator= (Dune::FieldMatrix< Entry, Size0, Size1 > const &a)
 
Element and subtensor access

The tensor class supports element access via the subscript operator [], indexed by integers, and the access via the call operator (). Both have different semantics. While subscript provides read and write access by returning (mutable or const) references to entries (or sub-tensors ordered by dimension), the call operator returns subtensors only by value, but is not restricted to ordered dimension access or complete ranges along dimensions.

Examples

Let \( a_{ijk} \) be a rank-3 tensor.

  • a[0] yields a reference to the rank-2 subtensor \( a_{0jk} \)
  • a[0][1][2] yields a reference to the tensor entry \( a_{012} \)
  • a(0,1,2) yields a copy of the tensor entry \( a_{012} \)
  • a(StaticIndexedRange<0,2>(),1,2) yields the rank-1 tensor (vector) \( (a_{i12})_{i\in\{0,1\}} \) by value
  • a(_,_,1) yields the rank-2 tensor (convertible to matrix) \( (a_{ij1})_{i,j} \) by value, taking the complete dimensions 0 and 1.
See also
_
template<class ... Access>
auto operator() (int i0, Access... is) const
 
template<int first, int last, class ... Access>
auto operator() (StaticIndexRange< first, last >, Access... is) const
 

Static Public Attributes

static constexpr int rank = Tensor<Entry,Sizes...>::rank + 1
 The rank of the tensor. More...
 

Related Functions

(Note that these are not member functions.)

template<class Entry , int Size0, int ... Sizes>
Tensor< Entry, Size0, Sizes... > operator* (typename EntryTraits< Entry >::field_type a, Tensor< Entry, Size0, Sizes... > A)
 Scalar times tensor multiplication. More...
 
template<class Entry , int n>
Entry trace (Tensor< Entry, n, n > const &A)
 Trace of a square matrix-shaped tensor. More...
 

Constructor & Destructor Documentation

◆ Tensor() [1/2]

template<class Entry , int Size0, int ... Sizes>
Kaskade::Tensor< Entry, Size0, Sizes >::Tensor ( )
default

◆ Tensor() [2/2]

template<class Entry , int Size0, int ... Sizes>
Kaskade::Tensor< Entry, Size0, Sizes >::Tensor ( Entry const &  e)
inline

Definition at line 103 of file tensor.hh.

Member Function Documentation

◆ operator std::conditional_t< rank==2, Dune::FieldMatrix< Entry, Size0, Base::block_type::dimension >, Base & >()

template<class Entry , int Size0, int ... Sizes>
Kaskade::Tensor< Entry, Size0, Sizes >::operator std::conditional_t< rank==2, Dune::FieldMatrix< Entry, Size0, Base::block_type::dimension >, Base & > ( ) const
inline

Implicit conversion of rank 2 tensors to Dune::FieldMatrix.

Definition at line 187 of file tensor.hh.

◆ operator()() [1/2]

template<class Entry , int Size0, int ... Sizes>
template<class ... Access>
auto Kaskade::Tensor< Entry, Size0, Sizes >::operator() ( int  i0,
Access...  is 
) const
inline

Definition at line 163 of file tensor.hh.

◆ operator()() [2/2]

template<class Entry , int Size0, int ... Sizes>
template<int first, int last, class ... Access>
auto Kaskade::Tensor< Entry, Size0, Sizes >::operator() ( StaticIndexRange< first, last >  ,
Access...  is 
) const
inline

Definition at line 169 of file tensor.hh.

◆ operator=() [1/2]

template<class Entry , int Size0, int ... Sizes>
Tensor & Kaskade::Tensor< Entry, Size0, Sizes >::operator= ( Dune::FieldMatrix< Entry, Size0, Size1 > const &  a)
inline

Definition at line 126 of file tensor.hh.

◆ operator=() [2/2]

template<class Entry , int Size0, int ... Sizes>
Tensor & Kaskade::Tensor< Entry, Size0, Sizes >::operator= ( Entry const &  e)
inline

Assignment from a scalar.

Definition at line 119 of file tensor.hh.

Member Data Documentation

◆ rank

template<class Entry , int Size0, int ... Sizes>
constexpr int Kaskade::Tensor< Entry, Size0, Sizes >::rank = Tensor<Entry,Sizes...>::rank + 1
staticconstexpr

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