-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Vectorized lazy indexing #1899
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
Vectorized lazy indexing #1899
Changes from 1 commit
dceb298
c1b4b60
d989a15
218763c
541fca3
3e05a16
030a2c4
b9f97b4
850f29c
943ec78
91aae64
991c1da
936954a
9144965
d1cb976
95e1f1c
180c4f5
dbbe531
c2e61ad
b545c3e
872de73
bb5d1f6
cfe29bb
17a7dac
2dff278
ead6327
a90ac05
73f4958
fd04966
b3c3d80
259f36c
0e7eb2e
0c2e31b
d8421a5
7e0959c
4fccdee
8e96710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…e in zarr.py
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,7 +440,7 @@ def __getitem__(self, key): | |
return self.array[self.indexer_cls(key)] | ||
|
||
|
||
class LazilyIndexedArray(ExplicitlyIndexedNDArrayMixin): | ||
class LazilyOuterIndexedArray(ExplicitlyIndexedNDArrayMixin): | ||
"""Wrap an array to make basic and orthogonal indexing lazy. | ||
""" | ||
|
||
|
@@ -541,10 +541,10 @@ def _updated_key(self, new_key): | |
return _combine_indexers(self.key, self.shape, new_key) | ||
|
||
def __getitem__(self, indexer): | ||
# If the indexed array becomes a scalar, return LazilyIndexedArray. | ||
# If the indexed array becomes a scalar, return LazilyOuterIndexedArray. | ||
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. E501 line too long (80 > 79 characters) |
||
if all(isinstance(ind, integer_types) for ind in indexer.tuple): | ||
key = BasicIndexer(tuple(k[indexer.tuple] for k in self.key.tuple)) | ||
return LazilyIndexedArray(self.array, key) | ||
return LazilyOuterIndexedArray(self.array, key) | ||
return type(self)(self.array, self._updated_key(indexer)) | ||
|
||
def transpose(self, order): | ||
|
@@ -645,7 +645,7 @@ def _outer_to_vectorized_indexer(key, shape): | |
|
||
Returns | ||
------- | ||
VectorizedInexer | ||
VectorizedIndexer | ||
Tuple suitable for use to index a NumPy array with vectorized indexing. | ||
Each element is an array: broadcasting them together gives the shape | ||
of the result. | ||
|
@@ -923,7 +923,9 @@ def _decompose_outer_indexer(indexer, shape, indexing_support): | |
return (OuterIndexer(tuple(backend_indexer)), | ||
OuterIndexer(tuple(np_indexer))) | ||
|
||
# basic | ||
# basic indexer | ||
assert indexing_support == IndexingSupport.BASIC | ||
|
||
for k, s in zip(indexer, shape): | ||
if isinstance(k, np.ndarray): | ||
# np.ndarray key is converted to slice that covers the entire | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ def get_variables(self): | |
def lazy_inaccessible(k, v): | ||
if k in self._indexvars: | ||
return v | ||
data = indexing.LazilyIndexedArray(InaccessibleArray(v.values)) | ||
data = indexing.LazilyOuterIndexedArray(InaccessibleArray(v.values)) | ||
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. E501 line too long (80 > 79 characters) |
||
return Variable(v.dims, data, v.attrs) | ||
return dict((k, lazy_inaccessible(k, v)) for | ||
k, v in iteritems(self._variables)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
from xarray.core import indexing | ||
from xarray.core.common import full_like, ones_like, zeros_like | ||
from xarray.core.indexing import ( | ||
BasicIndexer, CopyOnWriteArray, DaskIndexingAdapter, LazilyIndexedArray, | ||
BasicIndexer, CopyOnWriteArray, DaskIndexingAdapter, LazilyOuterIndexedArray, | ||
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. E501 line too long (81 > 79 characters) |
||
MemoryCachedArray, NumpyIndexingAdapter, OuterIndexer, PandasIndexAdapter, | ||
VectorizedIndexer) | ||
from xarray.core.pycompat import PY3, OrderedDict | ||
|
@@ -988,9 +988,9 @@ def test_repr(self): | |
assert expected == repr(v) | ||
|
||
def test_repr_lazy_data(self): | ||
v = Variable('x', LazilyIndexedArray(np.arange(2e5))) | ||
v = Variable('x', LazilyOuterIndexedArray(np.arange(2e5))) | ||
assert '200000 values with dtype' in repr(v) | ||
assert isinstance(v._data, LazilyIndexedArray) | ||
assert isinstance(v._data, LazilyOuterIndexedArray) | ||
|
||
def test_detect_indexer_type(self): | ||
""" Tests indexer type was correctly detected. """ | ||
|
@@ -1798,7 +1798,7 @@ def test_rolling_window(self): | |
|
||
class TestAsCompatibleData(TestCase): | ||
def test_unchanged_types(self): | ||
types = (np.asarray, PandasIndexAdapter, indexing.LazilyIndexedArray) | ||
types = (np.asarray, PandasIndexAdapter, indexing.LazilyOuterIndexedArray) | ||
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. E501 line too long (82 > 79 characters) |
||
for t in types: | ||
for data in [np.arange(3), | ||
pd.date_range('2000-01-01', periods=3), | ||
|
@@ -1961,17 +1961,17 @@ def test_NumpyIndexingAdapter(self): | |
v = Variable(dims=('x', 'y'), data=NumpyIndexingAdapter( | ||
NumpyIndexingAdapter(self.d))) | ||
|
||
def test_LazilyIndexedArray(self): | ||
v = Variable(dims=('x', 'y'), data=LazilyIndexedArray(self.d)) | ||
def test_LazilyOuterIndexedArray(self): | ||
v = Variable(dims=('x', 'y'), data=LazilyOuterIndexedArray(self.d)) | ||
self.check_orthogonal_indexing(v) | ||
self.check_vectorized_indexing(v) | ||
# doubly wrapping | ||
v = Variable(dims=('x', 'y'), | ||
data=LazilyIndexedArray(LazilyIndexedArray(self.d))) | ||
data=LazilyOuterIndexedArray(LazilyOuterIndexedArray(self.d))) | ||
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. E501 line too long (83 > 79 characters) |
||
self.check_orthogonal_indexing(v) | ||
# hierarchical wrapping | ||
v = Variable(dims=('x', 'y'), | ||
data=LazilyIndexedArray(NumpyIndexingAdapter(self.d))) | ||
data=LazilyOuterIndexedArray(NumpyIndexingAdapter(self.d))) | ||
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. E501 line too long (80 > 79 characters) |
||
self.check_orthogonal_indexing(v) | ||
|
||
def test_CopyOnWriteArray(self): | ||
|
@@ -1980,7 +1980,7 @@ def test_CopyOnWriteArray(self): | |
self.check_vectorized_indexing(v) | ||
# doubly wrapping | ||
v = Variable(dims=('x', 'y'), | ||
data=CopyOnWriteArray(LazilyIndexedArray(self.d))) | ||
data=CopyOnWriteArray(LazilyOuterIndexedArray(self.d))) | ||
self.check_orthogonal_indexing(v) | ||
self.check_vectorized_indexing(v) | ||
|
||
|
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.
E501 line too long (84 > 79 characters)