Repository navigation
Array slice array - #2430
Array slice array#2430TomAugspurger wants to merge 2 commits into
Conversation
| Slicing | ||
| ======= | ||
|
|
||
| Dask array supports most of the NumPy slicing syntax. In particular it |
There was a problem hiding this comment.
The diff on this section isn't too informative; https://github.com/TomAugspurger/dask/blob/58c247520373a5006cea6cb9075a59b1398bbc26/docs/source/array-slicing.rst has all of the cases previously, with the Slicing one dask.array with another dask array expanded to to (same shape, and boolean mask on first dimension). Actually, I see now that this is out of date, since we can handle the first N axes. I'll update.
| else: | ||
| shapes = [getattr(arg, 'shape', ()) for arg in args] | ||
| shapes = [s if isinstance(s, Iterable) else () for s in shapes] | ||
| out_ndim = len(broadcast_shapes(*shapes)) # Raises ValueError if dimensions mismatch |
There was a problem hiding this comment.
Do we want to keep this case within the general elemwise function or is there a clean way to move this logic elsewhere?
There was a problem hiding this comment.
The special-casing does feel out of place here. Perhaps I can move it to broadcast_shapes. Let me see.
There was a problem hiding this comment.
Functions like elemwise and atop are relied on very heavily by a lot of the module. I'd like to keep these functions as stripped down as possible.
There was a problem hiding this comment.
Just saw your comment, so I'm not sure if 3f50358 addresses your concerns. That simply extracted the same sort of computations into their own functions.
Are you concerned about the special casing directly inside of elemwise because it's less clear, or because of performance? I'm not sure that 3f50358 really helps with either of those...
I'll add unit-tests for those, and docstrings if you think they're OK.
There was a problem hiding this comment.
My concern is that these functions eventually become the dumping grounds for lots of different special situations. Slicing one array with another is something like a 1% case. If we had 100 such modifications to elemwise then I think that elemwise would become difficult to reason about when bugs arise.
I am not concerned about performance, I am concerned about maintenance costs.
There was a problem hiding this comment.
I think then, the best option is to not call elemwise from slice_with_dask_array (at least for boolean masks.)
There will be a small amount of duplication between elemwise and whatever new function I make, but I think it will be worth the clarity.
There was a problem hiding this comment.
Sounds good to me. Sorry for impeding progress on this.
There was a problem hiding this comment.
I appreciate the feedback. I think (hope!) that the latest version is a big improvement.
|
|
||
| name = kwargs.get('name', None) or '%s-%s' % (funcname(op), | ||
| tokenize(op, dt, *args)) | ||
| return atop(op, expr_inds, *atop_args, dtype=dt, name=name) |
There was a problem hiding this comment.
Is this likely to be used for operations other than slice_with_dask_array? If not then perhaps we should combine the two or keep this private? Thoughts?
There was a problem hiding this comment.
I suspect it would probably fail spectacularly if used with anything other than slice_with_dask_arrray. That function is already a bit long, so I'll make it elemwise_array_mask private.
There was a problem hiding this comment.
Actually, I think I'll move most of my changes to slice_with_dask_array into _elemwise_array_mask.
| if k[0] == y.name: # may have to reduce the dimensionality here | ||
| dsk[k[:ndim + 1]] = v | ||
| else: | ||
| dsk[k] = v |
There was a problem hiding this comment.
In general graphs produced by dask.arrays tend to be much larger than those produced by dask.dataframes, so we've started to avoid doing linear-time operations on these graphs. This is what led to the ShareDict data structure.
So iterating over a graph is to be avoided, so too is mutation.
Instead, we might consider making a new dask.array with a new dict that maps each of y._keys().flatten().tolist() to a new name or, if we want to dive into the sharedict data structure, then you might look at y.dask.dicts[y.name]
401aba7 to
348fce3
Compare
This is currently limited to slicing with *only* a boolean mask, which means only along axis 0. That actually covers my immediate need.
348fce3 to
5ab674e
Compare
5ab674e to
a7761b8
Compare
|
Superseded by #2658 (review) |
Closes #2412
Thanks for the help on this @mrocklin. I hope things look reasonable.