Intel® MKL 2017 Beta introduces new storage formats for interpolation results array in Data Fitting component
Intel® MKL provides interpolation functions df?Interpolate1D / df?InterpolateEx1D within Data Fitting component. They compute function and derivative values interpolated at each interpolation site for several functions, and all results put into results array r. Storage format of results array r is controlled by parameter rhint.
Intel® MKL 2017 Beta introduces new storage formats corresponding to rhint=DF_MATRIX_STORAGE_SITES_FUNCS_DERS and rhint=DF_MATRIX_STORAGE_SITES_DERS_FUNCS. Below we describe how result r is stored in sequential memory in these new formats.
Let we have yn functions, nder non-zero derivatives in total to interpolate at nsite sites, so size of array r is yn*nder*nsite. Let R(j,s,id) denotes result value for function with index j (0≤j≤yn-1), site with index s (0≤s≤nsite-1), derivative with index id (0≤d≤nder-1). Each line of the following tables is stored in memory contiguously left-to-right.
- When rhint=DF_MATRIX_STORAGE_SITES_FUNCS_DERS:
R(0,0, i0) | R(0,0, i1) | ... | R(0,0, inder-1) |
R(1,0, i0) | R(1,0, i1) | ... | R(1,0, inder-1) |
... | ... | ... | ... |
R(ny-1,0, i0) | R(ny-1,0, i1) | ... | R(ny-1,0, inder-1) |
R(0,1, i0) | R(0,1, i1) | ... | R(0,1, inder-1) |
R(1,1, i0) | R(1,1, i1) | ... | R(1,1, inder-1) |
... | ... | ... | ... |
R(ny-1,1, i0) | R(ny-1,1, i1) | ... | R(ny-1,1, inder-1) |
... | ... | ... | ... |
- When rhint=DF_MATRIX_STORAGE_SITES_DERS_FUNCS:
R(0,0, i0) | R(1,0, i0) | ... | R(ny-1,0, i0) |
R(0,0, i1) | R(1,0, i1) | ... | R(ny-1,0, i1) |
... | ... | ... | ... |
R(0,0, inder-1) | R(1,0, inder-1) | ... | R(ny-1,0, inder-1) |
R(0,1, i0) | R(1,1, i0) | ... | R(ny-1,1, i0) |
R(0,1, i1) | R(1,1, i1) | ... | R(ny-1,1, i1) |
... | ... | ... | ... |
R(0,1, inder-1) | R(1,1, inder-1) | ... | R(ny-1,1, inder-1) |
... | ... | ... | ... |
New formats are suitable for example when dealing with real-argument complex-valued functions. In Data Fitting component, such complex function can be treated as two real functions, real part function and imaginary part function. Complex function value is 2-lenght array, keeping first real and then imaginary part of complex value. The program below demonstrates such example. For simplicity, we interpolate only function values without derivatives, and use DF_MATRIX_STORAGE_SITES_FUNCS_DERS storage format for results.
Example program code (using DF_MATRIX_STORAGE_SITES_FUNCS_DERS format):
#include <stdio.h>
#include "mkl.h"
#define NX 4 // Number of breakpoints
#define NY 2 // Number of real functions (real-part function and imag-part function)
#define nsite 9 // Number of interpolation sites
int main() {
int i,j;
// Breakpoints:
float x[NX] = { 1, 2, 3, 4, };
// Values of two functions at breakpoints, ordered in memory as one complex function values (real0, imag0, real1, imag1, ...):
#define YHINT DF_MATRIX_STORAGE_COLS
float y[NX][NY] = { {20,120}, {30,130}, {20,120}, {30,130} };
// Interpolation sites:
float site[nsite] = { 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 };
// Results, ordered as one complex function values:
#define RHINT DF_MATRIX_STORAGE_SITES_FUNCS_DERS
float r[nsite][NY];
// Reference results, ordered as one complex function values:
float refres[nsite][NY]= { {15,115}, {20,120}, {25,125}, {30,130}, {25,125}, {20,120}, {25,125}, {30,130}, {35,135} };
float scoeff[NY*DF_PP_LINEAR*(NX-1)];
DFTaskPtr task; // Data Fitting task descriptor
MKL_INT ndorder = 1; // size of array describing derivatives
MKL_INT dorder[] = { 1 }; // only function value to calculate
int errcode;
/***** Create Data Fitting task *****/
errcode = dfsNewTask1D(&task, NX,x,DF_NON_UNIFORM_PARTITION, NY,&y[0][0],YHINT);
if(errcode)printf("dfsNewTask1D errcode=%d\n",errcode);
/***** Edit task parameters *****/
errcode = dfsEditPPSpline1D(task, DF_PP_LINEAR, DF_PP_DEFAULT, 0, 0, 0, 0, scoeff, DF_NO_HINT);
if(errcode)printf("dfsEditPPSpline1D errcode=%d\n",errcode);
/***** Construct spline *****/
errcode = dfsConstruct1D(task, DF_PP_SPLINE, DF_METHOD_STD);
if(errcode)printf("dfsConstruct1D errcode=%d\n",errcode);
/***** Interpolate *****/
errcode = dfsInterpolate1D(task, DF_INTERP, DF_METHOD_PP, nsite,site,DF_NO_HINT, ndorder,dorder,0, &r[0][0],RHINT, 0);
if(errcode) { printf("dfsInterpolate1D errcode=%d\n",errcode); }
/***** Print computed results and check with reference results *****/
for(i=0;i<nsite;i++) {
printf("i=%d, site[i]=%f, result ", i, site[i]);
for(j=0;j<NY;j++) {
printf(" func%d[i]=%f", j, r[i][j]);
if(refres[i][j]!=r[i][j]) printf("(ERR: %f expected)",refres[i][j]);
}
printf("\n");
}
/***** Delete Data Fitting task *****/
errcode = dfDeleteTask(&task);
return 0;
}