Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
cadabra::NTensor Class Reference

#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.
NTensoroperator= (const NTensor &)
 Assignment operator.
NTensoroperator= (NTensor &&) noexcept
 Move assignment operators.
NTensoroperator= (const NTensor &&) noexcept
NTensoroperator+= (const NTensor &)
 Addition operator. This requires the shapes to match.
NTensoroperator*= (const NTensor &)
 Element-wise multiplication operator. This requires the shapes to match.
NTensoroperator*= (const std::complex< double > &)
 Multiplyall elements with a scalar.
NTensoroperator*= (double)
NTensorpow (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.
NTensorapply (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)
 Expand the shape of the tensor to the specified shape by broadcasting to the other dimensions.

Public Attributes

std::vector< size_t > shape
std::vector< std::complex< double > > values

Friends

std::ostream & operator<< (std::ostream &, const NTensor &)

Constructor & Destructor Documentation

◆ NTensor() [1/9]

NTensor::NTensor ( const std::vector< size_t > & shape,
std::complex< double > val )
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.

◆ NTensor() [2/9]

NTensor::NTensor ( const std::vector< std::complex< double > > & vals)
explicit

Initialise as a vector of std::complex<double>s; sets shape automatically.

◆ NTensor() [3/9]

NTensor::NTensor ( const std::vector< double > & vals)
explicit

As above, but with doubles instead of complex doubles.

◆ NTensor() [4/9]

NTensor::NTensor ( std::initializer_list< std::complex< double > > vals)

Helper functions to be able to initialise a tensor with an initialiser list.

◆ NTensor() [5/9]

NTensor::NTensor ( std::initializer_list< double > vals)

◆ NTensor() [6/9]

NTensor::NTensor ( std::complex< double > val)
explicit

Initialise as a scalar; sets shape automatically.

◆ NTensor() [7/9]

NTensor::NTensor ( double val)
explicit

◆ NTensor() [8/9]

NTensor::NTensor ( const NTensor & other)
explicit

Copy constructor.

◆ NTensor() [9/9]

NTensor::NTensor ( NTensor && other)

Move constructor.

Member Function Documentation

◆ apply()

NTensor & NTensor::apply ( std::complex< double >(* fun )(const std::complex< double > &))

Apply a scalar function fun to all elements, return a reference to itself.

◆ at() [1/3]

std::complex< double > NTensor::at ( ) const

Get the value of a scalar NTensor.

◆ at() [2/3]

std::complex< double > & NTensor::at ( const std::vector< size_t > & indices)

Get the value of the tensor at the indicated component.

◆ at() [3/3]

std::complex< double > NTensor::at ( const std::vector< size_t > & indices) const

Get the value of the tensor at the indicated component.

◆ is_real()

bool NTensor::is_real ( ) const

Test if all values of the tensor are real.

◆ is_scalar()

bool NTensor::is_scalar ( ) const

Test if the shape is a single element equal to 1 (so the tensor is actually a scalar).

◆ linspace()

NTensor NTensor::linspace ( std::complex< double > from,
std::complex< double > to,
size_t steps )
static

Create equally spaced values in a range.

◆ operator*=() [1/3]

NTensor & NTensor::operator*= ( const NTensor & other)

Element-wise multiplication operator. This requires the shapes to match.

◆ operator*=() [2/3]

NTensor & NTensor::operator*= ( const std::complex< double > & m)

Multiplyall elements with a scalar.

◆ operator*=() [3/3]

NTensor & NTensor::operator*= ( double m)

◆ operator+=()

NTensor & NTensor::operator+= ( const NTensor & other)

Addition operator. This requires the shapes to match.

◆ operator=() [1/3]

NTensor & NTensor::operator= ( const NTensor && other)
noexcept

◆ operator=() [2/3]

NTensor & NTensor::operator= ( const NTensor & other)

Assignment operator.

◆ operator=() [3/3]

NTensor & NTensor::operator= ( NTensor && other)
noexcept

Move assignment operators.

◆ outer_product()

NTensor NTensor::outer_product ( const NTensor & a,
const NTensor & b )
static

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). */

NTensor broadcast(std::vector<size_t> new_shape, size_t pos) const;

/** 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}.

◆ pow()

NTensor & NTensor::pow ( const NTensor & other)

Element-wise pow operator (self**b, or pow(self,b)). Requires the shapes to match.

◆ operator<<

std::ostream & operator<< ( std::ostream & ,
const NTensor &  )
friend

Member Data Documentation

◆ shape

std::vector<size_t> cadabra::NTensor::shape

◆ values

std::vector<std::complex<double> > cadabra::NTensor::values

The documentation for this class was generated from the following files: