GalSim-developers/GalSim — pull request #155 by barnabytprowe (2012-05-18 15:42:32+00:00)
Title: #4 - Numerical recipes spline removed from code, now use Mike's TMV, regression tests added

Hi all,

Not a huge pull request. Have finally removed the last bit of NR code, that used to perform cubic spline interpolation. This is used in `src/Interpolate.cpp` to tabulate the k space versions of interpolants that don't have a simple analytic expression (e.g. Cubic, Quintic, Lanczos).

The new algorithm swaps out the crucial calculation of the second derivatives, using Mike's TMV code to perform a fast solution for the symmetric tridiagonal matrix equation rather than the straight recursion relation that the NR code used. The subsequent use of these second derivatives is the same as before, but there's not really much that can be done to alter that small piece of code - it is very straightforward - although any suggestions welcome.

I've added regression tests for Cubic, Quintic and Lanczos (5 & 7), comparing k-Values for an SBInterpolatedImage object (an OpticalPSF in this case) calculated using the new spline code to tabulated values from the old spline code.

On my machine, these agree at numerical precision, which makes me slightly nervous - @gbernstein , have I possibly tested something that doesn't change? `kValue()` return values for SBInterpolatedImage objects are what would be changed by a change in spline, is that correct?

Would be interested to see if this congruence is repeated on others' systems (I put the decimal place for the almost-equal array testing to 14, this might fail on other machines if too ambitious).

Finally, to do these tests I added proper wrappers for the SBProfile `xValue()` and `kValue()` methods to the `GSObject` base class in `base.py`. While I was at it I added/improved some docstrings for these and other generic methods... Sorry for that slightly digressive improvement!