Repository navigation
Closed
Description
Calling dask.array.flatnonzero() on Dask array created from a CuPy one fails due to missing cupy.compress() implementation. Sample and traceback:
import cupy
import dask.array as da
x = cupy.random.random(5000) * cupy.random.randint(-1, 1, 5000)
d = da.from_array(x, chunks=(1000), asarray=False)
da.flatnonzero(d).compute()Traceback (most recent call last):
File "flatnonzero.py", line 8, in <module>
da.flatnonzero(d).compute()
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/base.py", line 156, in compute
(result,) = compute(self, traverse=False, **kwargs)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/base.py", line 398, in compute
results = schedule(dsk, keys, **kwargs)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/threaded.py", line 76, in get
pack_exception=pack_exception, **kwargs)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/local.py", line 460, in get_async
raise_exception(exc, tb)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/compatibility.py", line 112, in reraise
raise exc
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/local.py", line 230, in execute_task
result = _execute_task(task, data)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/core.py", line 118, in _execute_task
args2 = [_execute_task(a, cache) for a in args]
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/core.py", line 118, in <listcomp>
args2 = [_execute_task(a, cache) for a in args]
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/core.py", line 119, in _execute_task
return func(*args2)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/optimization.py", line 942, in __call__
dict(zip(self.inkeys, args)))
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/core.py", line 149, in get
result = _execute_task(task, cache)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/core.py", line 119, in _execute_task
return func(*args2)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/dask/compatibility.py", line 93, in apply
return func(*args, **kwargs)
File "/home/nfs/pentschev/.local/lib/python3.5/site-packages/numpy/core/overrides.py", line 153, in public_api
implementation, public_api, relevant_args, args, kwargs)
File "cupy/core/core.pyx", line 1259, in cupy.core.core.ndarray.__array_function__
AttributeError: module 'cupy' has no attribute 'compress'I suppose the first thing we could is check whether compress() is really necessary for flatnonzero(), calling cupy.nonflatzero() on a CuPy array works, despite the lack of cupy.compress().
Metadata
Metadata
Assignees
Labels
No labels
Activity
jakirkham commentedon Mar 5, 2019
Are you able to do masked selection with CuPy arrays?
mrocklin commentedon Mar 5, 2019
Looks like it
jakirkham commentedon Mar 5, 2019
Thanks @mrocklin. One more question, do 1-D masked selections work on N-D arrays?
If so, I think we can write a helper function that uses mask selection and use it here instead of
np.compress. This would solve this case and a few other cases at the same time.pentschev commentedon Mar 5, 2019
@jakirkham it does work as well.
And thanks for the suggestion, @jakirkham. I will look into details as soon as I get to the issue here, unless you want to give it a try. :)
jakirkham commentedon Mar 5, 2019
Cool. Thanks for checking @pentschev.
Thinking on this again. We may actually want to just consolidate these two branches and perform the selection on the Dask Array directly. Since the
compresscode was written, Dask Arrays started supporting masked selection ( #2658 ). So it may simplify things a bit to just leverage that functionality here.Probably not this week. Maybe next week or the week after though. ;)
pentschev commentedon Mar 5, 2019
Thanks @jakirkham, otherwise I might come back to this one after we handle the
_metaissue.jakirkham commentedon Mar 5, 2019
This wound up being pretty easy. So just added PR ( #4548 ). :)
pentschev commentedon Mar 6, 2019
Thanks for the PR @jakirkham!
jakirkham commentedon Mar 6, 2019
Happy to help. Please let me know how it goes once you have a chance to retest.