-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
numbagg & flox #8233
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
Comments
Supporting numbagg as a backend for flox would be a major win (xarray-contrib/flox#72) particularly because it supports the "group nD array by 1D array" use-case. The pure numpy approach in numpy_groupies requires "group 1D array by other 1D array"; this transformation is a decent chunk of overhead (30-40%). flox does implement a I stalled out on numbagg because of issues around |
Ah interesting. I'm still at 80% of understanding — but to confirm "Form 3" here doesn't do what we need? i.e. the other dimensions are flattened into columns of ![]()
And if flox supports the numba (i.e. not yet numbagg) implementation in numpy_groupies, that doesn't help? (not to be too down on numbagg — I had high hopes for it, and still think it's great, just don't want it to be the 3rd best implementation if someone else does it better...) |
It does do what we need, but numbagg would do it substantially faster (I don't remember numbers off the top of my head, but at least 2X faster?).
I think of groupby with numpy_groupies as 3 steps, a useful rule is these steps take approximately equal amounts of time, though for small problems step 3 can be small-ish (20% of total time).
numpy_groupies uses numba for (3) but a lot of the overhead is in (2), which uses (side note: One of the overheads with flox is that for
I think it is the absolute best for typical Xarray user, just needs some effort around integration. |
Yes very much agree, nicely conceptualized.
Ah interesting, I need to think through this more. I hadn't actually thought (2) was expensive; that it could be done by indexing into an array of N dimensions with a set of 1D indices, like But maybe the data access there isn't great — by aggregating over each group in turn, it's jumping around; and much less efficient relative running through the data linearly, assigning to relevant group. Or maybe I'm completely misunderstanding, thanks for you patience if so... |
This is xarray's "for loop over groups" approach, it can get quite slow. If you have some clever ideas for vectorizing this, that would be amazing! It's also not a simple broadcasting because commonly you're only reducing along one of n dimensions. I did improve numpy_groupies for this (ml31415/numpy-groupies#46) but I remember thinking that numbagg would still be a major win. |
Yes I imagine it's slow for a few reasons:
I had thought that I'll try and come back to this and have a look (though to set expectations, I've probably gone too deep into numbagg for the moment, and so will try and spend a bit less time on it, and predominantly kicking this issue off to see if we could reduce its scope!) |
@dcherian is there an issue describing what is missing from numbagg to use it in flox? |
Here's a few: numbagg/numbagg#120, numbagg/numbagg#121, numbagg/numbagg#122 and an updated test run from EDIT: Well apparently I fixed the |
This may well be complete, at least for the moment, WDYT @dcherian ? |
Yes many thanks Max. It'll be possible to use In my tests it's approx 2X improvement (because |
Just released flox v0.8.0. Here are some benchmarks for grouping a 2D array by a 1D array. Great work, Max!
|
That's awesome! Thanks for doing the hard work — my part was relatively easy... And I'm excited that numbagg has the resurgence it deserves after some hibernation — thanks to @shoyer for the hard work there a few years ago... |
Wow, nice work both of you! |
What is your issue?
I've been doing some work recently on our old friend numbagg, improving the ewm routines & adding some more.
I'm keen to get numbagg back in shape, doing the things that it does best, and trimming anything it doesn't. I notice that it has grouped calcs. Am I correct to think that flox does this better? I haven't been up with the latest. flox looks like it's particularly focused on dask arrays, whereas numpy_groupies, one of the inspirations for this, was applicable to numpy arrays too.
At least from the xarray perspective, are we OK to deprecate these numbagg functions, and direct folks to flox?
The text was updated successfully, but these errors were encountered: