QL.info("Testing use of interpolations as functors...");
final Array x = new Array(new double[] { 0.0, 1.0, 2.0, 3.0, 4.0 });
final Array y = new Array(new double[] { 5.0, 4.0, 3.0, 2.0, 1.0 });
final Interpolation f = new LinearInterpolation(x, y);
f.update();
final Array x2 = new Array(new double[] { -2.0, -1.0, 0.0, 1.0, 3.0, 4.0, 5.0, 6.0, 7.0 });
final int N = x2.size();
final double tolerance = 1.0e-12;
// case 1: extrapolation not allowed
try {
final Array y2 = x2.clone().transform(f);
System.out.println(y2);
throw new NotThrown();
} catch (final NotThrown ex) {
throw new LibraryException("failed to throw exception when trying to extrapolate");
} catch (final Exception ex) {
// as expected, we are OK.
System.out.println(ex);
}
// case 2: enable extrapolation
f.enableExtrapolation();
final Array y2 = x2.clone().transform(f);
System.out.println(y2);
for (int i=0; i<N-1; i++) {
final double expected = 5.0 - x2.get(i);
final double calculated = y2.get(i);