-
-
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
Indexing benchmarking #1851
Merged
Merged
Indexing benchmarking #1851
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
59f9d99
Start adding benchmarking for basic operations.
fujiisoup 8ab3796
Merge branch 'master' into benchmark_indexing
fujiisoup 336e488
Update indexing.py
fujiisoup dbe2864
Benchmark for indexing.
fujiisoup c03b002
Make it a class.
fujiisoup 755f507
Add key to setup
fujiisoup 57da6e5
Use seed in randn and randint. Fix bug in dask benchmark
fujiisoup 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 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 |
---|---|---|
|
@@ -34,6 +34,9 @@ nosetests.xml | |
.cache | ||
.ropeproject/ | ||
|
||
# asv environments | ||
.asv | ||
|
||
# Translations | ||
*.mo | ||
|
||
|
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import xarray as xr | ||
|
||
from . import randn, randint, requires_dask | ||
|
||
|
||
nx = 3000 | ||
ny = 2000 | ||
nt = 1000 | ||
|
||
basic_indexes = { | ||
'1slice': {'x': slice(0, 3)}, | ||
'1slice-1scalar': {'x': 0, 'y': slice(None, None, 3)}, | ||
'2slicess-1scalar': {'x': slice(3, -3, 3), 'y': 1, 't': slice(None, -3, 3)} | ||
} | ||
|
||
basic_assignment_values = { | ||
'1slice': xr.DataArray(randn((3, ny), frac_nan=0.1), dims=['x', 'y']), | ||
'1slice-1scalar': xr.DataArray(randn(int(ny / 3) + 1, frac_nan=0.1), | ||
dims=['y']), | ||
'2slicess-1scalar': xr.DataArray(randn(int((nx - 6) / 3), frac_nan=0.1), | ||
dims=['x']) | ||
} | ||
|
||
outer_indexes = { | ||
'1d': {'x': randint(0, nx, 400)}, | ||
'2d': {'x': randint(0, nx, 500), 'y': randint(0, ny, 400)}, | ||
'2d-1scalar': {'x': randint(0, nx, 100), 'y': 1, 't': randint(0, nt, 400)} | ||
} | ||
|
||
outer_assignment_values = { | ||
'1d': xr.DataArray(randn((400, ny), frac_nan=0.1), dims=['x', 'y']), | ||
'2d': xr.DataArray(randn((500, 400), frac_nan=0.1), dims=['x', 'y']), | ||
'2d-1scalar': xr.DataArray(randn(100, frac_nan=0.1), dims=['x']) | ||
} | ||
|
||
vectorized_indexes = { | ||
'1-1d': {'x': xr.DataArray(randint(0, nx, 400), dims='a')}, | ||
'2-1d': {'x': xr.DataArray(randint(0, nx, 400), dims='a'), | ||
'y': xr.DataArray(randint(0, ny, 400), dims='a')}, | ||
'3-2d': {'x': xr.DataArray(randint(0, nx, 400).reshape(4, 100), | ||
dims=['a', 'b']), | ||
'y': xr.DataArray(randint(0, ny, 400).reshape(4, 100), | ||
dims=['a', 'b']), | ||
't': xr.DataArray(randint(0, nt, 400).reshape(4, 100), | ||
dims=['a', 'b'])}, | ||
} | ||
|
||
vectorized_assignment_values = { | ||
'1-1d': xr.DataArray(randn((400, 2000)), dims=['a', 'y'], | ||
coords={'a': randn(400)}), | ||
'2-1d': xr.DataArray(randn(400), dims=['a', ], coords={'a': randn(400)}), | ||
'3-2d': xr.DataArray(randn((4, 100)), dims=['a', 'b'], | ||
coords={'a': randn(4), 'b': randn(100)}) | ||
} | ||
|
||
|
||
class Base(object): | ||
def setup(self, key): | ||
self.ds = xr.Dataset( | ||
{'var1': (('x', 'y'), randn((nx, ny), frac_nan=0.1)), | ||
'var2': (('x', 't'), randn((nx, nt))), | ||
'var3': (('t', ), randn(nt))}, | ||
coords={'x': np.arange(nx), | ||
'y': np.linspace(0, 1, ny), | ||
't': pd.date_range('1970-01-01', periods=nt, freq='D'), | ||
'x_coords': ('x', np.linspace(1.1, 2.1, nx))}) | ||
|
||
|
||
class Indexing(Base): | ||
def time_indexing_basic(self, key): | ||
self.ds.isel(**basic_indexes[key]).load() | ||
|
||
time_indexing_basic.param_names = ['key'] | ||
time_indexing_basic.params = [list(basic_indexes.keys())] | ||
|
||
def time_indexing_outer(self, key): | ||
self.ds.isel(**outer_indexes[key]).load() | ||
|
||
time_indexing_outer.param_names = ['key'] | ||
time_indexing_outer.params = [list(outer_indexes.keys())] | ||
|
||
def time_indexing_vectorized(self, key): | ||
self.ds.isel(**vectorized_indexes[key]).load() | ||
|
||
time_indexing_vectorized.param_names = ['key'] | ||
time_indexing_vectorized.params = [list(vectorized_indexes.keys())] | ||
|
||
|
||
class Assignment(Base): | ||
def time_assignment_basic(self, key): | ||
ind = basic_indexes[key] | ||
val = basic_assignment_values[key] | ||
self.ds['var1'][ind.get('x', slice(None)), | ||
ind.get('y', slice(None))] = val | ||
|
||
time_assignment_basic.param_names = ['key'] | ||
time_assignment_basic.params = [list(basic_indexes.keys())] | ||
|
||
def time_assignment_outer(self, key): | ||
ind = outer_indexes[key] | ||
val = outer_assignment_values[key] | ||
self.ds['var1'][ind.get('x', slice(None)), | ||
ind.get('y', slice(None))] = val | ||
|
||
time_assignment_outer.param_names = ['key'] | ||
time_assignment_outer.params = [list(outer_indexes.keys())] | ||
|
||
def time_assignment_vectorized(self, key): | ||
ind = vectorized_indexes[key] | ||
val = vectorized_assignment_values[key] | ||
self.ds['var1'][ind.get('x', slice(None)), | ||
ind.get('y', slice(None))] = val | ||
|
||
time_assignment_vectorized.param_names = ['key'] | ||
time_assignment_vectorized.params = [list(vectorized_indexes.keys())] | ||
|
||
|
||
class IndexingDask(Indexing): | ||
def setup(self, key): | ||
requires_dask() | ||
super(IndexingDask, self).setup(key) | ||
self.ds = self.ds.chunk({'x': 100, 'y': 50, 't': 50}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any problem if
.asv
is added to.gitignore
?A bunch of files in this directory makes my gui-git-client freeze.