Skip to content

ENH: new function interp #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ev-br opened this issue Mar 31, 2025 · 7 comments
Open

ENH: new function interp #193

ev-br opened this issue Mar 31, 2025 · 7 comments
Labels
enhancement New feature or request new function

Comments

@ev-br
Copy link
Member

ev-br commented Mar 31, 2025

suggested at scipy/scipy#22343 (comment)

@lucascolley lucascolley changed the title Consider adding np.interp analog ENH: Consider adding np.interp analog Mar 31, 2025
@lucascolley lucascolley added enhancement New feature or request new function labels Mar 31, 2025
@lucascolley
Copy link
Member

first bit of due diligence: https://github.com/data-apis/array-api/issues?q=interp is blank

@rgommers
Copy link
Member

That definitely won't fly as part of the standard.

@lucascolley
Copy link
Member

@ev-br
Copy link
Member Author

ev-br commented Mar 31, 2025

Linear interpolation is certainly possible to write in pure python, here's one implementation (most likely, quite overengineered): https://github.com/scipy/scipy/blob/v1.15.2/scipy/interpolate/_interpolate.py#L457

One np.interp's feature to be careful about is its left and right arguments. Naively they are basically, out[x > x[-1]] = right; out[x < x[0]] = left, so need to take care of immutable arrays.

@lucascolley
Copy link
Member

This sounds like a perfect candidate for a Python implementation in array-api-extra, then, for as long as https://scipy.github.io/devdocs/tutorial/interpolate/1D.html#piecewise-linear-interpolation continues to direct to NumPy.

@lucascolley lucascolley changed the title ENH: Consider adding np.interp analog ENH: new function interp Apr 1, 2025
@lucascolley
Copy link
Member

next question: would interp be the best name @ev-br ? Or is there anything else that is more clear and doesn't clash with existing (semantically-different) functions?

@ev-br
Copy link
Member Author

ev-br commented Apr 1, 2025

IMO, yes.

xpx.pad is a drop-in replacement for np.pad; xpx.kron is a drop-in replacement for np.kron, xpx.interp is a drop-in replacement for np.interp.

The ecosystem is already too crowded with variant functions for linear interpolation, which are almost but not completely unlike each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new function
Projects
None yet
Development

No branches or pull requests

3 participants