![]() |
Cadabra
Computer algebra system for field theory problems
|
#include <NTensor.hh>
Public Member Functions | |
NTensor (const std::vector< size_t > &shape, std::complex< double > val) | |
Initialise by giving the dimension for each index. | |
NTensor (const std::vector< std::complex< double > > &vals) | |
Initialise as a vector of std::complex<double>s; sets shape automatically. | |
NTensor (const std::vector< double > &vals) | |
As above, but with doubles instead of complex doubles. | |
NTensor (std::initializer_list< std::complex< double > > vals) | |
Helper functions to be able to initialise a tensor with an initialiser list. | |
NTensor (std::initializer_list< double > vals) | |
NTensor (std::complex< double >) | |
Initialise as a scalar; sets shape automatically. | |
NTensor (double) | |
NTensor (const NTensor &) | |
Copy constructor. | |
NTensor (NTensor &&) | |
Move constructor. | |
NTensor & | operator= (const NTensor &) |
Assignment operator. | |
NTensor & | operator= (NTensor &&) noexcept |
Move assignment operators. | |
NTensor & | operator= (const NTensor &&) noexcept |
NTensor & | operator+= (const NTensor &) |
Addition operator. This requires the shapes to match. | |
NTensor & | operator*= (const NTensor &) |
Element-wise multiplication operator. This requires the shapes to match. | |
NTensor & | operator*= (const std::complex< double > &) |
Multiplyall elements with a scalar. | |
NTensor & | operator*= (double) |
NTensor & | pow (const NTensor &) |
Element-wise pow operator (self**b, or pow(self,b)). Requires the shapes to match. | |
std::complex< double > | at () const |
Get the value of a scalar NTensor. | |
std::complex< double > | at (const std::vector< size_t > &indices) const |
Get the value of the tensor at the indicated component. | |
std::complex< double > & | at (const std::vector< size_t > &indices) |
Get the value of the tensor at the indicated component. | |
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. | |
NTensor & | apply (std::complex< double >(*fun)(const std::complex< double > &)) |
Apply a scalar function fun to all elements, return a reference to itself. | |
bool | is_real () const |
Test if all values of the tensor are real. | |
bool | is_scalar () const |
Test if the shape is a single element equal to 1 (so the tensor is actually a scalar). | |
Static Public Member Functions | |
static NTensor | linspace (std::complex< double > from, std::complex< double > to, size_t steps) |
Create equally spaced values in a range. | |
static NTensor | outer_product (const NTensor &a, const NTensor &b) |
Outer product of two NTensors. | |
Public Attributes | |
std::vector< size_t > | shape |
std::vector< std::complex< double > > | values |
Friends | |
std::ostream & | operator<< (std::ostream &, const NTensor &) |
Initialise by giving the dimension for each index.
Storage is generalised row-major. Display 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.
Initialise as a vector of std::complex<double>s; sets shape automatically.
As above, but with doubles instead of complex doubles.
NTensor::NTensor | ( | std::initializer_list< std::complex< double > > | vals | ) |
Helper functions to be able to initialise a tensor with an initialiser list.
NTensor::NTensor | ( | std::initializer_list< double > | vals | ) |
|
explicit |
Initialise as a scalar; sets shape automatically.
|
explicit |
NTensor::NTensor | ( | NTensor && | other | ) |
Move constructor.
Apply a scalar function fun
to all elements, return a reference to itself.
Get the value of the tensor at the indicated component.
Get the value of the tensor at the indicated component.
Expand the shape of the tensor to the specified shape by broadcasting to the other dimensions.
Effectively,
A_{i} -> A_{k i l}
E.g. shape {2} tensor [3,4] (vector) to shape {4,2} (two-tensor) pos 1:
-> [[3,4], [3,4]]
So no matter the value of the new indices, the component is always determined by the value of the pos
index (i
above).
For now only works if the original shape size is 1, so that the tensor is rank one, `that is, a vector (as in the example above).
bool NTensor::is_real | ( | ) | const |
Test if all values of the tensor are real.
bool NTensor::is_scalar | ( | ) | const |
Test if the shape is a single element equal to 1 (so the tensor is actually a scalar).
|
static |
Create equally spaced values in a range.
Element-wise multiplication operator. This requires the shapes to match.
Multiplyall elements with a scalar.
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}.
Element-wise pow operator (self**b, or pow(self,b)). Requires the shapes to match.
std::vector<size_t> cadabra::NTensor::shape |
std::vector<std::complex<double> > cadabra::NTensor::values |