From 5182aad6d2efdcfba9f62f2835c9f64a48ec4368 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Fri, 21 Dec 2012 12:39:03 -0500 Subject: oops. fix interpolation for a uniformly sampled function --- chroma/cuda/interpolate.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/chroma/cuda/interpolate.h b/chroma/cuda/interpolate.h index a866272..e7335ba 100644 --- a/chroma/cuda/interpolate.h +++ b/chroma/cuda/interpolate.h @@ -32,19 +32,20 @@ interp(float x, int n, float *xp, float *fp) __device__ float interp_uniform(float x, int n, float x0, float dx, float *fp) { - if (x <= xp[0]) - return xp[0]; + if (x <= x0) + return x0; - if (x >= xp[n-1]) - return xp[n-1]; + float xmax = x0 + dx*(n-1); + + if (x >= xmax) + return xmax; int lower = (x - x0)/dx; int upper = lower + 1; float df = fp[upper] - fp[lower]; - float dx = xp[upper] - xp[lower]; - return fp[lower] + df*(x-xp[lower])/dx; + return fp[lower] + df*(x-(x0+dx*lower))/dx; } #endif -- cgit