26 namespace MD = MultiDimensional;
28 Tensor::Tensor() : _name{
"Tensor"},
39 Tensor::Tensor(
const std::string& name, std::vector<std::pair<MultiDimensional::SharedTensorData, bool>>&& data) : _name{name} {
44 : _name{other.
_name}, _data{other._data->clone()} {
58 _name = move(other._name);
59 _data = move(other._data);
68 return _data->element(indices);
84 return _data->labels();
115 if (other.
rank() == 0) {
120 complex<double> val =
element();
126 if (indices.size() == 0) {
128 tmpIndices.insert(labs.begin(), labs.end());
131 tmpIndices.insert(indices.begin(), indices.end());
134 if (positions.size() > 0) {
149 if(positions.size() > 0) {
156 size_t oldDim =
_data->numValues();
158 size_t newDim =
_data->numValues();
159 return operator*=((static_cast<double>(newDim))/(static_cast<double>(oldDim)));
177 _data->operator*=(val);
182 _data->operator*=(val);
198 throw Error(
"Tensor rank/sizes do not match. Whose gonna do it you, you Lieutenant Weinberg? I have a greater responsibility than you can possibly fathom.");
212 throw Error(
"Tensor rank/sizes do not match");
226 throw Error(
"Tensor rank/sizes do not match. Whose gonna do it you, you Lieutenant Weinberg? I have a greater responsibility than you can possibly fathom.");
234 auto serialname = msgwriter->CreateString(
_name);
236 auto serialvalue =
_data->write(msgwriter);
237 Serial::FBTensorBuilder serialTensor{*msgwriter};
238 serialTensor.add_name(serialname);
239 serialTensor.add_data_type(serialvalue.second);
240 serialTensor.add_data(serialvalue.first);
241 *msg = serialTensor.Finish();
246 if (msgreader !=
nullptr) {
270 result.
dot(second, indices);
TensorData toVector(TensorData origin)
Tensor elementDivide(const Tensor &first, const Tensor &second)
divides two tensors of the same rank and same dimensions element by element
Tensor & outerSquare()
creates a tensor with twice the rank by multiplying the tensor with its hermitean conjugate ...
Tensor & spinSum()
trace some of the indices of this tensor
Log & getLog() const
logging facility
std::complex< double > & element(const IndexList &indices={})
access an element given its indices
Tensor & spinAverage()
trace over the traceable spin indices and divide by the product of the dimensions of the traced indic...
Tensor & toVector()
forces conversion of a tensor to vector type
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 ...
Tensor & operator+=(const Tensor &other)
sums another tensor to itself
TensorData read(const Serial::FBTensor *msgreader)
std::vector< IndexPair > IndexPairList
LabelsList labels() const
get the labels of all the indices at once
const std::string & name() const
get the tensor name
Tensor outerSquare(const Tensor &first)
creates a tensor with twice the rank by multiplying the tensor with it's hermitean conjugate ...
TensorData calcTrace(TensorData origin, const IndexPairList &indices)
void write(flatbuffers::FlatBufferBuilder *msgwriter, flatbuffers::Offset< Serial::FBTensor > *msg) const
write the contents of the tensor for serialization
Tensor elementMultiply(const Tensor &first, const Tensor &second)
multiplies two tensors of the same rank and same dimensions element by element
bool hasFFLabels() const
checks if Tensor has indices in the FF range
TensorData calcDot(TensorData origin, const IContainer &other, const IndexPairList &indices)
std::unique_ptr< IContainer > TensorData
size_t rank() const
rank of the tensor
static Log & getLog(const std::string &name)
Get a logger with the given name.
Tensor spinSum(const Tensor &first)
trace a tensor
Tensor & operator*=(double val)
multiply all the elements of the tensor by a real number
(Sum of) Outer product tensor data container
Hammer exception definitions.
Interface class for tensor container data structure.
MultiDimensional::TensorData _data
std::vector< IndexType > IndexList
Order-0 tensor data container.
Invalid index label error class.
TensorData calcSquare(TensorData origin)
IndexLabel
label identifiers of tensor indices they are used to determine which indices can be contracted togeth...
Multidimensional tensor class with complex numbers as elements.
bool isEqualTo(const Tensor &other) const
Tensor operator*(const Tensor &first, double val)
left multiplies a tensor by a real constant
void clearData()
sets all the elements to 0
TensorData elementMultiply(TensorData origin, const IContainer &other)
std::string _name
the tensor name
TensorData combineSharedTensors(std::vector< std::pair< SharedTensorData, bool >> &&data)
TensorData makeEmptyScalar()
TensorData addAt(TensorData origin, const IContainer &other, IndexType index, IndexType position)
std::vector< IndexLabel > LabelsList
std::set< IndexLabel > UniqueLabelsList
Tensor & elementDivideBy(const Tensor &other)
divide two tensors element by element and stores the result in this tensor
Tensor spinAverage(const Tensor &first)
trace a tensor over the traceable spin indices and divide by the product of the dimensions of the tra...
Tensor & dot(const Tensor &other, const UniqueLabelsList &indices={})
contract this tensor with another and stores the result in this tensor
TensorData reOptimize(TensorData origin)
IndexList dims() const
get the dimensions of all the indices at once
Tensor & elementMultiplyBy(const Tensor &other)
multiply two tensors element by element and stores the result in this tensor
void read(const Serial::FBTensor *msgreader)
read the contents of the tensor for serialization
TensorData elementDivide(TensorData origin, const IContainer &other)
TensorData sum(TensorData origin, const IContainer &other)
Histogram operator+(const Histogram &first, const Histogram &second)
Serialization related typedefs and includes.
bool hasFFVarLabels() const
checks if Tensor has indices in the FF Var range
Tensor & operator=(const Tensor &other)
bool hasWCLabels() const
checks if Tensor has indices in the WC range
Tensor dot(const Tensor &first, const Tensor &second, const set< IndexLabel > &indices)