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

## Detailed Description

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:

Unless specified, linear interpolation is performed by default. Refer to af_interp_type for more information about ArrayFire's interpolation types.

## ◆ af_approx1()

 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.

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

 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.

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

 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.

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

 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.

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]

 AFAPI array af::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.

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:

// Input data array.
float input_vals[3] = {10.0f, 20.0f, 30.0f};
array in(dim4(3, 1), input_vals);
// [3 1 1 1]
// 10.0000
// 20.0000
// 30.0000
// Array of positions to be found along the first dimension.
float pv[5] = {0.0f, 0.5, 1.0f, 1.5, 2.0f};
array pos(dim4(5, 1), pv);
// [5 1 1 1]
// 0.0000
// 0.5000
// 1.0000
// 1.5000
// 2.0000
// Perform interpolation across dimension 0.
array interp = approx1(in, pos);
// [5 1 1 1]
// 10.0000
// 15.0000
// 20.0000
// 25.0000
// 30.0000

## ◆ approx1() [2/2]

 AFAPI array af::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.

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);
// [3 3 1 1]
// 10.0000 40.0000 70.0000
// 20.0000 50.0000 80.0000
// 30.0000 60.0000 90.0000
// Array of positions to be found along the interpolation
// dimension, interp_dim.
float pv[5] = {0.0f, 0.5, 1.0f, 1.5f, 2.0f};
array pos(dim4(5, 1), pv);
// [5 1 1 1]
// 0.0000
// 0.5000
// 1.0000
// 1.5000
// 2.0000
// Define range of indices with which the input values will
// correspond along the interpolation dimension.
const double idx_start = 0.0;
const double idx_step = 1.0;
// Perform interpolation across dimension 0.
int interp_dim = 0;
array col_major_interp = approx1(in, pos, interp_dim, idx_start, idx_step);
// [5 3 1 1]
// 10.0000 40.0000 70.0000
// 15.0000 45.0000 75.0000
// 20.0000 50.0000 80.0000
// 25.0000 55.0000 85.0000
// 30.0000 60.0000 90.0000
// Perform interpolation across dimension 1.
interp_dim = 1;
array row_major_interp =
approx1(in, transpose(pos), interp_dim, idx_start, idx_step);
// [3 5 1 1]
// 10.0000 25.0000 40.0000 55.0000 70.0000
// 20.0000 35.0000 50.0000 65.0000 80.0000
// 30.0000 45.0000 60.0000 75.0000 90.0000