Object-oriented Scientific Computing Library: Version 0.910
Public Member Functions | Protected Attributes
tensor_old_grid Class Reference

Tensor_Old class with arbitrary dimensions with a grid. More...

#include <tensor_old.h>

Inheritance diagram for tensor_old_grid:
tensor_old tensor_old_grid1 tensor_old_grid2 tensor_old_grid3 tensor_old_grid4

Detailed Description

This tensor_old 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.

Idea for Future:
Only allocate space for grid if it is set
Idea for Future:
Could implement arithmetic operators + and - and some different products.
Idea for Future:
Consider creating a set_grid() function which takes grids from an object like hist_grid. Maybe make a constructor for a tensor_old_grid object which just takes as input a set of grids?

Definition at line 508 of file tensor_old.h.

Public Member Functions

 tensor_old_grid ()
 Create an empty tensor_old with zero rank.
template<class uint_vec_t >
 tensor_old_grid (size_t rank, const uint_vec_t &dim)
 Create a tensor_old 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 uint_vec_t >
int 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.
int tensor_old_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)
 Set the grid.
int set_grid_old (double **vals)
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 index for grid closest to val.
template<class vec_t , class uint_vec_t >
int lookup_grid_vec (const vec_t &vals, const uint_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

double ** grd
 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< double * > * bim1
 The interpolation manager.
base_interp_mgr
< array_const_subvector > * 
bim2
 The subvector interpolation manager.

Interpolation

def_interp_mgr< double
*, linear_interp
dim1
def_interp_mgr
< array_const_subvector,
linear_interp
dim2
int set_interp (base_interp_mgr< double * > &bi1, base_interp_mgr< array_const_subvector > &bi2)
 Set interpolation managers.
double interpolate (double *vals)
 Interpolate values vals into the tensor_old, returning the result.

Constructor & Destructor Documentation

template<class uint_vec_t >
tensor_old_grid::tensor_old_grid ( 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 546 of file tensor_old.h.


Member Function Documentation

template<class vec_t , class vec2_t >
int tensor_old_grid::set_val ( const vec_t &  grdp,
double  val,
vec2_t &  closest 
) [inline]

The parameters closest and grdp may be identical, allowing one to update a vector grdp with the closest grid point.

Definition at line 604 of file tensor_old.h.

template<class uint_vec_t >
int tensor_old_grid::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 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_old is left unmodified and no deallocation is performed.

Reimplemented from tensor_old.

Definition at line 696 of file tensor_old.h.

template<class vec_t >
int tensor_old_grid::set_grid ( const vec_t &  grid) [inline]

The grid must be specified for all of the dimensions at once. Denote $ (\mathrm{size})_0 $ as the size of the first dimension, $ (\mathrm{size})_1 $ as the size of the second dimesion, and so on. Then the first $ (\mathrm{size})_0 $ entries in grid must be the grid for the first dimension, the next $ (\mathrm{size})_1 $ entries must be the grid for the second dimension, and so on. Thus grid must be a vector of size

\[ \sum_{i=0}^{\mathrm{rank}} (\mathrm{size})_i \]

Note that the grid is copied so the function argument may be destroyed by the user after calling set_grid() without affecting the tensor_old grid.

Idea for Future:
Define a more generic interface for matrix types

Definition at line 757 of file tensor_old.h.

template<class vec_t , class uint_vec_t >
int tensor_old_grid::lookup_grid_vec ( const vec_t &  vals,
const uint_vec_t &  indices 
) const [inline]

The values in vals are not modified by this function.

Definition at line 821 of file tensor_old.h.

double tensor_old_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.

Idea for Future:
Maybe make this a template as well?
Idea for Future:
It should be straightforward to improve the scaling of this algorithm significantly by creating a "window" of local points around the point of interest. This could be done easily by constructing an initial subtensor_old. However, this should probably be superceded by a more generic alternative which avoids explicit use of the 1-d interpolation types.

Definition at line 886 of file tensor_old.h.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.