21#include <lal/cubic_interp.h>
22#include <gsl/gsl_test.h>
23#include <gsl/gsl_math.h>
25#include <lal/XLALError.h>
28#define UNUSED __attribute__ ((unused))
34int main(
int UNUSED argc,
char UNUSED **argv)
37 static const double data[] = {0, 0, 0, 0};
40 for (
double t = 0; t <= 1; t += 0.01)
43 const double expected = 0;
44 gsl_test_abs(result, expected, 0,
45 "testing cubic interpolant for zero input");
51 static const double data[] = {1, 1, 1, 1};
54 for (
double t = 0; t <= 1; t += 0.01)
57 const double expected = 1;
58 gsl_test_abs(result, expected, 0,
59 "testing cubic interpolant for unit input");
65 static const double data[] = {1, 0, 1, 4};
68 for (
double t = 0; t <= 1; t += 0.01)
71 const double expected = gsl_pow_2(t);
72 gsl_test_abs(result, expected, 10 * GSL_DBL_EPSILON,
73 "testing cubic interpolant for quadratic input");
79 static const double data[] = {
80 GSL_POSINF, GSL_POSINF, GSL_POSINF, GSL_POSINF};
83 for (
double t = 0; t <= 1; t += 0.01)
86 const double expected = GSL_POSINF;
87 gsl_test_abs(result, expected, 0,
88 "testing cubic interpolant for +inf input");
94 static const double data[] = {
95 0, GSL_POSINF, GSL_POSINF, GSL_POSINF};
98 for (
double t = 0; t <= 1; t += 0.01)
101 const double expected = GSL_POSINF;
102 gsl_test_abs(result, expected, 0,
103 "testing cubic interpolant for +inf input");
109 static const double data[] = {
110 GSL_POSINF, GSL_POSINF, GSL_POSINF, 0};
113 for (
double t = 0; t <= 1; t += 0.01)
116 const double expected = GSL_POSINF;
117 gsl_test_abs(result, expected, 0,
118 "testing cubic interpolant for +inf input");
124 static const double data[] = {
125 0, GSL_POSINF, GSL_POSINF, 0};
128 for (
double t = 0; t <= 1; t += 0.01)
131 const double expected = GSL_POSINF;
132 gsl_test_abs(result, expected, 0,
133 "testing cubic interpolant for +inf input");
139 static const double data[] = {
140 0, 0, GSL_POSINF, 0};
143 for (
double t = 0.01; t <= 1; t += 0.01)
146 const double expected = 0;
147 gsl_test_abs(result, expected, 0,
148 "testing cubic interpolant for +inf input");
154 static const double data[] = {
155 0, GSL_NEGINF, GSL_POSINF, 0};
160 const double expected = GSL_POSINF;
161 gsl_test_abs(result, expected, 0,
162 "testing cubic interpolant for +inf input");
166 static const double data[] = {
167 0, GSL_POSINF, GSL_NEGINF, 0};
172 const double expected = GSL_POSINF;
173 gsl_test_abs(result, expected, 0,
174 "testing cubic interpolant for +inf input");
178 static const double data[] = {
179 0, GSL_NEGINF, GSL_NEGINF, GSL_NEGINF};
182 for (
double t = 0; t <= 1; t += 0.01)
185 const double expected = GSL_NEGINF;
186 gsl_test_abs(result, expected, 0,
187 "testing cubic interpolant for -inf input");
193 static const double data[] = {
194 GSL_NEGINF, GSL_NEGINF, GSL_NEGINF, 0};
197 for (
double t = 0; t <= 1; t += 0.01)
200 const double expected = GSL_NEGINF;
201 gsl_test_abs(result, expected, 0,
202 "testing cubic interpolant for -inf input");
208 static const double data[] = {
209 0, GSL_NEGINF, GSL_NEGINF, 0};
212 for (
double t = 0; t <= 1; t += 0.01)
215 const double expected = GSL_NEGINF;
216 gsl_test_abs(result, expected, 0,
217 "testing cubic interpolant for -inf input");
223 static const double data[] = {
224 0, 0, GSL_NEGINF, 0};
227 for (
double t = 0.01; t <= 1; t += 0.01)
230 const double expected = 0;
231 gsl_test_abs(result, expected, 0,
232 "testing cubic interpolant for -inf input");
238 static const double data[] = {
239 0, GSL_NEGINF, GSL_POSINF, 0};
244 const double expected = GSL_NEGINF;
245 gsl_test_abs(result, expected, 0,
246 "testing cubic interpolant for -inf input");
250 static const double data[] = {
251 0, GSL_POSINF, GSL_NEGINF, 0};
256 const double expected = GSL_NEGINF;
257 gsl_test_abs(result, expected, 0,
258 "testing cubic interpolant for -inf input");
262 static const double data[] = {
263 0, GSL_NEGINF, GSL_POSINF, 0};
266 for (
double t = 0.01; t < 1; t += 0.01)
269 const double expected = GSL_NEGINF;
270 gsl_test_abs(result, expected, 0,
271 "testing cubic interpolant for indeterminate input");
278 static const double constants[] = {
279 0, 1, GSL_POSINF, GSL_NEGINF, GSL_NAN};
280 for (
unsigned k = 0;
k <
sizeof(constants) /
sizeof(*constants);
k ++)
283 for (
int i = 0;
i < 4;
i ++)
284 for (
int j = 0;
j < 4;
j ++)
287 *
data, 4, 4, -1, -1, 1, 1);
288 for (
double s = -5;
s <= 2;
s += 0.1)
290 for (
double t = -5; t <= 1; t += 0.1)
293 const double expected = constants[
k];
294 gsl_test_abs(result, expected, 0,
295 "testing bicubic interpolant for constant %g input",
304 for (
int k = 1;
k < 3;
k ++)
308 for (
int i = 0;
i < 4;
i ++)
309 for (
int j = 0;
j < 4;
j ++)
312 *
data, 4, 4, -1, -1, 1, 1);
313 for (
double s = 0;
s <= 1;
s += 0.1)
315 for (
double t = 0; t <= 1; t += 0.1)
318 const double expected = gsl_pow_int(
s,
k);
319 gsl_test_abs(result, expected, 10 * GSL_DBL_EPSILON,
320 "testing bicubic interpolant for s^%d input",
k);
329 for (
int i = 0;
i < 4;
i ++)
330 for (
int j = 0;
j < 4;
j ++)
333 *
data, 4, 4, -1, -1, 1, 1);
334 for (
double s = 0;
s <= 1;
s += 0.1)
336 for (
double t = 0; t <= 1; t += 0.1)
339 const double expected = gsl_pow_int(t,
k);
340 gsl_test_abs(result, expected, 10 * GSL_DBL_EPSILON,
341 "testing bicubic interpolant for t^%d input",
k);
350 for (
int i = 0;
i < 4;
i ++)
351 for (
int j = 0;
j < 4;
j ++)
352 data[
i][
j] = gsl_pow_int(
i - 1,
k) + gsl_pow_int(
j - 1,
k);
354 *
data, 4, 4, -1, -1, 1, 1);
355 for (
double s = 0;
s <= 1;
s += 0.1)
357 for (
double t = 0; t <= 1; t += 0.1)
360 const double expected = gsl_pow_int(
s,
k)
362 gsl_test_abs(result, expected, 10 * GSL_DBL_EPSILON,
363 "testing bicubic interpolant for s^%d + t^%d input",
372 return gsl_test_summary();
bicubic_interp * bicubic_interp_init(const double *data, int ns, int nt, double smin, double tmin, double ds, double dt)
void cubic_interp_free(cubic_interp *interp)
void bicubic_interp_free(bicubic_interp *interp)
double bicubic_interp_eval(const bicubic_interp *interp, double s, double t)
cubic_interp * cubic_interp_init(const double *data, int n, double tmin, double dt)
double cubic_interp_eval(const cubic_interp *interp, double t)
#define XLAL_CHECK_EXIT(assertion)
int main(int UNUSED argc, char UNUSED **argv)