#include <qtensor/qtensor.h>
Public Member Functions | |
QTensor (const QTensor &tensor) | |
Copy constructor. Creates a tensor object and copy the valence and data from a given one. | |
QTensor (const QTensorValence &indexList) | |
Index list constructor. | |
QTensor & | operator= (const QTensor &tensor) |
Copy operator for tensors. | |
bool | operator== (const QTensor &tensor) const |
Compare operator for tensors. | |
QTensor | operator * (const QTensor &tensor) const |
Tensor product. | |
QTensor | operator^ (const QTensor &tensor) const |
Inner product. | |
QTensor | operator() (const QTensorValence &indexList) const |
Index renaming and contracting operator. | |
const int | getDataSize () const |
Gets the size of the data array. | |
const double * | getReadData () const |
Gets a reference of the data buffer of the tensor for read accesses. | |
double * | getWriteData () |
Gets a reference of the data buffer of the tensor for read and write accesses. | |
QTensorValence | getValence () const |
Gets valence of the tensor. | |
QTensor | slice (const QTensorIndexValues &indexRangeList) const |
Get a subtensor from a tensor. | |
QTensor | transpose (const QTensorValence &indexList) const |
Change the order of the index in the tensor. | |
QTensor | transpose (const QTensorIndex &i, const QTensorIndex &j) const |
overload of transpose function for convenience | |
QTensor | outerProduct (const QTensor &tensor) const |
obtains the outer product of two tensors | |
QTensor | tensorProduct (const QTensor &tensor) const |
Obtains the tensor product of two tensors. | |
QTensor | innerProduct (const QTensor &tensor) const |
Obtains the inner product of two tensors. | |
bool | equals (const QTensor &tensor) const |
Check equivalence between tensors. | |
QTensor | renameIndexes (const QTensorValence &indexList) const |
QTensor & | copy (const QTensor &tensor) |
Copy a tensor. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const QTensor &tensor) |
Opossed to scalar values, vector and matrices contain numeric values indexed by one and two index values respectively. A tensor is a generalization of these concepts, that can contain numeric values indexed by a set of fixed indexes.
QTensorIndex i = 10, j = 20, k = 7, l = 14;
Every index name has a dimension size asociated to it. It will indicate the number of elements in the index.
For tensor creation, these index names can be composed with the * operator, and the cov() function, to create an expression to represent the valence of a tensor. This valence expression will be used for tensor creation. An example:
QTensorIndex i = 10, j = 20, k = 7, l = 14; [...] QTensor A( i * j.cov() * k ), B ( k * l.cov() );
The latter code creates two tensor objects, A and B.
QTensorIndex i = 10, j = 20, k = 7; [...] QTensor A( i * j.cov() * k ), B = A, C; [...] A = B; C = B;
QTensorIndex i = 10, j = 20, k = 7, l = 10; [...] QTensor A( i * j.cov() * k ), B(l * j * k), C(k * j); [...] if (A == C) // This condition will never be true, unless valence of C changes { [...] } if (A == B) // This condition will be true, depending on the data values // contained in tensors A and B { [...] } [...] A = B; if (A == B) // This condition will always be true. { [...] }
QTensorIndex i = 10, j = 20, k = 7; [...] QTensor A( i * j.cov() * k ), B, C; [...] B = A(i[10] & i.range(3,5)); C = B(j[3] & J[1] & j.range(0,1));
Equivalent code, multiple variable slicing:
QTensorIndex i = 10, j = 20, k = 7; [...] QTensor A( i * j.cov() * k ), C; [...] C = B(i[10] & i.range(3,5) & j[3] & J[1] & j.range(0,1));
When an index has only one value left, it dissapears from the valence of the tensor:
QTensorIndex i = 10, j = 20, k = 7; [...] QTensor A( i * j.cov() * k ), C; [...] C = B(i[0] & j[1]);
QTensorIndex i = 10, j = 20, k = 10; [...] QTensor A( i * j * k ), B; [...] B = A( i * j * i.cov() );
QTensorIndex i = 10, j = 20, k = 10, l = 14, m = 10, n = 5; [...] QTensor A( i * j * k ), B; [...] B = A( i * j * i.cov() );
Definition at line 163 of file qtensor.h.
QTensor::QTensor | ( | const QTensorValence & | indexList | ) | [inline] |
Index list constructor.
Creates a new tensor from a given valence, represented by a QTensorIndex list. See Tensor basic usage section for a detailed description about its usage.
indexList | a QTensorValence, created from a list of QTensorIndex objects. |
bool QTensor::operator== | ( | const QTensor & | tensor | ) | const [inline] |
QTensor QTensor::operator() | ( | const QTensorValence & | indexList | ) | const [inline] |
Index renaming and contracting operator.
This operator is useful for two things: tensor index renaming and contraction.
Definition at line 209 of file qtensor.h.
References renameIndexes().
const int QTensor::getDataSize | ( | ) | const [inline] |
Gets the size of the data array.
This returns the number of elements in the tensor.
Definition at line 215 of file qtensor.h.
Referenced by outerProduct(), and tensorProduct().
const double* QTensor::getReadData | ( | ) | const [inline] |
Gets a reference of the data buffer of the tensor for read accesses.
Definition at line 219 of file qtensor.h.
Referenced by operator<<(), outerProduct(), slice(), and tensorProduct().
double* QTensor::getWriteData | ( | ) | [inline] |
Gets a reference of the data buffer of the tensor for read and write accesses.
Definition at line 223 of file qtensor.h.
Referenced by outerProduct(), slice(), and tensorProduct().
QTensorValence QTensor::getValence | ( | ) | const |
Gets valence of the tensor.
Definition at line 158 of file qtensor.cpp.
Referenced by outerProduct(), and tensorProduct().
QTensor QTensor::slice | ( | const QTensorIndexValues & | indexRangeList | ) | const |
Get a subtensor from a tensor.
Like with matrices, it is possible to extract a part of a tensor, given a list of values for some of its indexes. For futher details about the use of this function ,see Tensor slice operation.
Definition at line 166 of file qtensor.cpp.
References getReadData(), and getWriteData().
QTensor QTensor::transpose | ( | const QTensorValence & | indexList | ) | const |
Change the order of the index in the tensor.
This function receives a rearanged list of its indexes, and recollocates the values in its data buffer conforming to that ordering.
Definition at line 212 of file qtensor.cpp.
References ABS.
Referenced by tensorProduct(), and transpose().
QTensor QTensor::transpose | ( | const QTensorIndex & | i, | |
const QTensorIndex & | j | |||
) | const |
overload of transpose function for convenience
This overloaded version of transpose
Definition at line 191 of file qtensor.cpp.
References transpose().
obtains the outer product of two tensors
Definition at line 376 of file qtensor.cpp.
References getDataSize(), getReadData(), getValence(), and getWriteData().
Referenced by tensorProduct().
Obtains the tensor product of two tensors.
Definition at line 45 of file qtensor.cpp.
References contract(), getDataSize(), getReadData(), getValence(), getWriteData(), indexIds, outerProduct(), and transpose().
Referenced by operator *().
Obtains the inner product of two tensors.
Definition at line 139 of file qtensor.cpp.
Referenced by operator^().
bool QTensor::equals | ( | const QTensor & | tensor | ) | const |
Check equivalence between tensors.
Definition at line 39 of file qtensor.cpp.
Referenced by operator==().
QTensor QTensor::renameIndexes | ( | const QTensorValence & | indexList | ) | const |
Definition at line 145 of file qtensor.cpp.
References contract(), and indexIds.
Referenced by operator()().
Copy a tensor.
This functions copies content of the data buffer, valence, and index names on this vector, over a given one.
Definition at line 27 of file qtensor.cpp.
References data, and indexIds.
Referenced by operator=().