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 
11 
12 namespace cadabra {
13 
14  class NTensor {
15  public:
21  NTensor(const std::vector<size_t>& shape, double val);
22 
24  NTensor(const std::vector<double>& vals);
25 
27  NTensor(double);
28 
30  NTensor(const NTensor&);
31 
33  static NTensor linspace(double from, double to, size_t steps);
34 
36  NTensor& operator=(const NTensor&);
37 
39  NTensor& operator+=(const NTensor&);
40 
42  NTensor& operator*=(const NTensor&);
43 
45  NTensor& pow(const NTensor&);
46 
48  double at(const std::vector<size_t>& indices) const;
49 
51  double& at(const std::vector<size_t>& indices);
52 
64 
65  NTensor broadcast(std::vector<size_t> new_shape, size_t pos) const;
66 
73 
74  static NTensor outer_product(const NTensor& a, const NTensor& b);
75 
78  NTensor& apply(double (*fun)(double));
79 
80  friend std::ostream& operator<<(std::ostream&, const NTensor&);
81 
82  std::vector<size_t> shape;
83  std::vector<double> values;
84  };
85 
86  std::ostream& operator<<(std::ostream &, const NTensor &);
87 
88 }
cadabra::NTensor::operator+=
NTensor & operator+=(const NTensor &)
Addition operator. This requires the shapes to match.
Definition: NTensor.cc:141
cadabra::NTensor::shape
std::vector< size_t > shape
Definition: NTensor.hh:82
cadabra::NTensor::operator<<
friend std::ostream & operator<<(std::ostream &, const NTensor &)
Definition: NTensor.cc:99
cadabra::NTensor::at
double at(const std::vector< size_t > &indices) const
Get the value of the tensor at the indicated component.
Definition: NTensor.cc:57
cadabra::NTensor::pow
NTensor & pow(const NTensor &)
Element-wise pow operator (self**b, or pow(self,b)). Requires the shapes to match.
Definition: NTensor.cc:201
cadabra::NTensor::outer_product
static NTensor outer_product(const NTensor &a, const NTensor &b)
Outer product of two NTensors.
Definition: NTensor.cc:226
cadabra::NTensor::values
std::vector< double > values
Definition: NTensor.hh:83
cadabra::NTensor
Definition: NTensor.hh:14
cadabra::NTensor::apply
NTensor & apply(double(*fun)(double))
Apply a scalar function fun to all elements, return a reference to itself.
Definition: NTensor.cc:133
cadabra::NTensor::broadcast
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:248
cadabra::operator<<
std::ostream & operator<<(std::ostream &, const NTensor &)
Definition: NTensor.cc:99
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
cadabra::NTensor::linspace
static NTensor linspace(double from, double to, size_t steps)
Create equally spaced values in a range.
Definition: NTensor.cc:39
cadabra::NTensor::operator*=
NTensor & operator*=(const NTensor &)
Element-wise multiplication operator. This requires the shapes to match.
Definition: NTensor.cc:171
fun
void fun(int *&p)
Definition: passing.cc:6
cadabra::NTensor::operator=
NTensor & operator=(const NTensor &)
Assignment operator.
Definition: NTensor.cc:50
cadabra::NTensor::NTensor
NTensor(const std::vector< size_t > &shape, double val)
Initialise by giving the dimension for each index.
Definition: NTensor.cc:9