Cadabra
Computer algebra system for field theory problems

#include <NTensor.hh>
Public Member Functions  
NTensor (const std::vector< size_t > &shape, double val)  
Initialise by giving the dimension for each index. More...  
NTensor (const std::vector< double > &vals)  
Initialise as a vector of doubles; sets shape automatically. More...  
NTensor (double)  
Initialise as a scalar; sets shape automatically. More...  
NTensor (const NTensor &)  
Copy constructor. More...  
NTensor &  operator= (const NTensor &) 
Assignment operator. More...  
NTensor &  operator+= (const NTensor &) 
Addition operator. This requires the shapes to match. More...  
NTensor &  operator*= (const NTensor &) 
Elementwise multiplication operator. This requires the shapes to match. More...  
NTensor &  pow (const NTensor &) 
Elementwise pow operator (self**b, or pow(self,b)). Requires the shapes to match. More...  
double  at (const std::vector< size_t > &indices) const 
Get the value of the tensor at the indicated component. More...  
double &  at (const std::vector< size_t > &indices) 
Get the value of the tensor at the indicated component. More...  
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. More...  
NTensor &  apply (double(*fun)(double)) 
Apply a scalar function fun to all elements, return a reference to itself. More...  
Static Public Member Functions  
static NTensor  linspace (double from, double to, size_t steps) 
Create equally spaced values in a range. More...  
static NTensor  outer_product (const NTensor &a, const NTensor &b) 
Outer product of two NTensors. More...  
Public Attributes  
std::vector< size_t >  shape 
std::vector< double >  values 
Friends  
std::ostream &  operator<< (std::ostream &, const NTensor &) 
NTensor::NTensor  (  const std::vector< size_t > &  shape, 
double  val  
) 
Initialise by giving the dimension for each index.
Storage is generalised rowmajor. Dispay follows that convention: we use maths matrix conventions for printing, that is, earlier indices are more major, and are iterated over in a more outer loop.
NTensor::NTensor  (  const std::vector< double > &  vals  ) 
Initialise as a vector of doubles; sets shape automatically.
NTensor::NTensor  (  double  val  ) 
Initialise as a scalar; sets shape automatically.
NTensor::NTensor  (  const NTensor &  other  ) 
Copy constructor.
NTensor & NTensor::apply  (  double(*)(double)  fun  ) 
Apply a scalar function fun
to all elements, return a reference to itself.
double & NTensor::at  (  const std::vector< size_t > &  indices  ) 
Get the value of the tensor at the indicated component.
double NTensor::at  (  const std::vector< size_t > &  indices  )  const 
Get the value of the tensor at the indicated component.
NTensor 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.
Effectively,
A_{i} > A_{k i l}
shape {2} tensor [3,4] to shape {4,2} pos 1:
> [[3,4], [3,4]]
For now only works if the original shape is onedimensional, that is, a vector (as above).

static 
Create equally spaced values in a range.
Elementwise multiplication operator. This requires the shapes to match.
Addition operator. This requires the shapes to match.
Outer product of two NTensors.
The shape becomes the concatenation of the two shapes, with the shape of a
coming first.
a b { 3 } x { 4 } > { 3, 4}.
Elementwise pow operator (self**b, or pow(self,b)). Requires the shapes to match.

friend 
std::vector<size_t> cadabra::NTensor::shape 
std::vector<double> cadabra::NTensor::values 