ArrayFire: approx1 (original) (raw)
Interpolation across a single dimension. More...
| Functions | |
|---|---|
| AFAPI array | approx1 (const array &in, const array &pos, const interpType method=AF_INTERP_LINEAR, const float off_grid=0.0f) |
| C++ Interface for data interpolation on one-dimensional signals. More... | |
| AFAPI array | approx1 (const array &in, const array &pos, const int interp_dim, const double idx_start, const double idx_step, const interpType method=AF_INTERP_LINEAR, const float off_grid=0.0f) |
| C++ Interface for data interpolation on one-dimensional signals. More... | |
| AFAPI af_err | af_approx1 (af_array *out, const af_array in, const af_array pos, const af_interp_type method, const float off_grid) |
| C Interface for signals interpolation on one dimensional signals. More... | |
| AFAPI af_err | af_approx1_v2 (af_array *out, const af_array in, const af_array pos, const af_interp_type method, const float off_grid) |
| C Interface for the version of af_approx1 that accepts a preallocated output array. More... | |
| AFAPI af_err | af_approx1_uniform (af_array *out, const af_array in, const af_array pos, const int interp_dim, const double idx_start, const double idx_step, const af_interp_type method, const float off_grid) |
| C Interface for signals interpolation on one dimensional signals along specified dimension. More... | |
| AFAPI af_err | af_approx1_uniform_v2 (af_array *out, const af_array in, const af_array pos, const int interp_dim, const double idx_start, const double idx_step, const af_interp_type method, const float off_grid) |
| C Interface for the version of af_approx1_uniform that accepts a preallocated output array. More... | |
Interpolation across a single dimension.
Performs interpolation on data along a single dimension.
Interpolation is the process of computing for unknown values within a continuous range described by a discrete set of known values. These known values (in) correspond to a uniformly-spaced range of indices determined by start and step values, whose defaults are 0.0 and 1.0, respectively.
The positions array (pos) contains the interpolating points (indices whose values we want to find) along a given dimension. Values of known indices will be looked up in the input array, while values of unknown indices will be found via interpolation. Indices outside of the index range are not extrapolated. Instead, those values are set off_grid, whose default value is 0.0.
The following image illustrates a simple example (known values represented by blue dots, unknown values represented by red dots):

approx1() using idx_start=0.0, idx_step=1.0
Several interpolation methods are supported by approx1:
- Nearest neighbor interpolation - AF_INTERP_NEAREST
- Linear interpolation (default) - AF_INTERP_LINEAR, AF_INTERP_LINEAR_COSINE
- Cubic interpolation - AF_INTERP_CUBIC, AF_INTERP_CUBIC_SPLINE
- Lower interpolation - AF_INTERP_LOWER
Unless specified, linear interpolation is performed by default. Refer to af_interp_type for more information about ArrayFire's interpolation types.
◆ af_approx1()
C Interface for signals interpolation on one dimensional signals.
Parameters
| [out] | out | is the interpolated array. |
|---|---|---|
| [in] | in | is the multidimensional input array. Values assumed to lie uniformly spaced indices in the range of [0, n), where n is the number of elements in the array. |
| [in] | pos | positions of the interpolation points along the first dimension. |
| [in] | method | is the interpolation method to be used. The following types (defined in enum af_interp_type) are supported: nearest neighbor, linear, and cubic. |
| [in] | off_grid | is the default value for any indices outside the valid range of indices. |
Returns
AF_SUCCESS if the interpolation operation is successful, otherwise an appropriate error code is returned.
◆ af_approx1_uniform()
C Interface for signals interpolation on one dimensional signals along specified dimension.
af_approx1_uniform() accepts the dimension to perform the interpolation along the input. It also accepts start and step values which define the uniform range of corresponding indices.
The following image illustrates what the range of indices corresponding to the input values look like if idx_start and idx_step are set to an arbitrary value of 10,

