Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
NTensor.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include <vector>
5#include <iostream>
6#include <complex>
7
12
13namespace cadabra {
14
15 class NTensor {
16 public:
22 explicit NTensor(const std::vector<size_t>& shape, std::complex<double> val);
23
25 explicit NTensor(const std::vector<std::complex<double>>& vals);
27 explicit NTensor(const std::vector<double>& vals);
28
30 NTensor(std::initializer_list<std::complex<double>> vals);
31 NTensor(std::initializer_list<double> vals);
32
34 explicit NTensor(std::complex<double>);
35 explicit NTensor(double);
36
38 explicit NTensor(const NTensor&);
39
42
44 static NTensor linspace(std::complex<double> from, std::complex<double> to, size_t steps);
45
47 NTensor& operator=(const NTensor&);
48
50 NTensor& operator=(NTensor&&) noexcept;
51 NTensor& operator=(const NTensor&&) noexcept;
52
54 NTensor& operator+=(const NTensor&);
55
57 NTensor& operator*=(const NTensor&);
58
60 NTensor& operator*=(const std::complex<double>&);
61 NTensor& operator*=(double);
62
64 NTensor& pow(const NTensor&);
65
67 std::complex<double> at() const;
68
70 std::complex<double> at(const std::vector<size_t>& indices) const;
71
73 std::complex<double>& at(const std::vector<size_t>& indices);
74
89
90 NTensor broadcast(std::vector<size_t> new_shape, size_t pos) const;
91
98
99 static NTensor outer_product(const NTensor& a, const NTensor& b);
100
103 NTensor& apply(std::complex<double> (*fun)(const std::complex<double>&));
104
106 bool is_real() const;
107
110 bool is_scalar() const;
111
112 friend std::ostream& operator<<(std::ostream&, const NTensor&);
113
114 std::vector<size_t> shape;
115 std::vector<std::complex<double>> values;
116 };
117
118 std::ostream& operator<<(std::ostream &, const NTensor &);
119
120}
Definition NTensor.hh:15
bool is_real() const
Test if all values of the tensor are real.
Definition NTensor.cc:362
std::vector< size_t > shape
Definition NTensor.hh:114
static NTensor linspace(std::complex< double > from, std::complex< double > to, size_t steps)
Create equally spaced values in a range.
Definition NTensor.cc:104
bool is_scalar() const
Test if the shape is a single element equal to 1 (so the tensor is actually a scalar).
Definition NTensor.cc:370
std::complex< double > at() const
Get the value of a scalar NTensor.
Definition NTensor.cc:123
NTensor & operator+=(const NTensor &)
Addition operator. This requires the shapes to match.
Definition NTensor.cc:234
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:375
NTensor & operator=(const NTensor &)
Assignment operator.
Definition NTensor.cc:116
NTensor & operator*=(const NTensor &)
Element-wise multiplication operator. This requires the shapes to match.
Definition NTensor.cc:265
friend std::ostream & operator<<(std::ostream &, const NTensor &)
NTensor & apply(std::complex< double >(*fun)(const std::complex< double > &))
Apply a scalar function fun to all elements, return a reference to itself.
Definition NTensor.cc:219
NTensor & pow(const NTensor &)
Element-wise pow operator (self**b, or pow(self,b)). Requires the shapes to match.
Definition NTensor.cc:312
std::vector< std::complex< double > > values
Definition NTensor.hh:115
static NTensor outer_product(const NTensor &a, const NTensor &b)
Outer product of two NTensors.
Definition NTensor.cc:338
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
std::ostream & operator<<(std::ostream &os, const Multiplier &m)
Definition Multiplier.cc:208
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1179
void fun(int *&p)
Definition passing.cc:6