![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
Tensor_Old class with arbitrary dimensions. More...
#include <tensor_old.h>
The elements of a tensor_old are typically specified as a list of size_t
numbers with length equal to the tensor_old rank. For a rank-4 tensor_old named t
, the element t[1][2][0][3]
can be obtained with something similar to
size_t ix[4]={1,2,0,3}; double x=t.get(ix);
Empty tensor_olds have zero rank.
Slices of tensor_olds are subsets obtained from fixing the index of several dimensions, while letting other dimensions vary. For a slice with one dimension not fixed, see vector_slice(). For a slice with two dimensions not fixed, see matrix_slice().
For I/O with tensor_olds, see hdf_io.h .
value_t
.Definition at line 93 of file tensor_old.h.
Public Member Functions | |
tensor_old () | |
Create an empty tensor_old with zero rank. | |
template<class uint_vec_t > | |
tensor_old (size_t rank, const uint_vec_t &dim) | |
Create a tensor_old of rank rank with sizes given in dim . | |
Set functions | |
template<class uint_vec_t > | |
void | set (const uint_vec_t &index, double val) |
Set the element indexed by index to value val . | |
void | set_all (double x) |
Set all elements in a tensor_old to some fixed value. | |
Get functions | |
template<class uint_vec_t > | |
double & | get (const uint_vec_t &index) |
Get the element indexed by index . | |
template<class uint_vec_t > | |
double const & | get (const uint_vec_t &index) const |
Get a const reference to the element indexed by index . | |
Slice functions | |
template<class uint_vec_t > | |
ovector_array_stride | vector_slice (size_t ix, const uint_vec_t &index) |
Fix all but one index to create a vector. | |
template<class uint_vec_t > | |
omatrix_array | matrix_slice (size_t ix, const uint_vec_t &index) |
Fix all but two indices to create a matrix. | |
Memory allocation | |
template<class uint_vec_t > | |
void | tensor_old_allocate (size_t rank, const uint_vec_t &dim) |
Allocate space for a tensor_old of rank rank with sizes given in dim . | |
void | tensor_old_free () |
Free allocated space (also sets rank to zero) | |
Size functions | |
size_t | get_rank () const |
Return the rank of the tensor_old. | |
size_t | get_size (size_t i) const |
Returns the size of the ith index. | |
const size_t * | get_size_arr () const |
Return the full array of sizes. | |
const double * | get_data () const |
Return the full array of sizes. | |
size_t | total_size () const |
Returns the size of the tensor_old (the product of the sizes over every index) | |
Index manipulation | |
template<class uint_vec_t > | |
size_t | pack_indices (const uint_vec_t &index) |
Pack the indices into a single array index. | |
template<class uint_vec_t > | |
void | unpack_indices (size_t ix, uint_vec_t &index) |
Unpack the single array index into indices. | |
Protected Attributes | |
double * | data |
The data. | |
size_t * | size |
A rank-sized array of the sizes of each dimension. | |
size_t | rk |
Rank. |
tensor_old::tensor_old | ( | size_t | rank, |
const uint_vec_t & | dim | ||
) | [inline] |
The parameter dim
must be a pointer to an array of sizes with length rank
. If the user requests any of the sizes to be zero, this constructor will call the error handler, create an empty tensor_old, and will allocate no memory.
Definition at line 127 of file tensor_old.h.
ovector_array_stride tensor_old::vector_slice | ( | size_t | ix, |
const uint_vec_t & | index | ||
) | [inline] |
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_old in that index. The value index[ix]
is ignored.
For example, for a rank 3 tensor_old allocated with
tensor_old t; size_t dim[3]={3,4,5}; t.tensor_old_allocate(3,dim);
the following code
size_t index[3]={1,0,3}; ovector_view v=t.vector_slice(1,index);
Gives a vector 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)
.
Definition at line 282 of file tensor_old.h.
omatrix_array tensor_old::matrix_slice | ( | size_t | ix, |
const uint_vec_t & | index | ||
) | [inline] |
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_old in the two indices which are not fixed.
Since the last index is always fixed, the parameter ix
is limited to be .
Definition at line 310 of file tensor_old.h.
void tensor_old::tensor_old_allocate | ( | size_t | rank, |
const uint_vec_t & | dim | ||
) | [inline] |
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.
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_old is left unmodified and no deallocation is performed.
Reimplemented in tensor_old_grid.
Definition at line 355 of file tensor_old.h.
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).