All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
PLMD::TensorGeneric< n, m > Class Template Reference

Class implementing fixed size matrices of doubles. More...

#include <Tensor.h>

Inheritance diagram for PLMD::TensorGeneric< n, m >:
Inheritance graph
[legend]

Public Member Functions

 TensorGeneric ()
 initialize the tensor to zero More...
 
 TensorGeneric (const VectorGeneric< n > &v1, const VectorGeneric< m > &v2)
 initialize a tensor as an external product of two Vector More...
 
 TensorGeneric (double, double, double, double)
 initialize a tensor with 4 values, in standard C order More...
 
 TensorGeneric (double, double, double, double, double, double, double, double, double)
 initialize a tensor with 9 values, in standard C order More...
 
void zero ()
 set it to zero More...
 
double & operator() (unsigned i, unsigned j)
 access element More...
 
const double & operator() (unsigned i, unsigned j) const
 access element More...
 
TensorGenericoperator+= (const TensorGeneric< n, m > &b)
 increment More...
 
TensorGenericoperator-= (const TensorGeneric< n, m > &b)
 decrement More...
 
TensorGenericoperator*= (double)
 multiply More...
 
TensorGenericoperator/= (double)
 divide More...
 
TensorGeneric operator+ () const
 return +t More...
 
TensorGeneric operator- () const
 return -t More...
 
TensorGenericsetCol (unsigned j, const VectorGeneric< n > &c)
 set j-th column More...
 
TensorGenericsetRow (unsigned i, const VectorGeneric< m > &r)
 set i-th row More...
 
VectorGeneric< ngetCol (unsigned j) const
 get j-th column More...
 
VectorGeneric< mgetRow (unsigned i) const
 get i-th row More...
 
double determinant () const
 returns the determinant More...
 
TensorGeneric inverse () const
 return the matrix inverse More...
 
TensorGeneric< m, ntranspose () const
 return the transpose matrix More...
 
template<>
 TensorGeneric (double d00, double d01, double d10, double d11)
 
template<>
 TensorGeneric (double d00, double d01, double d02, double d10, double d11, double d12, double d20, double d21, double d22)
 
template<>
double determinant () const
 
template<>
TensorGeneric< 3, 3 > inverse () const
 
Row operator[] (I i)
 access element (with [][] syntax) More...
 
Const_row operator[] (I i) const
 access element (with [][] syntax) More...
 

Static Public Member Functions

static TensorGeneric< n, nidentity ()
 return an identity tensor More...
 

Private Attributes

double d [n *m]
 

Friends

template<unsigned n_, unsigned m_>
TensorGeneric< n_, m_ > operator+ (const TensorGeneric< n_, m_ > &, const TensorGeneric< n_, m_ > &)
 return t1+t2 More...
 
template<unsigned n_, unsigned m_>
TensorGeneric< n_, m_ > operator- (const TensorGeneric< n_, m_ > &, const TensorGeneric< n_, m_ > &)
 return t1+t2 More...
 
template<unsigned n_, unsigned m_>
TensorGeneric< n_, m_ > operator* (double, const TensorGeneric< n_, m_ > &)
 scale the tensor by a factor s More...
 
template<unsigned n_, unsigned m_>
TensorGeneric< n_, m_ > operator* (const TensorGeneric< n_, m_ > &, double s)
 scale the tensor by a factor s More...
 
template<unsigned n_, unsigned m_>
TensorGeneric< n_, m_ > operator/ (const TensorGeneric< n_, m_ > &, double s)
 scale the tensor by a factor 1/s More...
 
template<unsigned n_, unsigned m_, unsigned l_>
TensorGeneric< n_, l_ > matmul (const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &)
 matrix-matrix multiplication More...
 
template<unsigned n_, unsigned m_>
VectorGeneric< n_ > matmul (const TensorGeneric< n_, m_ > &, const VectorGeneric< m_ > &)
 matrix-vector multiplication More...
 
template<unsigned n_, unsigned m_>
VectorGeneric< n_ > matmul (const VectorGeneric< m_ > &, const TensorGeneric< m_, n_ > &)
 vector-matrix multiplication More...
 
template<unsigned n_, unsigned m_, unsigned l_, unsigned i_>
TensorGeneric< n_, i_ > matmul (const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &, const TensorGeneric< l_, i_ > &)
 matrix-matrix-matrix multiplication More...
 
template<unsigned n_, unsigned m_, unsigned l_>
VectorGeneric< n_ > matmul (const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &, const VectorGeneric< l_ > &)
 matrix-matrix-vector multiplication More...
 
template<unsigned n_, unsigned m_, unsigned l_>
VectorGeneric< l_ > matmul (const VectorGeneric< n_ > &, const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &)
 vector-matrix-matrix multiplication More...
 
double determinant (const TensorGeneric< 3, 3 > &)
 returns the determinant of a tensor More...
 
TensorGeneric< 3, 3 > inverse (const TensorGeneric< 3, 3 > &)
 returns the inverse of a tensor (same as inverse()) More...
 
