Skip to content

Array slice array - #2430

Closed
TomAugspurger wants to merge 2 commits into
dask:masterfrom
TomAugspurger:array-slice-array
Closed

TomAugspurger wants to merge 2 commits into
dask:masterfrom
TomAugspurger:array-slice-array

Conversation

@TomAugspurger

Copy link
Copy Markdown
Member

Closes #2412

Thanks for the help on this @mrocklin. I hope things look reasonable.

Slicing
=======

Dask array supports most of the NumPy slicing syntax. In particular it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread dask/array/core.py Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep this case within the general elemwise function or is there a clean way to move this logic elsewhere?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The special-casing does feel out of place here. Perhaps I can move it to broadcast_shapes. Let me see.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@TomAugspurger TomAugspurger Jun 7, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. Sorry for impeding progress on this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the feedback. I think (hope!) that the latest version is a big improvement.

Comment thread dask/array/core.py Outdated

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think I'll move most of my changes to slice_with_dask_array into _elemwise_array_mask.

Comment thread dask/array/core.py Outdated
if k[0] == y.name: # may have to reduce the dimensionality here
dsk[k[:ndim + 1]] = v
else:
dsk[k] = v

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@TomAugspurger
TomAugspurger force-pushed the array-slice-array branch 2 times, most recently from 401aba7 to 348fce3 Compare June 15, 2017 14:20
This is currently limited to slicing with *only* a boolean mask, which means
only along axis 0. That actually covers my immediate need.
@TomAugspurger

Copy link
Copy Markdown
Member Author

Superseded by #2658 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants