Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Hammer::Tensor Class Reference

Multidimensional tensor class with complex numbers as elements. More...

#include <Tensor.hh>

+ Collaboration diagram for Hammer::Tensor:

Public Member Functions

 Tensor ()
 
 Tensor (const std::string &name)
 
 Tensor (const std::string &name, MultiDimensional::TensorData container)
 
 Tensor (const std::string &name, std::vector< std::pair< MultiDimensional::SharedTensorData, bool >> &&data)
 
 Tensor (const Tensor &other)
 
Tensoroperator= (const Tensor &other)
 
 Tensor (Tensor &&other)
 
Tensoroperator= (Tensor &&other)
 
 ~Tensor ()
 
template<typename... Args>
void setValue (std::complex< double > value, Args...rest)
 set the value of a specific tensor element More...
 
template<typename... Args>
std::complex< double > value (Args...rest) const
 returns the value of a specific tensor element More...
 
std::complex< double > & element (const IndexList &indices={})
 access an element given its indices More...
 
std::complex< double > element (const IndexList &indices={}) const
 access an element given its indices (const version) More...
 
size_t rank () const
 rank of the tensor More...
 
IndexList dims () const
 get the dimensions of all the indices at once More...
 
LabelsList labels () const
 get the labels of all the indices at once More...
 
bool hasWCLabels () const
 checks if Tensor has indices in the WC range More...
 
bool hasFFLabels () const
 checks if Tensor has indices in the FF range More...
 
bool hasFFVarLabels () const
 checks if Tensor has indices in the FF Var range More...
 
const std::string & name () const
 get the tensor name More...
 
bool isEqualTo (const Tensor &other) const
 
Tensordot (const Tensor &other, const UniqueLabelsList &indices={})
 contract this tensor with another and stores the result in this tensor More...
 
TensorspinSum ()
 trace some of the indices of this tensor More...
 
TensorspinAverage ()
 trace over the traceable spin indices and divide by the product of the dimensions of the traced indices (equal to \( 2s_i + 1 \)) More...
 
TensorouterSquare ()
 creates a tensor with twice the rank by multiplying the tensor with its hermitean conjugate More...
 
TensortoVector ()
 forces conversion of a tensor to vector type More...
 
Tensoroperator*= (double val)
 multiply all the elements of the tensor by a real number More...
 
Tensoroperator*= (std::complex< double > val)
 multiply all the elements of the tensor by a complex number More...
 
Tensoroperator+= (const Tensor &other)
 sums another tensor to itself More...
 
TensorelementMultiplyBy (const Tensor &other)
 multiply two tensors element by element and stores the result in this tensor More...
 
TensorelementDivideBy (const Tensor &other)
 divide two tensors element by element and stores the result in this tensor More...
 
TensoraddAt (const Tensor &t, IndexLabel coord, IndexType position)
 add a tensor of rank N-1 to a specific position in a specific coordinate the dimension of the tensor should match those of this tensor in all the other dimensions More...
 
void clearData ()
 sets all the elements to 0 More...
 
void write (flatbuffers::FlatBufferBuilder *msgwriter, flatbuffers::Offset< Serial::FBTensor > *msg) const
 write the contents of the tensor for serialization More...
 
void read (const Serial::FBTensor *msgreader)
 read the contents of the tensor for serialization More...
 

Protected Member Functions

LoggetLog () const
 logging facility More...
 

Private Attributes

std::string _name
 the tensor name More...
 
MultiDimensional::TensorData _data
 

Detailed Description

Multidimensional tensor class with complex numbers as elements.

Contains a complex tensor flattened to a vector as raw-major

Definition at line 33 of file Tensor.hh.

Constructor & Destructor Documentation

Hammer::Tensor::Tensor ( )

Definition at line 28 of file Tensor.cc.

Hammer::Tensor::Tensor ( const std::string &  name)

Definition at line 32 of file Tensor.cc.

Hammer::Tensor::Tensor ( const std::string &  name,
MultiDimensional::TensorData  container 
)

Definition at line 36 of file Tensor.cc.

Hammer::Tensor::Tensor ( const std::string &  name,
std::vector< std::pair< MultiDimensional::SharedTensorData, bool >> &&  data 
)

Definition at line 39 of file Tensor.cc.

Hammer::Tensor::Tensor ( const Tensor other)

Definition at line 43 of file Tensor.cc.

Hammer::Tensor::Tensor ( Tensor &&  other)

Definition at line 53 of file Tensor.cc.

Hammer::Tensor::~Tensor ( )

Definition at line 63 of file Tensor.cc.

Member Function Documentation

Tensor & Hammer::Tensor::addAt ( const Tensor t,
IndexLabel  coord,
IndexType  position 
)

add a tensor of rank N-1 to a specific position in a specific coordinate the dimension of the tensor should match those of this tensor in all the other dimensions

Parameters
[in]tthe other tensor
[in]coordthe cooridnate, identified by its label. If multiple dimensions have the same label, the first one is considered.
[in]positionthe position along the dimension
Returns
a reference to itself. Throws if the dimensions of the two tensors are incompatible

Definition at line 259 of file Tensor.cc.

void Hammer::Tensor::clearData ( )

sets all the elements to 0

Definition at line 229 of file Tensor.cc.

IndexList Hammer::Tensor::dims ( ) const

get the dimensions of all the indices at once

Returns
the list of dimensions

Definition at line 79 of file Tensor.cc.

Tensor & Hammer::Tensor::dot ( const Tensor other,
const UniqueLabelsList indices = {} 
)

contract this tensor with another and stores the result in this tensor

