-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow skipna in .dot() #4482
Comments
I agree this would be a welcome option. As a workaround, you could fillna with zero? |
Great, looks like I missed that option. Thanks. For reference, |
Yes that would be very helpful. This is used for the weighted operations: xarray/xarray/core/weighted.py Lines 129 to 135 in 333e8db
and it would be great if this could be done upstream. However, |
I agree this would be welcome! Even if it isn't much faster than the options already shown here, at least we could point users to the best option we know of. I suspect achieving the full speed of |
Any idea why For some functions where |
|
Maybe on very small arrays it's quicker to do a product than a copy? As the array scales, it's surely not — dot product is O(n^3) or similar. I would be interested to see a repro... |
Adding on here, even if This is happening with More evidence in favor: if I do
I'm happy to live with a memory copy for now with |
This is surprising behavior, and definitely sounds like a bug! If you could put together a minimal test case for reproducing the issue, we could look into it. It's hard to say what a work-around would be without knowing the source of the issue. |
See below. I temporarily write some files to netcdf then recombine them lazily using The issue seems to present itself more consistently when my I used the
|
Right — that makes sense now. Given that So I think there's a spectrum of implementations of
The second would be required for @heerad 's case above |
Adding on, whatever the solution is that avoids blowing up memory, especially when using with xarray/xarray/core/weighted.py Line 169 in 333e8db
|
On the topic of fillna(), I'm seeing an odd unrelated issue that I don't have an explanation for. I have a dataarray When I do
Stack trace shows it's failing on a I have no idea how to reproduce this simply... If it helps narrow things down, |
Is your feature request related to a problem? Please describe.
Right now there's no efficient way to do a dot product that skips over nan elements.
Describe the solution you'd like
I want to be able to treat the summation in
dot
as anansum
, controlled by a skipna option. Either this can be implemented directly, or an additional ufunc can be added:xarray.unfuncs.nan_to_num
that can be called on the inputs todot
. Unfortunately using numpy'snan_to_num
will initiate eager execution.Describe alternatives you've considered
It's possible to implement this by hand, but it ends up being extremely inefficient in one of my use-cases:
(x*y).sum('dot_prod_dim', skipna=True)
takes 30 secondsx.dot(y)
takes 1 secondThe text was updated successfully, but these errors were encountered: