jax-ml / jax

Composable transformations of Python+NumPy programs: differentiate, vectorize, JIT to GPU/TPU, and more
http://jax.readthedocs.io/
Apache License 2.0
29.98k stars 2.75k forks source link

Implementation of `scipy.signal.savgol_filter` (or at least `scipy.signal.savgol_coeffs`). #12224

Open tnecniv opened 2 years ago

tnecniv commented 2 years ago

Please:


Hello,

On a recent project, I had to implement the Savitzky-Golay filter in code that needed to run efficiently — i.e., it needed to be JIT-compiled and run repeatedly, not just used for post-processing in which case the SciPy function would suffice. This is a popular filter for a variety of applications, particularly ones in Analytic Chemistry (to my understanding, I am not a chemist).

I was able to port the SciPy implementation of scipy.signal.savgol_coeffs, which handles the bulk of the filtering algorithm, to JAX easily. Matching the API of scipy.signal.savgol_filter would take some additional work to handle the different ways it permits handling the boundaries of the signal.

I'm happy to contribute my JAX implementation of scipy.signal.savgol_coeffs to build out the on-going port of SciPy's functionality to JAX and, when I have time, port scipy.signal.savgol_filter properly as well. However, I wanted to open an issue before simply issuing a pull request.

apaszke commented 2 years ago

Thanks for checking in! Those two functions definitely seem in scope of what jax.scipy so we'd welcome a PR!

hawkinsp commented 2 years ago

One note: if you have ported/copied scipy code rather than rewriting the algorithm from scratch yourself, the implementation must go in https://github.com/google/jax/tree/main/jax/_src/third_party/scipy