approx1() using idx_start=10.0, idx_step=10.0
The blue dots represent indices whose values are known. The red dots represent indices whose values are unknown.
Parameters
| [out] | out | the interpolated array. |
|---|---|---|
| [in] | in | is the multidimensional input array. Values lie on uniformly spaced indices determined by idx_start and idx_step. |
| [in] | pos | positions of the interpolation points along interp_dim. |
| [in] | interp_dim | is the dimension to perform interpolation across. |
| [in] | idx_start | is the first index value along interp_dim. |
| [in] | idx_step | is the uniform spacing value between subsequent indices along interp_dim. |
| [in] | method | is the interpolation method to be used. The following types (defined in enum af_interp_type) are supported: nearest neighbor, linear, and cubic. |
| [in] | off_grid | is the default value for any indices outside the valid range of indices. |
Returns
AF_SUCCESS if the interpolation operation is successful, otherwise an appropriate error code is returned.
◆ af_approx1_uniform_v2()
C Interface for the version of af_approx1_uniform that accepts a preallocated output array.
Parameters
| [in,out] | out | the interpolated array (can be preallocated). |
|---|---|---|
| [in] | in | is the multidimensional input array. Values lie on uniformly spaced indices determined by idx_start and idx_step. |
| [in] | pos | positions of the interpolation points along interp_dim. |
| [in] | interp_dim | is the dimension to perform interpolation across. |
| [in] | idx_start | is the first index value along interp_dim. |
| [in] | idx_step | is the uniform spacing value between subsequent indices along interp_dim. |
| [in] | method | is the interpolation method to be used. The following types (defined in enum af_interp_type) are supported: nearest neighbor, linear, and cubic. |
| [in] | off_grid | is the default value for any indices outside the valid range of indices. |
Returns
AF_SUCCESS if the interpolation operation is successful, otherwise an appropriate error code is returned.
Note
out can either be a null or existing af_array object. If it is a sub-array of an existing af_array, only the corresponding portion of the af_array will be overwritten
Passing an af_array to out that has not been initialized will cause undefined behavior.
◆ af_approx1_v2()
C Interface for the version of af_approx1 that accepts a preallocated output array.
Parameters
| [in,out] | out | is the interpolated array (can be preallocated). |
|---|---|---|
| [in] | in | is the multidimensional input array. Values assumed to lie uniformly spaced indices in the range of [0, n), where n is the number of elements in the array. |
| [in] | pos | positions of the interpolation points along the first dimension. |
| [in] | method | is the interpolation method to be used. The following types (defined in enum af_interp_type) are supported: nearest neighbor, linear, and cubic. |
| [in] | off_grid | is the default value for any indices outside the valid range of indices. |
Returns
AF_SUCCESS if the interpolation operation is successful, otherwise an appropriate error code is returned.
Note
out can either be a null or existing af_array object. If it is a sub-array of an existing af_array, only the corresponding portion of the af_array will be overwritten
Passing an af_array that has not been initialized to out will cause undefined behavior.
◆ approx1() [1/2]
C++ Interface for data interpolation on one-dimensional signals.
The following version of approx1() accepts the dimension to perform the interpolation along the input. It also accepts start and step values which define the uniform range of corresponding indices.
The following image illustrates what the range of indices corresponding to the input values look like if idx_start and idx_step are set to an arbitrary value of 10,

approx1() using idx_start=10.0, idx_step=10.0
The blue dots represent indices whose values are known. The red dots represent indices whose values are unknown.
Parameters
| [in] | in | is the multidimensional input array. Values lie on uniformly spaced indices determined by idx_start and idx_step. |
|---|---|---|
| [in] | pos | positions of the interpolation points along interp_dim. |
| [in] | interp_dim | is the dimension to perform interpolation across. |
| [in] | idx_start | is the first index value along interp_dim. |
| [in] | idx_step | is the uniform spacing value between subsequent indices along interp_dim. |
| [in] | method | is the interpolation method to be used. The following types (defined in enum af_interp_type) are supported: nearest neighbor, linear, and cubic. |
| [in] | off_grid | is the default value for any indices outside the valid range of indices. |
Returns
the interpolated array.
The code sample below demonstrates usage:
float input_vals[9] = {10.0f, 20.0f, 30.0f, 40.0f, 50.0f,
60.0f, 70.0f, 80.0f, 90.0f};
array in(dim4(3, 3), input_vals);
float pv[5] = {0.0f, 0.5, 1.0f, 1.5f, 2.0f};
array pos(dim4(5, 1), pv);
const double idx_start = 0.0;
const double idx_step = 1.0;
int interp_dim = 0;
array col_major_interp = approx1(in, pos, interp_dim, idx_start, idx_step);
interp_dim = 1;
array row_major_interp =
AFAPI array transpose(const array &in, const bool conjugate=false)
C++ Interface to transpose a matrix.
AFAPI array approx1(const array &in, const array &pos, const interpType method=AF_INTERP_LINEAR, const float off_grid=0.0f)
C++ Interface for data interpolation on one-dimensional signals.
◆ approx1() [2/2]
C++ Interface for data interpolation on one-dimensional signals.
Parameters
| [in] | in | is the multidimensional input array. Values assumed to lie uniformly spaced indices in the range of [0, n), where n is the number of elements in the array. |
|---|---|---|
| [in] | pos | positions of the interpolation points along the first dimension. |
| [in] | method | is the interpolation method to be used. The following types (defined in enum af_interp_type) are supported: nearest neighbor, linear, and cubic. |
| [in] | off_grid | is the default value for any indices outside the valid range of indices. |
Returns
the interpolated array.
The code sample below demonstrates approx1()'s usage:
float input_vals[3] = {10.0f, 20.0f, 30.0f};
array in(dim4(3, 1), input_vals);
float pv[5] = {0.0f, 0.5, 1.0f, 1.5, 2.0f};
array pos(dim4(5, 1), pv);
array interp = approx1(in, pos);