![]() |
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. |
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 &) |
|
explicit |
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.
|
explicit |
Initialise as a vector of std::complex<double>s; sets shape automatically.
|
explicit |
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 |
|
explicit |
Copy constructor.
NTensor::NTensor | ( | NTensor && | other | ) |
Move constructor.
NTensor & NTensor::apply | ( | std::complex< double >(* | fun )(const std::complex< double > &) | ) |
Apply a scalar function fun to all elements, return a reference to itself.
std::complex< double > NTensor::at | ( | ) | const |
Get the value of a scalar NTensor.
std::complex< double > & NTensor::at | ( | const std::vector< size_t > & | indices | ) |
Get the value of the tensor at the indicated component.
std::complex< 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 one-dimensional, that is, a vector (as above).
bool NTensor::is_real | ( | ) | const |
Test if all values of the tensor are real.
|
static |
Create equally spaced values in a range.
Element-wise multiplication operator. This requires the shapes to match.
NTensor & NTensor::operator*= | ( | const std::complex< double > & | m | ) |
Multiplyall elements with a scalar.
NTensor & NTensor::operator*= | ( | double | m | ) |
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.
|
friend |
std::vector<size_t> cadabra::NTensor::shape |
std::vector<std::complex<double> > cadabra::NTensor::values |