Repository navigation
Conversation
np.vectorize looped over all non-core dimensions, although the new coordinates only vary along some of them (GH10683). _interpnd now loops over only those dimensions itself and passes all others to the interpolator in bulk, for numpy and dask arrays alike. The localization and conversion of the coordinates now happens once per call instead of once per loop iteration. Also fix interp with empty new coordinates for the linear and nearest methods. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
It's somehow much uglier than just |
|
I can take a look later. My conclusion a year ago was that there are no real nice solutions without reinventing parts of apply_ufunc. Perhaps there's a vectorization helper for apply-ufunc that we can use here? But this is why i accepted the slowdown for #9881; indeed it was much worse than expected though. |
we can totally construct an interpolator outside the loop no? |
I let Claude benchmark several variations of that and neither showed a clear performance improvement. There are always tradeoffs for small or large arrays while just adding more code boilerplate. |
Thanks! I couln't find any such helper, but thinking about it we could totally turn the new interp code into such a helper. Potentially even add it as a new |
vectorize="shared" only loops over the broadcast dimensions along which more than one input varies and passes all others to func in bulk. interp now uses it instead of its own loop, and localizes and converts datetime coordinates once per call before apply_ufunc. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@dcherian I turned the loop into a helper and added it to [This is Claude Code on behalf of Michael Niklas] |
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tag the cells that fail on purpose with raises-exception so that the notebook is executed in the documentation build again, fix outdated text and links, and print simple values in the numba example. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
⚡ Zoom zoom! Some benchmarks improved.
🚀 better · 🐌 worse · 💥 now failing · 🩹 fixed · 🤷 not comparable Comparing |
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # xarray/core/missing.py
|
@dcherian do you like the new vectorize option? In xarray I didn't find any other usecase for it (most applications are differing only by none or a single dim and there |
Fixes the performance regression from #9881 when the new coordinates vary along a dimension of the interpolated object, e.g.
da[t, r, z].interp(z=new_z[t]).apply_ufunc(..., vectorize="shared"): only loops over the broadcast dimensions along which more than one input varies, all others are passed tofuncin bulk (which must then broadcast its inputs following numpy rules).interpuses it, so it only loops overtinstead oftandrlikenp.vectorize. Works for numpy and dask alike, without changing chunks or the task graph._localizeand the datetime conversion run once per call beforeapply_ufuncinstead of once per loop iteration.method="linear"/"nearest".InterpolationVectorized/InterpolationVectorizedDask.apply_ufuncdocstring examples from basic to advanced, and avectorize="shared"section in the apply_ufunc example notebook, which is executed in the docs build again.vectorize="shared"could also enable multidimensional weights inpolyfit(#9846): loop over the dimensions the weights vary along and solve all other series in onelstsqcall.This is an alternative to #11496, which declares the free dimensions as core dimensions (numpy only).
The remaining gap for
linearcompared to before #9881 comes from the Python loop overt: each iteration builds its own scipy interpolator. Before #9881, the shared dimensions were added as extra interpolation dimensions, which needs merged dask chunks, only works for n-D capable methods with numeric coordinates, and leaks NaNs between slices.whats-new.rstAI Disclosure
🤖 Generated with Claude Code