tensor_grid Class Template Reference

#include <tensor.h>

Inheritance diagram for tensor_grid:

tensor

Detailed Description

template<template< class c_t > class base_interp_t = cspline_interp>
class tensor_grid< base_interp_t >

Tensor class with arbitrary dimensions.

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

Idea for future:
Only allocate space for grid if it is set
Idea for future:
Could implement arithmetic operators + and - and some different products.

Definition at line 360 of file tensor.h.


Public Member Functions

 tensor_grid ()
 Create an empty tensor with zero rank.
 tensor_grid (size_t rank, size_t *dim)
 Create a tensor of rank rank with sizes given in dim.
virtual int set_val (double *grdp, double val)
 Set the element closest to grid point grdp to value val.
virtual int set_val (double *grdp, double val, double *closest)
 Set the element closest to grid point grdp to value val.
virtual double get_val (double *grdp)
 Get the element closest to grid point grdp.
virtual double get_val (double *grdp, double *closest)
 Get the element closest to grid point grdp to value val.
virtual int set_grid (double **val)
 Set the grid.
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 lookup_grid (size_t i, double val)
 Lookup index for grid closest to val.
virtual double get_grid (size_t i, size_t j)
 Lookup index for grid closest to val.
virtual int lookup_grid (double *vals, size_t *indices)
 Lookup indices for grid closest to val.
virtual size_t lookup_grid_val (size_t i, double val, double &val2)
 Lookup index for grid closest to val, returning the grid point.
virtual double interpolate (double *vals)
 Interpolate values vals into the tensor, returning the result.

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.

Constructor & Destructor Documentation

tensor_grid ( size_t  rank,
size_t *  dim 
) [inline]

Create 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 the user requests any of the sizes to be zero, this constructor will call the error handler, create an empty tensor, and will allocate no memory.

Definition at line 390 of file tensor.h.


Member Function Documentation

virtual int set_grid ( double **  val  )  [inline, virtual]

Set the grid.

The parameter grid must define the grid, so that val[i][j] is the jth grid point for the ith index. The size of array grid[i] should be given by dim[i] where dim was the argument given in the constructor or to the function tensor_allocate().

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

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

Definition at line 521 of file tensor.h.

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 from tensor.

Definition at line 547 of file tensor.h.

virtual double interpolate ( double *  vals  )  [inline, virtual]

Interpolate values vals into the tensor, returning the result.

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:
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.

Definition at line 654 of file tensor.h.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page