Skip to content

Slice array with smaller mask - #2659

Closed
jakirkham wants to merge 2 commits into
dask:masterfrom
jakirkham:slice_array_w_small_mask
Closed

jakirkham wants to merge 2 commits into
dask:masterfrom
jakirkham:slice_array_w_small_mask

Conversation

@jakirkham

Copy link
Copy Markdown
Member

Allows a Dask Array to be sliced with a boolean Dask Array that is smaller than the array it is slicing. This constitutes a very small, but useful step towards resolving issue ( #2651 ).

@jakirkham
jakirkham requested a review from mrocklin September 5, 2017 18:10
@jakirkham
jakirkham force-pushed the slice_array_w_small_mask branch from d047f2b to f574c76 Compare September 5, 2017 18:45
Comment thread dask/array/core.py
chunks = ((np.nan,) * y.npartitions,)
if index.ndim < x.ndim:
x = x.reshape((-1,) + x.shape[index.ndim:])
index = index.flatten()

@jakirkham jakirkham Sep 5, 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.

This won't work if either array has an unknown length. Not sure of a good, simple way to fix this. Maybe it is ok to leave as is (considering this case was completely unsupported before as well).

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.

This is, I think, something that we want to support. the use case that I had in mind personally was for machine learning workloads, where the arrays almost always come from dataframes with unknown row-chunk sizes.

I believe that by default atop will allow nan-chunked arrays to interact with each other assuming that they have equivalent chunk sizes

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 problem is reshaping doesn't seem to be supported on arrays with unknown dimension lengths. Is that something that could be supported? If not, I don't know of a simple fix.

Makes a tweak to the handling of slicing of a Dask Array with a boolean
Dask Array that may be smaller in size. Uses a technique based on the
one used in `compress` to handle the unknown dimension lengths.
Exercises slicing an array with one of lower dimensionality.
@jakirkham
jakirkham force-pushed the slice_array_w_small_mask branch from f574c76 to 6ab6489 Compare September 5, 2017 18:57
@mrocklin

mrocklin commented Sep 5, 2017 via email

Copy link
Copy Markdown
Member

@jakirkham

jakirkham commented Sep 5, 2017 •

Copy link
Copy Markdown
Member Author

However the full fix to that issue is quite a bit of work (as already noted). The last attempt at solving it (before your more recent one) has been untouched for 3 months. This suggests to me that we should break this problem up into smaller more achievable chunks to make it easier for more people to push it forward. Do you agree?

I would think one problem is the one this PR tries to tackle. Namely allowing the mask to be smaller than the array it is applied to. There may be other ways to tackle it that are worth considering. Though I think solving a problem of this scope is a good first step.

Once we solve this problem, it should be possible to build off such a solution and consider where that mask is positioned. As a next step, we could consider allowing multiple different masks for some axes of the array being sliced.

It's my opinion that breaking this problem up will allow us to tackle it in a reasonable period of time instead of letting it idle for months. Plus it will be easier for interested contributors to pick up a piece of this work and complete it.

@mrocklin

mrocklin commented Sep 5, 2017

Copy link
Copy Markdown
Member

This suggest to me that we should break this problem up into smaller more achievable chunks to make it easier for more people to push it forward. Do you agree?

In the general principle, yes, but this isn't the way in which I would break it up. Instead I would make a change to top and atop to support literals. I think that this will allow us to resolve this issue (and possibly several more) much more easily.

@mrocklin

Copy link
Copy Markdown
Member

Should this be closed in favor of #2658 ?

@jakirkham

Copy link
Copy Markdown
Member Author

Thanks for working on PR ( #2658 ), @mrocklin. That will be very useful.

In that PR bool arrays that are 1-D or the same dimensionality as the data were ok, but I don't think it was permissible to have a single bool array inbetween those two ranks (unless I'm missing something). The objective of this PR was to handle this inbetween case. That said, most of the cases I would want to handle are already well addressed by your PR.

Though if solving this case is useful to others, I could rework it in the context of your PR pretty easily as you have already done the hard work. Just thinking about this briefly would do a reshape of the data and mask to get the mask to actually be 1-D before applying it. That said, this is easy for anyone to do themselves too. So would be happy either reworking this or closing it. Please let me know your thoughts.

@jakirkham

Copy link
Copy Markdown
Member Author

On second thought, I think this is just better off closed.

@jakirkham jakirkham closed this Sep 14, 2017
@jakirkham
jakirkham deleted the slice_array_w_small_mask branch September 14, 2017 21:39
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