 Documentation
approx

C++ interface for Interpolation. More...

 array approx1 (const array &Y, const array &Xi, char method='L', float offgrid=af::NaN) Interpolation in one dimension (1D). More... array approx2 (const array &Z, const array &Xi, const array &Yi, char method='L', float offgrid=af::NaN) Interpolation in two dimensions (2D): z=f(x,y) More...

## Detailed Description

C++ interface for Interpolation.

approx1 and approx2 perform interpolation on data in one and two dimensions, respectively. These methods have three options for the type of interpolation to perform—nearest neighbor, linear interpolation, and cubic interpolation.

1D Example:

// Pass the values to arrayfire
float h_Y[] = {0,1,2,3,4,5,6};
array Y = array(7,h_Y);
// Interpolate for the following
float h_Xi[] = {1.2, 1.4, 1.6, 4, 700};
array Xi = array(5,h_Xi);
// Perform interpolation
array Yi = approx1(Y, // Original sample data
Xi, // locations for interpolation
'L'); // linear interpolation
print(Yi);
// Yi =
// 1.2000
// 1.4000
// 1.6000
// 4.0000
// nan

2D Example:

float h_data[] = { 0.00, // (0,0)
0.10, // (1,0)
0.20, // (2,0)
0.01, // (0,1)
0.11, // (1,1)
0.21 // (2,1)
};
// Interpolate for the following
float h_Xirange[] = {1.2, 1.4, 1.6};
float h_Yirange[] = {0.3, 0.4, 0.6, 0.7};
// Pass the values to arrayfire
array data = array(3,2, h_data);
// Create a 2D grid from the 1D range vectors
array Xi = tile(array(3, 1, h_Xirange), 1, 4);
array Yi = tile(array(1, 4, h_Yirange), 3, 1);
// Perform interpolation
array result = approx2(data, // Original sample data
Xi, Yi, // locations for interpolation
'L'); // linear interpolation
print(result);
// result =
// 0.1230 0.1240 0.1260 0.1270
// 0.1430 0.1440 0.1460 0.1470
// 0.1630 0.1640 0.1660 0.1670

## Function Documentation

 array af::approx1 ( const array & Y, const array & Xi, char method = 'L', float offgrid = af::NaN )

Interpolation in one dimension (1D).

Parameters
 [in] Y Function values (range) [in] Xi Domain positions at which to interpolate Y [in] method interpolation type ('N' nearest, 'L' linear, 'C' cubic) [in] offgrid value assumed when interpolating outside domain (default: af::NaN)
Returns
array same size as Xi with values interpolated from Y
 array af::approx2 ( const array & Z, const array & Xi, const array & Yi, char method = 'L', float offgrid = af::NaN )

Interpolation in two dimensions (2D): z=f(x,y)

Parameters
 [in] Z function values (domain: (0:nx-1,0:ny-1) [in] Xi X domain positions at which to interpolate Z [in] Yi Y domain positions at which to interpolate Z [in] method interpolation type ('N' nearest, 'L' linear, 'C' cubic) [in] offgrid value assumed when interpolating outside domain (default: af::NaN)
Returns
array same size as Xi and Yi with values interpolated from Z