template<unsigned n_, unsigned m_>
TensorGeneric< n_, m_ > transpose (const TensorGeneric< m_, n_ > &)
 returns the transpose of a tensor (same as transpose()) More...
 
template<unsigned n_, unsigned m_>
TensorGeneric< n_, m_ > extProduct (const VectorGeneric< n > &, const VectorGeneric< m > &)
 returns the transpose of a tensor (same as TensorGeneric(const VectorGeneric&,const VectorGeneric&)) More...
 
TensorGeneric< 3, 3 > dcrossDv1 (const VectorGeneric< 3 > &, const VectorGeneric< 3 > &)
 
TensorGeneric< 3, 3 > dcrossDv2 (const VectorGeneric< 3 > &, const VectorGeneric< 3 > &)
 

Detailed Description

template<unsigned n, unsigned m>
class PLMD::TensorGeneric< n, m >

Class implementing fixed size matrices of doubles.

Template Parameters
nThe number rows
mThe number columns

This class implements a matrix of doubles with size fixed at compile time. It is useful for small fixed size objects (e.g. 3x3 tensors) as it does not waste space to store the vector size. Moreover, as the compiler knows the size, it can be completely opimized inline. Matrix elements are initialized to zero by default. Notice that this means that constructor is a bit slow. This point might change in future if we find performance issues. It takes advantage of MatrixSquareBracketsAccess to provide both () and [] syntax for access. Several functions are declared as friends even if not necessary so as to properly appear in Doxygen documentation.

Aliases are defined to simplify common declarations (Tensor, Tensor2d, Tensor3d, Tensor4d). Also notice that some operations are only available for 3x3 tensors.

Example of usage

#include "Tensor.h"

using namespace PLMD;

int main(){
  Tensor a;
  TensorGeneric<3,2> b;
  TensorGeneric<3,2> c=matmul(a,b);
  return 0;
}

Definition at line 70 of file Tensor.h.

Constructor & Destructor Documentation

template<unsigned n, unsigned m>
PLMD::TensorGeneric< n, m >::TensorGeneric ( )

initialize the tensor to zero

Definition at line 165 of file Tensor.h.

template<unsigned n, unsigned m>
PLMD::TensorGeneric< n, m >::TensorGeneric ( const VectorGeneric< n > &  v1,
const VectorGeneric< m > &  v2 
)

initialize a tensor as an external product of two Vector

Definition at line 170 of file Tensor.h.

template<unsigned n, unsigned m>
PLMD::TensorGeneric< n, m >::TensorGeneric ( double  ,
double  ,
double  ,
double   
)

initialize a tensor with 4 values, in standard C order

template<unsigned n, unsigned m>
PLMD::TensorGeneric< n, m >::TensorGeneric ( double  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double   
)

initialize a tensor with 9 values, in standard C order

template<>
PLMD::TensorGeneric< 2, 2 >::TensorGeneric ( double  d00,
double  d01,
double  d10,
double  d11 
)
inline

Definition at line 176 of file Tensor.h.

template<>
PLMD::TensorGeneric< 3, 3 >::TensorGeneric ( double  d00,
double  d01,
double  d02,
double  d10,
double  d11,
double  d12,
double  d20,
double  d21,
double  d22 
)
inline

Definition at line 185 of file Tensor.h.

Member Function Documentation

template<unsigned n, unsigned m>
double PLMD::TensorGeneric< n, m >::determinant ( ) const

returns the determinant

template<>
double PLMD::TensorGeneric< 3, 3 >::determinant ( ) const
inline

Definition at line 306 of file Tensor.h.

template<unsigned n, unsigned m>
VectorGeneric< n > PLMD::TensorGeneric< n, m >::getCol ( unsigned  j) const

get j-th column

Definition at line 260 of file Tensor.h.

template<unsigned n, unsigned m>
VectorGeneric< m > PLMD::TensorGeneric< n, m >::getRow ( unsigned  i) const

get i-th row

Definition at line 267 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, n > PLMD::TensorGeneric< n, m >::identity ( )
inlinestatic

return an identity tensor

Definition at line 318 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric PLMD::TensorGeneric< n, m >::inverse ( ) const

return the matrix inverse

template<>
TensorGeneric< 3, 3 > PLMD::TensorGeneric< 3, 3 >::inverse ( ) const
inline

Definition at line 333 of file Tensor.h.

template<unsigned n, unsigned m>
double & PLMD::TensorGeneric< n, m >::operator() ( unsigned  i,
unsigned  j 
)

access element

Definition at line 203 of file Tensor.h.

template<unsigned n, unsigned m>
const double & PLMD::TensorGeneric< n, m >::operator() ( unsigned  i,
unsigned  j 
) const

access element

Definition at line 208 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator*= ( double  s)

multiply

Definition at line 225 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, m > PLMD::TensorGeneric< n, m >::operator+ ( ) const

return +t

Definition at line 236 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator+= ( const TensorGeneric< n, m > &  b)

increment

Definition at line 213 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, m > PLMD::TensorGeneric< n, m >::operator- ( ) const

