#include <tensor.h>
Definition at line 57 of file tensor.h.
Public Member Functions | |
tensor () | |
Create an empty tensor with zero rank. | |
tensor (size_t rank, size_t *dim) | |
Create a tensor of rank rank with sizes given in dim . | |
virtual int | set (size_t *index, double val) |
Set the element indexed by index to value val . | |
virtual double & | get (size_t *index) |
Get the element indexed by index . | |
virtual double const & | get (size_t *index) const |
Get the element indexed by index . | |
ovector_array_stride | vector_slice (size_t ix, size_t *index) |
Fix all but one index to create a vector. | |
omatrix_array | matrix_slice (size_t *index, size_t ix) |
Fix all but two indices to create a matrix. | |
virtual int | get_rank () |
Return the rank of the tensor. | |
virtual int | tensor_allocate (size_t rank, size_t *dim) |
Allocate space for a tensor of rank rank with sizes given in dim . | |
virtual int | tensor_free () |
Free allocated space (also sets rank to zero). | |
virtual size_t | get_size (size_t i) |
Returns the size of the ith index. | |
virtual size_t | total_size () |
Returns the size of the tensor. | |
size_t | pack_indices (size_t *index) |
Pack the indices into a single array index. | |
int | unpack_indices (size_t ix, size_t *index) |
Unpack the single array index into indices. | |
Protected Attributes | |
double * | data |
size_t * | size |
A rank-sized array of the sizes of each dimension. | |
size_t | rk |
Rank. |
tensor | ( | size_t | rank, | |
size_t * | dim | |||
) | [inline] |
omatrix_array matrix_slice | ( | size_t * | index, | |
size_t | ix | |||
) | [inline] |
Fix all but two indices to create a matrix.
This fixes all of the indices to the values given in index
except for the index number ix
and the last index, and returns the corresponding matrix, whose size is equal to the size of the tensor in the two indices which are not fixed.
virtual int tensor_allocate | ( | size_t | rank, | |
size_t * | dim | |||
) | [inline, virtual] |
Allocate space for a tensor of rank rank
with sizes given in dim
.
The parameter dim
must be a pointer to an array of sizes with length rank
.
If memory was previously allocated, it will be freed before the new allocation and previously specified grid data will be lost.
If the user requests any of the sizes to be zero, this function will call the error handler and will allocate no memory. If memory was previously allocated, the tensor is left unmodified and no deallocation is performed.
Reimplemented in tensor_grid.
ovector_array_stride vector_slice | ( | size_t | ix, | |
size_t * | index | |||
) | [inline] |
Fix all but one index to create a vector.
This fixes all of the indices to the values given in index
except for the index number ix
, and returns the corresponding vector, whose length is equal to the size of the tensor in that index. The value index[ix]
is ignored.
For example, for a rank 3 tensor allocated with
tensor t; size_t dim[3]={3,4,5}; t.tensor_allocate(3,dim);
size_t index[3]={1,0,3}; ovector_view v=t.vector_slice(index,1);
v
of length 4 which refers to the values t(1,0,3)
, t(1,1,3)
, t(1,2,3)
, and t(1,3,3)
.
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page