Tensor class with arbitrary dimensions with a grid. More...
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() or set_grid_packed() and then interpolation can be done using interp_linear() or interpolate().
By convention, member functions ending in the _val suffix return the closest grid-point to some user-specified values.
Only allocate space for grid if it is set
Consider creating a new set_grid() function which takes grids from an object like uniform_grid. Maybe make a constructor for a tensor_grid object which just takes as input a set of grids?
Definition at line 95 of file tensor_grid.h.
#include <tensor_grid.h>
Public Types | |
typedef boost::numeric::ublas::vector < double > | ubvector |
typedef boost::numeric::ublas::vector < size_t > | ubvector_size_t |
typedef boost::numeric::ublas::range | range |
typedef boost::numeric::ublas::vector_range < ubvector > | ubvector_range |
typedef boost::numeric::ublas::vector_range < ubvector_size_t > | ubvector_size_t_range |
![]() | |
typedef boost::numeric::ublas::vector_slice < boost::numeric::ublas::vector < double > > | ubvector_slice |
typedef boost::numeric::ublas::slice | slice |
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 . More... | |
Set functions | |
template<class vec_t > | |
void | 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 > | |
void | set_val (const vec_t &grdp, double val, vec2_t &closest) |
Set the element closest to grid point grdp to value val . More... | |
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, vec2_t &closest) |
Get the element closest to grid point grdp to value val . More... | |
Resize method | |
template<class size_vec_t > | |
void | resize (size_t rank, const size_vec_t &dim) |
Resize the tensor to rank rank with sizes given in dim . More... | |
Grid manipulation | |
bool | is_grid_set () const |
Return true if the grid has been set. | |
template<class vec_t > | |
void | set_grid_packed (const vec_t &grid_vec) |
Set the grid. More... | |
template<class vec_vec_t > | |
void | set_grid (const vec_vec_t &grid_vecs) |
Set grid from a vector of vectors of grid points. | |
double | get_grid (size_t i, size_t j) const |
Lookup jth value on the ith grid. | |
void | set_grid (size_t i, size_t j, double val) |
Set the jth value on the ith grid. | |
size_t | lookup_grid (size_t i, double val) |
Lookup index for grid closest to val . | |
template<class vec_t , class size_vec_t > | |
void | lookup_grid_vec (const vec_t &vals, size_vec_t &indices) const |
Lookup indices for grid closest point to vals . More... | |
size_t | lookup_grid_val (size_t i, const double &val, double &val2) |
Lookup index for grid closest to val , returning the grid point. More... | |
size_t | lookup_grid_packed (size_t i, double val) |
Lookup index for grid closest to val . | |
size_t | lookup_grid_packed_val (size_t i, double val, double &val2) |
Lookup index for grid closest to val . | |
Slicing | |
template<class size_vec_t > | |
void | copy_slice_align (size_t ix_x, size_t ix_y, size_vec_t &index, table3d &tab, std::string slice_name) |
Create a slice in a table3d object with an aligned grid. More... | |
template<class size_vec_t > | |
void | copy_slice_interp (size_t ix_x, size_t ix_y, size_vec_t &index, table3d &tab, std::string slice_name) |
Copy to a slice in a table3d object using interpolation. More... | |
Interpolation | |
void | set_interp_type (size_t interp_type) |
Set interpolation type. | |
double | interpolate (double *vals) |
Interpolate values vals into the tensor, returning the result. More... | |
template<class vec2_t > | |
double | interp_linear (vec2_t &v) |
Perform a linear interpolation of v into the function implied by the tensor and grid. More... | |
template<class vec2_t > | |
double | interp_linear_power_two (vec2_t &v) |
Perform linear interpolation assuming that all indices can take only two values. More... | |
![]() | |
tensor () | |
Create an empty tensor with zero rank. | |
tensor (size_t rank, const size_vec_t &dim) | |
Create a tensor of rank rank with sizes given in dim . More... | |
void | set (const size_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 to some fixed value. | |
double & | get (const size_vec_t &index) |
Get the element indexed by index . | |
double const & | get (const size_vec_t &index) const |
Get a const reference to the element indexed by index . | |
ubvector_slice | vector_slice (size_t ix, const size_vec_t &index) |
Fix all but one index to create a vector. More... | |
void | resize (size_t rank, const size_vec_t &dim) |
Resize the tensor to rank rank with sizes given in dim . More... | |
size_t | get_rank () const |
Return the rank of the tensor. | |
size_t | get_size (size_t i) const |
Returns the size of the ith index. | |
const boost::numeric::ublas::vector < size_t > & | get_size_arr () const |
Return the full vector of sizes. | |
const boost::numeric::ublas::vector < double > & | get_data () const |
Return the full data vector. | |
size_t | total_size () const |
Returns the size of the tensor (the product of the sizes over every index) | |
size_t | pack_indices (const size_vec_t &index) |
Pack the indices into a single vector index. | |
void | unpack_indices (size_t ix, size_vec_t &index) |
Unpack the single vector index into indices. | |
Protected Member Functions | |
ubvector & | get_data () |
Return a reference to the data (for HDF I/O) | |
Protected Attributes | |
ubvector | grid |
A rank-sized set of arrays for the grid points. | |
bool | grid_set |
If true, the grid has been set by the user. | |
size_t | itype |
Interpolation type. | |
![]() | |
boost::numeric::ublas::vector < double > | data |
The data. | |
boost::numeric::ublas::vector < size_t > | size |
A rank-sized vector of the sizes of each dimension. | |
size_t | rk |
Rank. | |
Friends | |
void | o2scl_hdf::hdf_output (o2scl_hdf::hdf_file &hf, tensor_grid &t, std::string name) |
void | o2scl_hdf::hdf_input (o2scl_hdf::hdf_file &hf, tensor_grid &t, std::string name) |
|
inline |
The parameter dim
must be a vector of sizes with length rank
. If the user requests any of the sizes to be zero, this constructor will call the error handler.
Definition at line 143 of file tensor_grid.h.
|
inline |
This function uses the grid associated with indices ix_x
and ix_y
, and the tensor interpolation function to copy to the slice named slice_name
in the table3d object tab
.
If the table3d object does not currently have a grid set, then the grid is automatically set to be the same as that stored in the tensor_grid object associated with ranks ix_x
and iy_y
. If the o2scl::table3d object does have a grid set, then the values returned by o2scl::table3d::get_nx() and o2scl::table3d::get_ny() must be equal to the size of the tensor in indices ix_x
and ix_y, respectively.
This currently requires a copy of all the tensor data into the table3d object.
Definition at line 564 of file tensor_grid.h.
|
inline |
This function uses the grid associated with indices ix_x
and ix_y
, and the tensor interpolation function to copy the tensor information to the slice named slice_name
in the table3d object tab
.
Definition at line 626 of file tensor_grid.h.
|
inline |
The parameters grdp
and closest
may refer to the same object.
Definition at line 245 of file tensor_grid.h.
|
inline |
This performs multi-dimensional linear interpolation (or extrapolation) It works by first using o2scl::search_vec to find the interval containing (or closest to) the specified point in each direction and constructing the corresponding hypercube of size containing
v
. It then calls interp_linear_power_two() to perform the interpolation in that hypercube.
Definition at line 787 of file tensor_grid.h.
|
inline |
This function works by recursively slicing the hypercube of size into a hypercube of size
performing linear interpolation for each pair of points.
Definition at line 834 of file tensor_grid.h.
|
inline |
This is a quick and dirty implementation of n-dimensional interpolation by recursive application of the 1-dimensional routine from interp_vec, using the base interpolation object specified in the template parameter base_interp_t
. This will be slow for sufficiently large data sets.
Definition at line 697 of file tensor_grid.h.
|
inline |
The parameters val
and val2
may refer to the same object.
Definition at line 464 of file tensor_grid.h.
|
inline |
The values in vals
are not modified by this function.
Definition at line 451 of file tensor_grid.h.
|
inline |
The parameter dim
must be a vector of sizes with a length equal to rank
. This resize method is always destructive, and the grid is always reset.
If the user requests any of the sizes to be zero, this function will call the error handler.
Definition at line 278 of file tensor_grid.h.
|
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_packed() without affecting the tensor grid.
Definition at line 340 of file tensor_grid.h.
|
inline |
The parameters closest
and grdp
may be identical, allowing one to update a vector grdp
with the closest grid point.
Definition at line 194 of file tensor_grid.h.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).
Hosted at
.