Repository navigation
Only fuse simple indexing with getarray backends - #1529
Conversation
Certain numpy-array-like-things may not support all of the indexing methods that numpy uses. When fusing getitem/getarray calls together, we shouldn't pass "fancy indexing" requests to these backends. The easiest way to do this is to not propogate fusing of these types back inside calls to `getarray`. This PR includes the following changes: - Don't fuse indexing using lists or arrays inside calls to `getarray`. - Make `from_array` use `getitem` when used with numpy types that return instances of `ndarray` when indexed. This is a small optimization to make use of `np.memmap` and `np.ndarray` still as fast as before.
|
Oop, turns out slicing Depending on backend, |
|
As is, this would be a significant performance regression for xarray. We need a way to be able to call |
|
Would exposing |
|
I think a keyword argument would suffice -- an extensible dispatch system On Wed, Sep 7, 2016 at 5:04 PM, Jim Crist [email protected] wrote:
|
|
Just out of interest, what set of fancy indexing features do you make use of in the case where the backend is numpy array? FWIW I'd be happy to use a keyword argument if that's easier. Maybe "fancy=True" if the intention is to specify whether the backend supports fancy indexing? |
In the simplest case, just pulling out a single value from some axes of an array, e.g., |
|
Zarr supports this, I.e., indexing with slices and/or integers. It doesn't I asked because if dask needs only a limited subset of fancy indexing On Thursday, 8 September 2016, Stephan Hoyer [email protected]
Alistair Miles |
In that case this isn't even a good fix for Zarr. We need to not fuse fancy indexing operations, but integers/slices should still be fused. |
`da.from_array` now takes the keyword `fancy=True` to indicate whether the datastore supports "fancy indexing". The default is True, keeping with current behavior. If `False`, the rewrites will no longer fuse indexing involving fancy indexing inside of calls to `getarray_nofancy`.
|
I added a keyword Example using zarr: import zarr
import dask.array as da
import numpy as np
x = np.random.randint(0, 4, size=(10000, 100))
zx = zarr.array(x)
dzx = da.from_array(zx, chunks=zx.chunks, fancy=False)
dzx[[1, 2]].compute() # This works fine
dzx = da.from_array(zx, chunks=zx.chunks) # don't pass in `Fancy=False`
dzx[[1, 2]].compute() # This errors |
|
Planning to merge later today if no comment. |
| pass in True to have dask.array create one for you. | ||
| fancy : bool, optional | ||
| If ``x`` doesn't support fancy indexing (e.g. indexing with lists or | ||
| arrays) then set to False. Default is True. |
There was a problem hiding this comment.
"Default is True." is inconsistent with the function signature (one reason why you never put default argument values in docstrings)
There was a problem hiding this comment.
def from_array(x, chunks, name=None, lock=False, fancy=True)
The default for fancy is True.
|
I can't say I follow the logic of the fusing operations, but given that this is backwards compatible it seems safe to me. |
Certain numpy-array-like-things may not support all of the indexing methods that numpy uses. When fusing getitem/getarray calls together, we shouldn't pass "fancy indexing" requests to these backends. The easiest way to do this is to not propogate fusing of these types back inside calls to
getarray.This PR includes the following changes:
getarray.from_arrayusegetitemwhen used with numpy types that returninstances of
ndarraywhen indexed. This is a small optimization tomake use of
np.memmapandnp.ndarraystill as fast as before.Fixes #1528.