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
Reshaping vs core_ndim
#218
Comments
Here was my original reasoning: compiling a new gufunc helps because unlike reshaping you can be sure you'll never need to copy the data with the reshape. Then as long as you use NumPy iterators like My thinking has shifted a bit since then. This really only matters in a best case scenario, and in practice I'm not sure these advantages are usually realized. When you start to think about full programs, non-trivial programs in Python usually involve at least a handful of operations that do need full memory copies, so you barely notice the extra copies. Given the way that Numbagg is used to replace specific bottleneck in NumPy code, which generally is not compiled end-to-end, I suspect this is usually the case. The other consideration is that more complex functions may require iterating over data in a more specific order, in which case a copy to speed-up iteration may be a good idea anyways. |
Interesting, and thanks for the quick response. I had been holding that For the moment, we can leave things as they are — no need to shift either approach to the other proactively... |
We use the "new" form in #268, which is required to add additional scalar args such as |
Hi @shoyer!
When you originally wrote the library, you wrote some logic for allowing an arbitrary tuple of axes — the function is recompiled on a change in the number of axes:
numbagg/numbagg/decorators.py
Lines 187 to 205 in da469cc
More recently, we've been doing the simpler thing of just reshaping, calling the gufunc, and then reshaping back if needed. The code is arguably simpler:
numbagg/numbagg/decorators.py
Lines 551 to 557 in 8aac114
What was the rationale for compiling a new gufunc, vs. the reshape? IIUC the reshape is quite cheap. It's also possibly easier to inspect, when debugging. It is less elegant, and to the extent it would be upstream-ed into numba, it's plausibly more general.
Do you have a view of how we should be doing this going forward?
The text was updated successfully, but these errors were encountered: