28 #ifndef _CHAINCON_TENSOR_H_ 29 #define _CHAINCON_TENSOR_H_ 37 #include "chomp/system/config.h" 51 template <
class Cell1T,
class Cell2T,
class CoefT>
74 const Cell1T &
left (int_t n)
const;
77 const Cell2T &
right (int_t n)
const;
80 const CoefT &
coef (int_t n)
const;
83 void add (
const Cell1T &c1,
const Cell2T &c2,
const CoefT &
coef);
110 template <
class Cell1T,
class Cell2T,
class CoefT>
116 template <
class Cell1T,
class Cell2T,
class CoefT>
122 template <
class Cell1T,
class Cell2T,
class CoefT>
128 template <
class Cell1T,
class Cell2T,
class CoefT>
134 template <
class Cell1T,
class Cell2T,
class CoefT>
140 template <
class Cell1T,
class Cell2T,
class CoefT>
143 return tensor. getCoef (n);
146 template <
class Cell1T,
class Cell2T,
class CoefT>
148 (
const Cell1T &c1,
const Cell2T &c2,
const CoefT &
coef)
153 template <
class Cell1T,
class Cell2T,
class CoefT>
157 int_t ch1size = ch1.
size ();
158 int_t ch2size = ch2.
size ();
159 for (int_t i = 0; i < ch1size; ++ i)
161 const Cell1T &cell1 = ch1. getCell (i);
162 const CoefT &coef1 = ch1. getCoef (i);
163 for (int_t j = 0; j < ch2size; ++ j)
165 const Cell2T &cell2 = ch2. getCell (j);
166 CoefT
coef (ch2. getCoef (j));
168 add (cell1, cell2, coef);
174 template <
class Cell1T,
class Cell2T,
class CoefT>
183 template <
class Cell1T,
class Cell2T,
class CoefT>
185 tTensor<Cell1T,Cell2T,CoefT>::operator *=
192 template <
class Cell1T,
class Cell2T,
class CoefT>
193 inline bool tTensor<Cell1T,Cell2T,CoefT>::operator ==
199 template <
class Cell1T,
class Cell2T,
class CoefT>
210 template <
class Cell1T,
class Cell2T,
class CoefT>
219 for (int_t i = 0; i <
size; ++ i)
223 out << c.
coef (i) <<
" * " <<
231 template <
class Cell1T,
class Cell2T,
class CoefT>
235 throw "Operator >> not implemented for tTensor.";
240 #endif // _CHAINCON_TENSOR_H_ tTensor()
The default constructor of an empty tensor.
A pair of elements of two (possibly different) types.
int_t size() const
Returns the number of elements in the tensor.
Cell2T Cell2Type
The type of right cells in the tensor.
const Cell1T & left(int_t n) const
Returns the n-th left element of the tensor.
A chain with coefficients in an arbitrary ring.
bool operator==(const tTensor< Cell1T, Cell2T, CoefT > &ch) const
Compares if the two tensors are equal.
bool empty() const
Returns true if and only if the tensor is zero (empty set).
void add(const Cell1T &c1, const Cell2T &c2, const CoefT &coef)
Adds a pair of cells to the tensor.
CoefT CoefType
The type of coefficients in the chain.
tTensor< Cell1T, Cell2T, CoefT > & operator*=(const CoefT &coef)
Multiples the tensor by a given coefficient.
const CoefT & coef(int_t n) const
Returns the n-th coefficient in the tensor.
A chain with coefficients in an arbitrary commutative ring.
std::istream & operator>>(std::istream &in, tTensor< Cell1T, Cell2T, CoefT > &c)
Reads a tensor from an input stream.
std::ostream & operator<<(std::ostream &out, const tTensor< Cell1T, Cell2T, CoefT > &c)
Writes a tensor to an output stream.
tChain< tPair< Cell1T, Cell2T >, CoefT > tensor
The set of elements in the tensor.
void swap(tTensor< Cell1T, Cell2T, CoefT > &ch)
Swaps the data with another tensor.
Cell1T Cell1Type
The type of left cells in the tensor.
const Cell2T & right(int_t n) const
Returns the n-th right element of the tensor.