QTensor Class Reference

Implementation of tensors, a generalization for matrices and vectors. More...

#include <qtensor/qtensor.h>

List of all members.

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.
QTensoroperator= (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
QTensorcopy (const QTensor &tensor)
 Copy a tensor.

Friends

std::ostream & operator<< (std::ostream &os, const QTensor &tensor)


Detailed Description

Implementation of tensors, a generalization for matrices and vectors.

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.

Tensor basic usage

Tensor creation: index naming and tensor valence

Generally, every tensor index should have a name. Index names are created as QTensorIndex objects, as follows:
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:

Creation

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.

Note:
Index equivalence:: explain about how two index names can be equivalent.

Copy operator (=)

QTensorIndex i = 10, j = 20, k = 7;
[...]
QTensor A( i * j.cov() * k ), B = A, C;
[...]
A = B;
C = B;

Compare operator (==)

Evaluates true if both tensors are equivalent (same valence and data content):
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.
        { [...] }

Data accessing

Tensor slice operation

Equivalent to a submatrix extractor. Keep some index values for a concrete index, in a tensor:
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]);

Tensor transpose operation

Tensor contraction

QTensorIndex i = 10, j = 20, k = 10;
[...]
QTensor A( i * j * k ), B;
[...]
B = A( i * j * i.cov() );

Tensor product

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() );

Inner product

Definition at line 163 of file qtensor.h.


Constructor & Destructor Documentation

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.

Parameters:
indexList a QTensorValence, created from a list of QTensorIndex objects.
Todo:
check that no indexes are repeated in the indexList

Definition at line 176 of file qtensor.h.


Member Function Documentation

QTensor& QTensor::operator= ( const QTensor tensor  )  [inline]

Copy operator for tensors.

This functions copies content of the data buffer, valence, and index names on this vector, over a given one.

Returns:
a reference of this tensor

Definition at line 191 of file qtensor.h.

References copy().

bool QTensor::operator== ( const QTensor tensor  )  const [inline]

Compare operator for tensors.

Returns:
true if valence and data of both tensors.

Definition at line 195 of file qtensor.h.

References equals().

QTensor QTensor::operator * ( const QTensor tensor  )  const [inline]

Tensor product.

See also:

Definition at line 199 of file qtensor.h.

References tensorProduct().

QTensor QTensor::operator^ ( const QTensor tensor  )  const [inline]

Inner product.

See also:

Definition at line 203 of file qtensor.h.

References innerProduct().

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.

See also:

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.

Returns:
the product of the sizes of all the indexes 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.

Returns:
a constant pointer to the data buffer of the tensor

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.

Returns:
a pointer to the data buffer of the tensor

Definition at line 223 of file qtensor.h.

Referenced by outerProduct(), slice(), and tensorProduct().

QTensorValence QTensor::getValence (  )  const

Gets valence of the tensor.

Returns:
a QList<QTensorIndex> object, containing the QTensorIndex objects corresponding to the indexes 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.

See also:
transpose(const QTensorIndex &, const QTensorIndex &) const;

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.

See also:
transpose(const QTensorIndex &, const QTensorIndex &) const;

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

See also:
transpose(const QTensorValence &) const

Definition at line 191 of file qtensor.cpp.

References transpose().

QTensor QTensor::outerProduct ( const QTensor tensor  )  const

obtains the outer product of two tensors

See also:
transpose(const QTensorValence &) const

Definition at line 376 of file qtensor.cpp.

References getDataSize(), getReadData(), getValence(), and getWriteData().

Referenced by tensorProduct().

QTensor QTensor::tensorProduct ( const QTensor tensor  )  const

Obtains the tensor product of two tensors.

Returns:
the contracted tensor resulting from the outer product of the actual tensor and the one given through the parameter.
See also:
operator*(const QTensorValence &) const

Definition at line 45 of file qtensor.cpp.

References contract(), getDataSize(), getReadData(), getValence(), getWriteData(), indexIds, outerProduct(), and transpose().

Referenced by operator *().

QTensor QTensor::innerProduct ( const QTensor tensor  )  const

Obtains the inner product of two tensors.

Returns:
the inner product from the actual tensor, and the one given through the parameter.
See also:
operator^(const QTensorValence &) const

Todo:
: to be done.

Definition at line 139 of file qtensor.cpp.

Referenced by operator^().

bool QTensor::equals ( const QTensor tensor  )  const

Check equivalence between tensors.

Returns:
true if the given tensor has equivalent valence and equal content of the data buffer.
See also:
operator==(const QTensorValence &) const

Todo:

Definition at line 39 of file qtensor.cpp.

Referenced by operator==().

QTensor QTensor::renameIndexes ( const QTensorValence &  indexList  )  const

Todo:
: check if valence (variance/covariance and size) of new and old indexes is equivalent

Definition at line 145 of file qtensor.cpp.

References contract(), and indexIds.

Referenced by operator()().

QTensor & QTensor::copy ( const QTensor tensor  ) 

Copy a tensor.

This functions copies content of the data buffer, valence, and index names on this vector, over a given one.

Returns:
a reference to this vector
See also:
operator=(const QTensorValence &)

Definition at line 27 of file qtensor.cpp.

References data, and indexIds.

Referenced by operator=().


The documentation for this class was generated from the following files:
Generated on Thu Mar 13 19:18:17 2008 for QVision by  doxygen 1.5.3