Cubic spline evaluation function.
[dyp [,dyp1 [,dyp2 [,dyp3]]]] = gpuInterp(xp, x, y, d [, out_mode])
Can be :
Real vector or matrix stored in device memory (GPU).
Real vector or matrix stored in host memory (CPU).
Real vector or matrix of same size defining a cubic spline or sub-spline function.(called s
in the following)
x must be strictly increasing and a size more or equal to 2.
These parameters can be stored in host memory (CPU) or in device memory (GPU).
String defining the evaluation of s
outside the [x1,xn] interval. (optional)
Vector or matrix of same size than xp
, elementwise evaluation of s
on xp
(yp(i)=s(xp(i) or yp(i,j)=s(xp(i,j)).
dyp is stored on device memory (GPU)
Vectors or matrices of same size than xp
, elementwise evaluation of the successive derivatives of s
on xp
.
dyp1, dyp2, dyp3 are stored on device memory (GPU)
gpuInterp
performs the same operation as Scilab function interp.
The out_mode argument is the same as the Scilab function interp.
// An example showing C2 and C1 continuity of spline and subspline a = -8; b = 8; x = linspace(a,b,20)'; y = sinc(x); dk = splin(x,y); // not_a_knot df = splin(x,y, "fast"); xx = linspace(a,b,800)'; [yyk, yy1k, yy2k] = interp(xx, x, y, dk); [yyf, yy1f, yy2f] = interp(xx, x, y, df); [dyyk, dyy1k, dyy2k] = gpuInterp(xx, x, y, dk); [dyyf, dyy1f, dyy2f] = gpuInterp(xx, x, y, df); // display host result clf() subplot(3,2,1) plot2d(xx, [yyk yyf]) plot2d(x, y, style=-9) legends(["not_a_knot spline","fast sub-spline","interpolation points"],... [1 2 -9], "ur",%f) xtitle("spline interpolation CPU") subplot(3,2,3) plot2d(xx, [yy1k yy1f]) legends(["not_a_knot spline","fast sub-spline"], [1 2], "ur",%f) xtitle("spline interpolation (derivatives) CPU") subplot(3,2,5) plot2d(xx, [yy2k yy2f]) legends(["not_a_knot spline","fast sub-spline"], [1 2], "lr",%f) xtitle("spline interpolation (second derivatives) CPU") // display device result subplot(3,2,2) plot2d(xx, [gpuGetData(dyyk) gpuGetData(dyyf)]) plot2d(x, y, style=-9) legends(["not_a_knot spline","fast sub-spline","interpolation points"],... [1 2 -9], "ur",%f) xtitle("spline interpolation GPU") subplot(3,2,4) plot2d(xx, [gpuGetData(dyy1k) gpuGetData(dyy1f)]) legends(["not_a_knot spline","fast sub-spline"], [1 2], "ur",%f) xtitle("spline interpolation (derivatives) GPU") subplot(3,2,6) plot2d(xx, [gpuGetData(dyy2k) gpuGetData(dyy2f)]) legends(["not_a_knot spline","fast sub-spline"], [1 2], "lr",%f) xtitle("spline interpolation (second derivatives) GPU") gpuFree(dyyk); gpuFree(dyy1k); gpuFree(dyy2k); gpuFree(dyyf); gpuFree(dyy1f); gpuFree(dyy2f); // here is an example showing the different extrapolation possibilities x = linspace(0,1,11)'; y = cosh(x-0.5); d = splin(x,y); xx = linspace(-0.5,1.5,401)'; yy0 = interp(xx,x,y,d,"C0"); yy1 = interp(xx,x,y,d,"linear"); yy2 = interp(xx,x,y,d,"natural"); yy3 = interp(xx,x,y,d,"periodic"); dyy0 = gpuInterp(xx,x,y,d,"C0"); dyy1 = gpuInterp(xx,x,y,d,"linear"); dyy2 = gpuInterp(xx,x,y,d,"natural"); dyy3 = gpuInterp(xx,x,y,d,"periodic"); clf() subplot(2,1,1) plot2d(xx,[yy0 yy1 yy2 yy3],style=2:5,frameflag=2,leg="C0@linear@natural@periodic") xtitle(" different way to evaluate a spline outside its domain computed on host (CPU)") subplot(2,1,2) plot2d(xx,[gpuGetData(dyy0) gpuGetData(dyy1) gpuGetData(dyy2) gpuGetData(dyy3)],style=2:5,frameflag=2,leg="C0@linear@natural@periodic") xtitle(" different way to evaluate a spline outside its domain computed on device (GPU)") gpuFree(dyy0); gpuFree(dyy1); gpuFree(dyy2); gpuFree(dyy3); | ![]() | ![]() |