-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Faster interp #4740
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
Merged
Merged
Faster interp #4740
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
69dc174
performance improvements for interp with dask
dcherian 02b0a13
2. Call _localize at the Dataset level
dcherian 5c6dab1
3. Set align_arrays=False since we explicitly unify_chunks
dcherian 16f5fa1
4. Create dask coordinate arrays only once.
dcherian 84293a1
5. Access .ndim only once
dcherian bfd8174
add whats-new
dcherian 1546b71
Merge branch 'master' into faster-interp
max-sixty 14ed808
Merge branch 'master' into faster-interp
shoyer a6cd732
bump dask
dcherian f9ef920
Revert "bump dask"
dcherian 27ffc40
Avoid setting meta. Breaks on old dask?
dcherian 577659d
Update xarray/core/missing.py
dcherian 6b90815
lint.
dcherian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2992,17 +2992,38 @@ def _validate_interp_indexer(x, new_x): | |||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||
return x, new_x | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
validated_indexers = { | ||||||||||||||||||||||||||||||||||||||||||
k: _validate_interp_indexer(maybe_variable(obj, k), v) | ||||||||||||||||||||||||||||||||||||||||||
for k, v in indexers.items() | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# optimization: subset to coordinate range of the target index | ||||||||||||||||||||||||||||||||||||||||||
if method in ["linear", "nearest"]: | ||||||||||||||||||||||||||||||||||||||||||
for k, v in validated_indexers.items(): | ||||||||||||||||||||||||||||||||||||||||||
obj, newidx = missing._localize(obj, {k: v}) | ||||||||||||||||||||||||||||||||||||||||||
validated_indexers[k] = newidx[k] | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+2995
to
+3004
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Could do something like this to avoid the mutating loops. |
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# optimization: create dask coordinate arrays once per Dataset | ||||||||||||||||||||||||||||||||||||||||||
# rather than once per Variable when dask.array.unify_chunks is called later | ||||||||||||||||||||||||||||||||||||||||||
# GH4739 | ||||||||||||||||||||||||||||||||||||||||||
if obj.__dask_graph__(): | ||||||||||||||||||||||||||||||||||||||||||
dask_indexers = { | ||||||||||||||||||||||||||||||||||||||||||
k: (index.to_base_variable().chunk(), dest.to_base_variable().chunk()) | ||||||||||||||||||||||||||||||||||||||||||
for k, (index, dest) in validated_indexers.items() | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
variables: Dict[Hashable, Variable] = {} | ||||||||||||||||||||||||||||||||||||||||||
for name, var in obj._variables.items(): | ||||||||||||||||||||||||||||||||||||||||||
if name in indexers: | ||||||||||||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if is_duck_dask_array(var.data): | ||||||||||||||||||||||||||||||||||||||||||
use_indexers = dask_indexers | ||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||
use_indexers = validated_indexers | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if var.dtype.kind in "uifc": | ||||||||||||||||||||||||||||||||||||||||||
var_indexers = { | ||||||||||||||||||||||||||||||||||||||||||
k: _validate_interp_indexer(maybe_variable(obj, k), v) | ||||||||||||||||||||||||||||||||||||||||||
for k, v in indexers.items() | ||||||||||||||||||||||||||||||||||||||||||
if k in var.dims | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
var_indexers = {k: v for k, v in use_indexers.items() if k in var.dims} | ||||||||||||||||||||||||||||||||||||||||||
variables[name] = missing.interp(var, var_indexers, method, **kwargs) | ||||||||||||||||||||||||||||||||||||||||||
elif all(d not in indexers for d in var.dims): | ||||||||||||||||||||||||||||||||||||||||||
# keep unrelated object array | ||||||||||||||||||||||||||||||||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.