ndpolator 1.3.0
fast, n-dimensional linear interpolation and extrapolation on sparse grids
Loading...
Searching...
No Matches
Memory Management

Functions for instantiating and destroying ndpolator data structures. More...

Functions

ndp_axisndp_axis_new ()
 Default constructor for ndp_axis.
ndp_axisndp_axis_new_from_data (int len, double *val, int owns_data)
 Constructor for ndp_axis from existing data.
int ndp_axis_free (ndp_axis *axis)
 Destructor for ndp_axis.
ndp_axesndp_axes_new ()
 Default constructor for ndp_axes.
ndp_axesndp_axes_new_from_data (int naxes, int nbasic, ndp_axis **axis)
 Constructor for ndp_axes from existing data.
int ndp_axes_free (ndp_axes *axes)
 Destructor for ndp_axes.
ndp_query_ptsndp_query_pts_new ()
 Default constructor for ndp_query_pts.
ndp_query_ptsndp_query_pts_new_from_data (int nelems, int naxes, int *indices, int *flags, double *requested, double *normed)
 Constructor for ndp_query_pts from existing data.
int ndp_query_pts_alloc (ndp_query_pts *qpts, int nelems, int naxes)
 Allocates memory for ndp_query_pts arrays.
int ndp_query_pts_free (ndp_query_pts *qpts)
 Destructor for ndp_query_pts.
ndp_tablendp_table_new ()
 Default constructor for ndp_table.
ndp_tablendp_table_new_from_data (ndp_axes *axes, int vdim, double *grid, int owns_data)
 Constructor for ndp_table from existing data.
int ndp_table_free (ndp_table *table)
 Destructor for ndp_table.
ndp_hypercubendp_hypercube_new ()
 Default constructor for ndp_hypercube.
ndp_hypercubendp_hypercube_new_from_data (int dim, int vdim, int fdhc, double *v)
 Constructor for ndp_hypercube from existing data.
int ndp_hypercube_alloc (ndp_hypercube *hc, int dim, int vdim)
 Allocates memory for ndp_hypercube vertex array.
int ndp_hypercube_free (ndp_hypercube *hc)
 Destructor for ndp_hypercube.
ndp_queryndp_query_new ()
 Default constructor for ndp_query.
int ndp_query_free (ndp_query *query)
 Destructor for ndp_query.

Detailed Description

Functions for instantiating and destroying ndpolator data structures.

Use these functions to properly allocate and free memory for ndpolator structures.

Function Documentation

◆ ndp_axis_new()

ndp_axis * ndp_axis_new ( void )

Default constructor for ndp_axis.

Initializes a new ndp_axis instance, sets axis->len to 0 and axis->val to NULL.

Returns
Initialized ndp_axis instance

◆ ndp_axis_new_from_data()

ndp_axis * ndp_axis_new_from_data ( int len,
double * val,
int owns_data )

Constructor for ndp_axis from existing data.

Parameters
lenLength of the val array
valArray of vertices that span the axis
owns_dataFlag indicating if the val array is owned by self

Initializes a new ndp_axis instance, sets axis->len to len and axis->val to val. Note that the function does not copy the array, it only assigns a pointer to it. Thus, the calling function needs to determine data ownership and pass an allocated copy if the array is (re)used elsewhere. Ndpolator treats the val array as read-only and will not change it. On destruction, the val array will be freed only if owns_data is set to true.

Returns
Initialized ndp_axis instance

◆ ndp_axis_free()

int ndp_axis_free ( ndp_axis * axis)

Destructor for ndp_axis.

Parameters
axisndp_axis instance to be freed

Frees memory allocated for the ndp_axis instance. This includes the val array memory and the ndp_axis instance itself.

Returns
ndp_status code

◆ ndp_axes_new()

ndp_axes * ndp_axes_new ( void )

Default constructor for ndp_axes.

Initializes a new ndp_axes instance, sets axes->len and axes->nbasic to 0, and sets axes->axis and axes->cplen to NULL.

Returns
Initialized ndp_axes instance with default values

◆ ndp_axes_new_from_data()

ndp_axes * ndp_axes_new_from_data ( int naxes,
int nbasic,
ndp_axis ** axis )

Constructor for ndp_axes from existing data.

Parameters
naxesNumber of axes
nbasicNumber of basic axes
axisArray of ndp_axis pointers
Returns
Initialized ndp_axes instance

Initializes a new ndp_axes instance, sets axes->len to naxes, axes->nbasic to nbasic, and axes->axis to axis. Note that the function does not copy the array, it only assigns a pointer to it. Thus, the calling function needs to pass an allocated copy if the array is (re)used elsewhere. Ndpolator treats the axis array as read-only and will not change it. On destruction, the axis array, along with all individual axis instances, will be freed.

◆ ndp_axes_free()

int ndp_axes_free ( ndp_axes * axes)

Destructor for ndp_axes.

Parameters
axesndp_axes instance to be freed

Frees memory allocated for the ndp_axes instance. This includes the cplen array memory and the ndp_axes instance, along with all individual axis instances.

Returns
ndp_status code

◆ ndp_query_pts_new()

ndp_query_pts * ndp_query_pts_new ( void )

Default constructor for ndp_query_pts.

Initializes a new ndp_query_pts instance, sets nelems and naxes to 0, and sets indices, flags, requested, and normed array pointers to NULL.

Returns
Initialized ndp_query_pts instance

◆ ndp_query_pts_new_from_data()

ndp_query_pts * ndp_query_pts_new_from_data ( int nelems,
int naxes,
int * indices,
int * flags,
double * requested,
double * normed )

Constructor for ndp_query_pts from existing data.

Parameters
nelemsNumber of query points
naxesNumber of axes (query point dimension)
indicesFlattened array of parent hypercube indices, of length nelems * naxes
flagsFlattened array of ndp_vertex_flag flags, one for each query point component, of length nelems * naxes
requestedFlattened array of query points (in physical/axis units), of length nelems * naxes
normedFlattened array of hypercube-normalized query points (in grid/tick units), of length nelems * naxes

Initializes a new ndp_query_pts instance, sets nelems and naxes to the provided values, and points the indices, flags, requested, and normed arrays to the provided arrays. Memory for these arrays must be allocated by the caller. Ndpolator treats these arrays as read-only and will not change them. On destruction, the arrays will be freed along with the ndp_query_pts instance.

Returns
Initialized ndp_query_pts instance

◆ ndp_query_pts_alloc()

int ndp_query_pts_alloc ( ndp_query_pts * qpts,
int nelems,
int naxes )

Allocates memory for ndp_query_pts arrays.

Parameters
qptsndp_query_pts instance to allocate memory for
nelemsNumber of query points
naxesNumber of axes (query point dimension)

Allocates memory for the indices, flags, requested, and normed arrays; each array will be of length nelems * naxes.

Returns
ndp_status code

◆ ndp_query_pts_free()

int ndp_query_pts_free ( ndp_query_pts * qpts)

Destructor for ndp_query_pts.

Parameters
qptsndp_query_pts instance to be freed

Frees memory allocated for the ndp_query_pts instance. This includes the indices, flags, requested, and normed arrays.

Returns
ndp_status code

◆ ndp_table_new()

ndp_table * ndp_table_new ( void )

Default constructor for ndp_table.

Initializes a new ndp_table instance, sets vdim to 0, and sets axes, grid, vtree and hctree to NULL.

Returns
Initialized ndp_table instance

◆ ndp_table_new_from_data()

ndp_table * ndp_table_new_from_data ( ndp_axes * axes,
int vdim,
double * grid,
int owns_data )

Constructor for ndp_table from existing data.

Parameters
axesndp_axes instance defining all axes
vdimVertex dimension (function value length)
gridFlattened array holding all function values, in C-native order, of size vdim * nverts
owns_dataFlag indicating if the grid array is owned by self

Initializes a new ndp_table instance from passed data. Note that the function does not copy the arrays, it only assigns pointers to them. Thus, the calling function needs to determine data ownership and pass an allocated copy if the array is (re)used elsewhere. Ndpolator treats all arrays as read-only and will not change them. On destruction, the grid array will be freed only if owns_data is set to true.

This constructor also initializes a private list of all non-nan vertices and fully defined hypercubes in the grid. It does so by traversing the grid and storing their count in a private array. These fields are only used internally by ndpolator for the linear search of nearest neighbors and are likely to be made obsolete in the future.

Returns
Initialized ndp_table instance

◆ ndp_table_free()

int ndp_table_free ( ndp_table * table)

Destructor for ndp_table.

Parameters
tablendp_table instance to be freed

Frees memory allocated for the ndp_table instance. This includes the axes, grid, vtree and hctree arrays. All private structures are also freed.

Returns
ndp_status code

◆ ndp_hypercube_new()

ndp_hypercube * ndp_hypercube_new ( void )

Default constructor for ndp_hypercube.

Initializes a new ndp_hypercube instance, sets dim and vdim to 0, fdhc to 0 (not fully defined), and vertex array v to NULL.

Returns
Initialized ndp_hypercube instance with default values

◆ ndp_hypercube_new_from_data()

ndp_hypercube * ndp_hypercube_new_from_data ( int dim,
int vdim,
int fdhc,
double * v )

Constructor for ndp_hypercube from existing data.

Parameters
dimDimension of the hypercube
vdimFunction value length
fdhcFlag indicating whether hypercube is fully defined
vHypercube vertex function values

Initializes a new ndp_hypercube instance and populates all fields from passed arguments. Note that the function does not copy the array, it only assigns a pointer to it. Thus, the calling function needs to pass an allocated copy if the array is (re)used elsewhere. Ndpolator treats the v array as read-only and it will not change it. On destruction, the v array is freed along with the ndp_hypercube instance.

Returns
Initialized ndp_hypercube instance

◆ ndp_hypercube_alloc()

int ndp_hypercube_alloc ( ndp_hypercube * hc,
int dim,
int vdim )

Allocates memory for ndp_hypercube vertex array.

Parameters
hcndp_hypercube instance to allocate memory for
dimDimension of the hypercube
vdimFunction value length

Allocates memory for the vertex array v, of length vdim * 2^dim. It also sets the dim and vdim fields of the hypercube instance, and sets fdhc to 0 (not fully defined).

Returns
ndp_status code

◆ ndp_hypercube_free()

int ndp_hypercube_free ( ndp_hypercube * hc)

Destructor for ndp_hypercube.

Parameters
hcndp_hypercube instance to be freed

Frees memory allocated for the ndp_hypercube instance. This includes the vertex array v and the ndp_hypercube instance itself.

Returns
ndp_status code

◆ ndp_query_new()

ndp_query * ndp_query_new ( void )

Default constructor for ndp_query.

Initializes a new ndp_query instance, sets nelems to 0, extrapolation_method to NDP_METHOD_NONE, search algorithm to NDP_SEARCH_KDTREE and sets hypercubes, interps, and dists to NULL.

Returns
Initialized ndp_query instance with default values

◆ ndp_query_free()

int ndp_query_free ( ndp_query * query)

Destructor for ndp_query.

Parameters
queryndp_query instance to be freed

Frees memory allocated for the ndp_query instance. This includes the hypercubes, interps, and dists arrays, along with all individual hypercube instances.

Returns
ndp_status code