-
-
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
weighted operations: performance optimisations #3883
Comments
maybe relevant: #1995 |
%load_ext line_profiler
import numpy as np
import xarray as xr
from xarray.core.weighted import Weighted as w
shape_weights = (1000, 1000)
shape_data = (1000, 1000, 10)
add_nans = False
def lprun_weighted(shape_weights, shape_data, add_nans, skipna=None):
weights = xr.DataArray(np.random.randn(*shape_weights))
data = np.random.randn(*shape_data)
# add approximately 25 % NaNs
if add_nans:
c = int(data.size * 0.25)
data.ravel()[np.random.choice(data.size, c, replace=False)] = np.NaN
data = xr.DataArray(data)
return data.weighted(weights).mean(skipna=skipna)
%lprun -f w._reduce -f w._weighted_mean -f w._sum_of_weights -f w._weighted_sum -f w.__init__ -f lprun_weighted -u 1e-03 lprun_weighted(shape_weights, shape_data, add_nans, skipna=None) |
xarray/xarray/core/weighted.py Line 143 in d1f7cb8
and xarray/xarray/core/weighted.py Line 130 in d1f7cb8
|
There was a discussion on the performance of the weighted mean/ sum in terms of memory footprint but also speed, and there may indeed be some things that can be optimized. See the posts at the end of the PR. However, the optimal implementation will probably depend on the use case and some profiling will be required.
I'll just open an issue to keep track of this.
@seth-p
The text was updated successfully, but these errors were encountered: