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]YFunction values (range)
[in]XiDomain positions at which to interpolate Y
[in]methodinterpolation type ('N' nearest, 'L' linear, 'C' cubic)
[in]offgridvalue 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]Zfunction values (domain: (0:nx-1,0:ny-1)
[in]XiX domain positions at which to interpolate Z
[in]YiY domain positions at which to interpolate Z
[in]methodinterpolation type ('N' nearest, 'L' linear, 'C' cubic)
[in]offgridvalue assumed when interpolating outside domain (default: af::NaN)
Returns
array same size as Xi and Yi with values interpolated from Z