Parameters
[in]otherthe othe tensor
[in]indicesrestrict the indices to be contracted, identified by labels. If no labels are passed all the contractable indices are contracted. If a set of labels is passed, the indices to be contracted will be the intersection between the provided set and the set of contractable labels
Returns
a reference to itself

Definition at line 114 of file Tensor.cc.

complex< double > & Hammer::Tensor::element ( const IndexList indices = {})

access an element given its indices

Parameters
[in]indicesthe list of indices, 0-based
Returns
a reference to the element

Definition at line 67 of file Tensor.cc.

complex< double > Hammer::Tensor::element ( const IndexList indices = {}) const

access an element given its indices (const version)

Parameters
[in]indicesthe list of indices, 0-based
Returns
a reference to the element

Definition at line 71 of file Tensor.cc.

Tensor & Hammer::Tensor::elementDivideBy ( const Tensor other)

divide two tensors element by element and stores the result in this tensor

Parameters
[in]otherthe other tensor
Returns
a reference to itself. Throws if tensors have different shapes or if a division by zero is encountered

Definition at line 215 of file Tensor.cc.

Tensor & Hammer::Tensor::elementMultiplyBy ( const Tensor other)

multiply two tensors element by element and stores the result in this tensor

Parameters
[in]otherthe other tensor
Returns
a reference to itself. Throws if tensors have different shapes

Definition at line 201 of file Tensor.cc.

Log & Hammer::Tensor::getLog ( ) const
protected

logging facility

Returns
stream to be used for logging

Definition at line 110 of file Tensor.cc.

bool Hammer::Tensor::hasFFLabels ( ) const

checks if Tensor has indices in the FF range

Returns
bool

Definition at line 92 of file Tensor.cc.

bool Hammer::Tensor::hasFFVarLabels ( ) const

checks if Tensor has indices in the FF Var range

Returns
bool

Definition at line 97 of file Tensor.cc.

bool Hammer::Tensor::hasWCLabels ( ) const

checks if Tensor has indices in the WC range

Returns
bool

Definition at line 87 of file Tensor.cc.

bool Hammer::Tensor::isEqualTo ( const Tensor other) const

Definition at line 106 of file Tensor.cc.

LabelsList Hammer::Tensor::labels ( ) const

get the labels of all the indices at once

Returns
the list of labels

Definition at line 83 of file Tensor.cc.

const string & Hammer::Tensor::name ( ) const

get the tensor name

Returns
the name

Definition at line 102 of file Tensor.cc.

Tensor & Hammer::Tensor::operator*= ( double  val)

multiply all the elements of the tensor by a real number

Parameters
[in]valthe value
Returns
a reference to itself

Definition at line 176 of file Tensor.cc.

Tensor & Hammer::Tensor::operator*= ( std::complex< double >  val)

multiply all the elements of the tensor by a complex number

Parameters
[in]valthe value
Returns
a reference to itself

Definition at line 181 of file Tensor.cc.

Tensor & Hammer::Tensor::operator+= ( const Tensor other)

sums another tensor to itself

Parameters
[in]otherthe other tensor
Returns
a reference to itself. Throws if tensors have different shapes

Definition at line 187 of file Tensor.cc.

Tensor & Hammer::Tensor::operator= ( const Tensor other)

Definition at line 47 of file Tensor.cc.

Tensor & Hammer::Tensor::operator= ( Tensor &&  other)

Definition at line 57 of file Tensor.cc.

Tensor & Hammer::Tensor::outerSquare ( )

creates a tensor with twice the rank by multiplying the tensor with its hermitean conjugate

Returns
a reference to itself

Definition at line 162 of file Tensor.cc.

size_t Hammer::Tensor::rank ( ) const

rank of the tensor

Returns
the number of components

Definition at line 75 of file Tensor.cc.

void Hammer::Tensor::read ( const Serial::FBTensor *  msgreader)

read the contents of the tensor for serialization

Parameters
[in]msgreaderthe reader object

Definition at line 245 of file Tensor.cc.

template<typename... Args>
void Hammer::Tensor::setValue ( std::complex< double >  value,
Args...  rest 
)

set the value of a specific tensor element

Parameters
[in]valuethe value
[in]restthe rest of the indices (0-based)

Definition at line 22 of file TensorDefs.hh.

Tensor & Hammer::Tensor::spinAverage ( )

trace over the traceable spin indices and divide by the product of the dimensions of the traced indices (equal to \( 2s_i + 1 \))

Returns
a reference to itself

Definition at line 155 of file Tensor.cc.

Tensor & Hammer::Tensor::spinSum ( )

trace some of the indices of this tensor

Returns
a reference to itself

Definition at line 144 of file Tensor.cc.

Tensor & Hammer::Tensor::toVector ( )

forces conversion of a tensor to vector type

Returns
a reference to itself

Definition at line 171 of file Tensor.cc.

template<typename... Args>
std::complex< double > Hammer::Tensor::value ( Args...  rest) const

returns the value of a specific tensor element

Parameters
[in]restthe rest of the indices (0-based)
Returns
the element value

Definition at line 31 of file TensorDefs.hh.

void Hammer::Tensor::write ( flatbuffers::FlatBufferBuilder *  msgwriter,
flatbuffers::Offset< Serial::FBTensor > *  msg 
) const

write the contents of the tensor for serialization

Parameters
[in]msgwriterthe writer object
[in]msgthe location where to write

Definition at line 233 of file Tensor.cc.

Member Data Documentation

MultiDimensional::TensorData Hammer::Tensor::_data
mutableprivate

Definition at line 196 of file Tensor.hh.

std::string Hammer::Tensor::_name
private

the tensor name

Definition at line 195 of file Tensor.hh.


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