![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
Tensor class with arbitrary dimensions with a grid. More...
#include <tensor.h>
This tensor class allows one to assign the indexes to numerical scales, so that n-dimensional interpolation can be performed. To set the grid, use set_grid() and then interpolation can be done using interpolate().
By convention, member functions ending in the _val suffix return the closest grid-point to some user-specified values.
Public Member Functions | |
tensor_grid () | |
Create an empty tensor with zero rank. | |
template<class size_vec_t > | |
tensor_grid (size_t rank, const size_vec_t &dim) | |
Create a tensor of rank rank with sizes given in dim . | |
Set functions | |
template<class vec_t > | |
int | set_val (const vec_t &grdp, double val) |
Set the element closest to grid point grdp to value val . | |
template<class vec_t , class vec2_t > | |
int | set_val (const vec_t &grdp, double val, vec2_t &closest) |
Set the element closest to grid point grdp to value val . | |
Get functions | |
template<class vec_t > | |
double | get_val (const vec_t &grdp) |
Get the element closest to grid point grdp . | |
template<class vec_t , class vec2_t > | |
double | get_val (const vec_t &grdp, const vec2_t &closest) |
Get the element closest to grid point grdp to value val . | |
Memory allocation | |
template<class size_vec_t > | |
int | allocate (size_t rank, const size_vec_t &dim) |
Allocate space for a tensor of rank rank with sizes given in dim . | |
int | free () |
Free allocated space (also sets rank to zero) | |
Grid manipulation | |
bool | is_grid_set () const |
Return true if the grid has been set. | |
template<class vec_t > | |
int | set_grid (const vec_t &grid_vec) |
Set the grid. | |
size_t | lookup_grid (size_t i, double val) |
Lookup index for grid closest to val . | |
double | get_grid (size_t i, size_t j) const |
Lookup jth value on the ith grid. | |
template<class vec_t , class size_vec_t > | |
int | lookup_grid_vec (const vec_t &vals, const size_vec_t &indices) const |
Lookup indices for grid closest point to vals . | |
size_t | lookup_grid_val (size_t i, double &val, double &val2) |
Lookup index for grid closest to val , returning the grid point. | |
Protected Attributes | |
uvector | grid |
A rank-sized set of arrays for the grid points. | |
bool | grid_set |
If true, the grid has been set by the user. | |
base_interp_mgr< uvector_base > * | bim1 |
The interpolation manager. | |
base_interp_mgr < uvector_const_subvector > * | bim2 |
The subvector interpolation manager. | |
Interpolation | |
def_interp_mgr< uvector_base, linear_interp > | dim1 |
def_interp_mgr < uvector_const_subvector, linear_interp > | dim2 |
int | set_interp (base_interp_mgr< uvector_base > &bi1, base_interp_mgr< uvector_const_subvector > &bi2) |
Set interpolation managers. | |
double | interpolate (double *vals) |
Interpolate values vals into the tensor, returning the result. |
tensor_grid::tensor_grid | ( | size_t | rank, |
const size_vec_t & | dim | ||
) | [inline] |
int tensor_grid::set_val | ( | const vec_t & | grdp, |
double | val, | ||
vec2_t & | closest | ||
) | [inline] |
int tensor_grid::allocate | ( | size_t | rank, |
const size_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 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 from tensor.
int tensor_grid::set_grid | ( | const vec_t & | grid_vec | ) | [inline] |
The grid must be specified for all of the dimensions at once. Denote as the size of the first dimension,
as the size of the second dimesion, and so on. Then the first
entries in
grid
must be the grid for the first dimension, the next entries must be the grid for the second dimension, and so on. Thus
grid
must be a vector of size
Note that the grid is copied so the function argument may be destroyed by the user after calling set_grid() without affecting the tensor grid.
int tensor_grid::lookup_grid_vec | ( | const vec_t & | vals, |
const size_vec_t & | indices | ||
) | const [inline] |
double tensor_grid::interpolate | ( | double * | vals | ) | [inline] |
This is a quick and dirty implementation of n-dimensional interpolation by recursive application of the 1-dimensional routine from smart_interp_vec, using the base interpolation object specified in the template parameter base_interp_t
. This will be slow for sufficiently large data sets.
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).