return -t

Definition at line 241 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator-= ( const TensorGeneric< n, m > &  b)

decrement

Definition at line 219 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator/= ( double  s)

divide

Definition at line 231 of file Tensor.h.

Row PLMD::MatrixSquareBracketsAccess< TensorGeneric< n, m > , double , I, J >::operator[] ( i)
inherited

access element (with [][] syntax)

Const_row PLMD::MatrixSquareBracketsAccess< TensorGeneric< n, m > , double , I, J >::operator[] ( i) const
inherited

access element (with [][] syntax)

template<unsigned n, unsigned m>
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::setCol ( unsigned  j,
const VectorGeneric< n > &  c 
)

set j-th column

Definition at line 248 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::setRow ( unsigned  i,
const VectorGeneric< m > &  r 
)

set i-th row

Definition at line 254 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric< m, n > PLMD::TensorGeneric< n, m >::transpose ( ) const

return the transpose matrix

Definition at line 325 of file Tensor.h.

template<unsigned n, unsigned m>
void PLMD::TensorGeneric< n, m >::zero ( )

set it to zero

Definition at line 198 of file Tensor.h.

Friends And Related Function Documentation

template<unsigned n, unsigned m>
TensorGeneric<3,3> dcrossDv1 ( const VectorGeneric< 3 > &  v1,
const VectorGeneric< 3 > &  v2 
)
friend

Definition at line 401 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric<3,3> dcrossDv2 ( const VectorGeneric< 3 > &  v1,
const VectorGeneric< 3 > &  v2 
)
friend

Definition at line 410 of file Tensor.h.

template<unsigned n, unsigned m>
double determinant ( const TensorGeneric< 3, 3 > &  t)
friend

returns the determinant of a tensor

Definition at line 381 of file Tensor.h.

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
TensorGeneric<n_,m_> extProduct ( const VectorGeneric< n > &  v1,
const VectorGeneric< m > &  v2 
)
friend

returns the transpose of a tensor (same as TensorGeneric(const VectorGeneric&,const VectorGeneric&))

Definition at line 396 of file Tensor.h.

template<unsigned n, unsigned m>
TensorGeneric<3,3> inverse ( const TensorGeneric< 3, 3 > &  t)
friend

returns the inverse of a tensor (same as inverse())

Definition at line 386 of file Tensor.h.

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_, unsigned l_>
TensorGeneric<n_,l_> matmul ( const TensorGeneric< n_, m_ > &  ,
const TensorGeneric< m_, l_ > &   
)
friend

matrix-matrix multiplication

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
VectorGeneric<n_> matmul ( const TensorGeneric< n_, m_ > &  ,
const VectorGeneric< m_ > &   
)
friend

matrix-vector multiplication

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
VectorGeneric<n_> matmul ( const VectorGeneric< m_ > &  ,
const TensorGeneric< m_, n_ > &   
)
friend

vector-matrix multiplication

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_, unsigned l_, unsigned i_>
TensorGeneric<n_,i_> matmul ( const TensorGeneric< n_, m_ > &  ,
const TensorGeneric< m_, l_ > &  ,
const TensorGeneric< l_, i_ > &   
)
friend

matrix-matrix-matrix multiplication

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_, unsigned l_>
VectorGeneric<n_> matmul ( const TensorGeneric< n_, m_ > &  ,
const TensorGeneric< m_, l_ > &  ,
const VectorGeneric< l_ > &   
)
friend

matrix-matrix-vector multiplication

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_, unsigned l_>
VectorGeneric<l_> matmul ( const VectorGeneric< n_ > &  ,
const TensorGeneric< n_, m_ > &  ,
const TensorGeneric< m_, l_ > &   
)
friend

vector-matrix-matrix multiplication

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
TensorGeneric<n_,m_> operator* ( double  ,
const TensorGeneric< n_, m_ > &   
)
friend

scale the tensor by a factor s

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
TensorGeneric<n_,m_> operator* ( const TensorGeneric< n_, m_ > &  ,
double  s 
)
friend

scale the tensor by a factor s

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
TensorGeneric<n_,m_> operator+ ( const TensorGeneric< n_, m_ > &  ,
const TensorGeneric< n_, m_ > &   
)
friend

return t1+t2

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
TensorGeneric<n_,m_> operator- ( const TensorGeneric< n_, m_ > &  ,
const TensorGeneric< n_, m_ > &   
)
friend

return t1+t2

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
TensorGeneric<n_,m_> operator/ ( const TensorGeneric< n_, m_ > &  ,
double  s 
)
friend

scale the tensor by a factor 1/s

template<unsigned n, unsigned m>
template<unsigned n_, unsigned m_>
TensorGeneric<n_,m_> transpose ( const TensorGeneric< m_, n_ > &  )
friend

returns the transpose of a tensor (same as transpose())

Member Data Documentation

template<unsigned n, unsigned m>
double PLMD::TensorGeneric< n, m >::d[n *m]
private

Definition at line 73 of file Tensor.h.


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