Cubic Spline Interpolator#719
Conversation
Pull Request Checklist
|
|
@MothNik thanks a lot for taking the time to turn the long stand Github issue into a PR ❤️ I am going to try to reply to all the points you have raised here and in your last comment in the Github issue, I will later do a proper review of the code and provide inline comments:
and seems to fail
probably nothing that will be ever perceived, but just curious 😉 1) not sure what you mean, if I run the code I gave you above with |
|
@mrava87 |
|
Perfect 😄 Do not worry about some of the CI failing, these are problems unrelated to your PR (as long as the doc and main Github action CI passes it is all good...) |
- stripped down `matvec` + `matmat` methods to solely rely on `matvec` - stripped down `reshape`-logic
…ssin.interpspline`
- moved utilities for interpolation to `_interp_utils.py` - fixed floating point rounding error of penultimate sample clipping behaviour for linear interpolation - transitioned `CubicSplineInterpolator` to `InterpCubicSpline` and enriched its docs (1 TODO, Notes missing)
- exposed `InterpCubicSpline` - made clipping logic for penultimate sample more natural by just going via the size of `iava`
- exposed `InterpCubicSpline`
- added `InterpCubicSpline`
- fixed missing naming update for `iava` clipping
- implemented matrix solver for when `dims[axis] == 2` - updated docs for minimum number of samples
- thoroughly tests `InterpCubicSpline` against `scipy.interpolate.CubicSpline`
- added `bc_type` argument to be forwards-compatible with the potential addition for further boundary conditions
- fixed typo
- fixed failing checks introduced with `bc_type`
- made casting to complex more explicit
- used `pytest.params` with `id` to make tests self-documenting without relying on comments - transitioned test specifications to a `dataclass` to avoid typos in key-based access with hard-coded strings - added typing
- removed duplicated code for non-unique `iava`-checks
- check `with pytest.raises` for actual error message - this uncovered a bug in the tests for `Bilinear` that only tested for a `ValueError` being raised in the `iava`-duplicate logic, but this was already raised during the attempt of element duplication in `iava` itself
|
@mrava87 The lines with pytest.raises(ValueError):
iava_rep = iava.copy()
iava_rep[-2] = [0, 0]
iava_rep[-1] = [0, 0]
_, _ = Bilinear(
iava_rep, dims=(par.y_num, par.x_num, par.t_num), dtype=par.dtype
)passed the assertion, but never hit the with pytest.raises(ValueError, match="repeated"):
iava_rep = iava.copy()
iava_rep[-2] = [0, 0]
iava_rep[-1] = [0, 0]
_, _ = Bilinear(
iava_rep, dims=(par.y_num, par.x_num, par.t_num), dtype=par.dtype
)revealed the following > with pytest.raises(ValueError, match="repeated"):
E AssertionError: Regex pattern did not match.
E Expected regex: 'repeated'
E Actual message: 'could not broadcast input array from shape (2,) into shape (10,)'The error happened already in Checking against common exceptions like Altneratively, and probably more readable, one can use something more verbose like with pytest.raises(ValueError) as exception_info:
iava_rep = iava.copy()
iava_rep[-2] = [0, 0]
iava_rep[-1] = [0, 0]
_, _ = Bilinear(
iava_rep, dims=(par.y_num, par.x_num, par.t_num), dtype=par.dtype
)
error_message = str(exception_info.value)
assert "iava" in error_message
assert "repeated" in error message |
- added `References` and `Notes` to `InterpCubicSpline`
- fixed typos and phrasing in documentation of `InterpCubicSpline`
Oh yeah, good catch! I agree, sometimes our with... tests have too generic assertments leading to unexpected behaviors like the one you spotted. I like the second one so we can check multiple words or even partial sentences in the error message 😉 |
|
@MothNik let me know if you have time to make these final changes or if you want me to go ahead and do them before I can merge 😄 |
|
@mrava87 Thanks for the thorough review! |
- made docs of `InterpCubicSpline` jump less back and forth refactor: `signalprocessing.interpspline` - adapted type hint and docs for `dims` for `InterpCubicSpline` - made internal methods and attributes of `InterpCubicSpline` private
- removed `return` after test is done
- made internally used functions private - adapted/added docstrings
- deleted `NumericNDArray` in favour of updating `pylops.utils.typing.NDArray` to only allow for numeric dtypes
- adapted type of `iava` to `SamplingLike`
- deleted wrong brackets in return
- replaced `y` by `x` in computation of `m`
- update version and changelog
|
@mrava87 |
- removed duplicated quote (")
|
There is definitely also some follow-up work to do. The current |
|
Fantastic, I will do one final review but I think this is likely ready to be merged 😄 and yes, if the logic of the LU-decomposition were to move to scipy that would be even better.. for now, happy to host it as part of the spline interpolator |
This pull request aims to close #632 by adding the
kind="cubic_spline"-option topylops.signalprocessing.Interp.It is implemented in a way that can handle 1D-Arrays and 2D-Arrays along a single axis (0 or 1) in a vectorized fashion that heavily reuses pre-computations (optimised to match speed of
kind="linear"while providing similar accuracy askind="sinc"with less oscillations).Currently, only a
numpy-backend is available.