 Cadabra Computer algebra system for field theory problems
NTensor.hh
Go to the documentation of this file.
1
2 #pragma once
3
4 #include <vector>
5 #include <iostream>
6
9
10 class NTensor {
11  public:
17  NTensor(const std::vector<size_t>& shape, double val);
18
20  NTensor(const std::vector<double>& vals);
21
23  NTensor(double);
24
26  NTensor(const NTensor&);
27
29  static NTensor linspace(double from, double to, size_t steps);
30
32  NTensor& operator=(const NTensor&);
33
35  NTensor& operator+=(const NTensor&);
36
38  NTensor& operator*=(const NTensor&);
39
41  double at(const std::vector<size_t>& indices) const;
42
44  double& at(const std::vector<size_t>& indices);
45
57
58  NTensor broadcast(std::vector<size_t> new_shape, size_t pos) const;
59
66
67  static NTensor outer_product(const NTensor& a, const NTensor& b);
68
71  NTensor& apply(double (*fun)(double));
72
73  friend std::ostream& operator<<(std::ostream&, const NTensor&);
74
75  std::vector<size_t> shape;
76  std::vector<double> values;
77 };
78
79 std::ostream& operator<<(std::ostream &, const NTensor &);
NTensor::shape
std::vector< size_t > shape
Definition: NTensor.hh:75
NTensor::linspace
static NTensor linspace(double from, double to, size_t steps)
Create equally spaced values in a range.
Definition: NTensor.cc:36
NTensor broadcast(std::vector< size_t > new_shape, size_t pos) const
Expand the shape of the tensor to the specified shape by broadcasting to the other dimensions.
Definition: NTensor.cc:184
NTensor::operator<<
friend std::ostream & operator<<(std::ostream &, const NTensor &)
Definition: NTensor.cc:96
NTensor::apply
NTensor & apply(double(*fun)(double))
Apply a scalar function fun to all elements, return a reference to itself.
Definition: NTensor.cc:130
NTensor::at
double at(const std::vector< size_t > &indices) const
Get the value of the tensor at the indicated component.
Definition: NTensor.cc:54
operator<<
std::ostream & operator<<(std::ostream &, const NTensor &)
Definition: NTensor.cc:96
NTensor::operator+=
NTensor & operator+=(const NTensor &)
Addition operator. This requires the shapes to match.
Definition: NTensor.cc:138
NTensor::outer_product
static NTensor outer_product(const NTensor &a, const NTensor &b)
Outer product of two NTensors.
Definition: NTensor.cc:162
NTensor::operator=
NTensor & operator=(const NTensor &)
Assignment operator.
Definition: NTensor.cc:47
NTensor::NTensor
NTensor(const std::vector< size_t > &shape, double val)
Initialise by giving the dimension for each index.
Definition: NTensor.cc:6
fun
void fun(int *&p)
Definition: passing.cc:6
NTensor
Class to hold numerical values structured in tensor form, that is, a multi-dimensional array.
Definition: NTensor.hh:10
NTensor::operator*=
NTensor & operator*=(const NTensor &)
Element-wise multiplication operator. This requires the shapes to match.
Definition: NTensor.cc:150
NTensor::values
std::vector< double > values
Definition: NTensor.hh:76