Skip to content

Add a roll function for Dask Arrays#2135

Merged
mrocklin merged 1 commit intodask:masterfrom
jakirkham:add_roll
Mar 29, 2017
Merged

Add a roll function for Dask Arrays#2135
mrocklin merged 1 commit intodask:masterfrom
jakirkham:add_roll

Conversation

@jakirkham
Copy link
Copy Markdown
Member

Fixes #2132

Provides a function that performs the same operation as NumPy's roll except on Dask Arrays. This is done by using a mixture of slicing and concatenating. The effect is a Dask Array that is either raveled, rolled, and reshaped or rolled along specified axes. Added a few tests and added the function to the API doc.

@jakirkham jakirkham mentioned this pull request Mar 29, 2017
@mrocklin
Copy link
Copy Markdown
Member

This looks good to me. cc @shoyer does this allow you to drop logic from xarray?


result = concatenate([result[sl1], result[sl2]], axis=i)

result = result.reshape(array.shape)
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.

Side note: This is only needed for the case where axis is None. It should be a no-op everywhere else. Seems cleaner to not have a branch here. Though I don't know if this gets optimized out by Dask or not in the no-op cases. Just figured I'd mention it.

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.

Dask.array doesn't optimize this out currently. It would be good to add the check either here or in reshape.

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.

Adding the check in reshape seems better IMHO.

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.

PR ( #2137 ) adds this optimization and tests for it as well.

@shoyer
Copy link
Copy Markdown
Member

shoyer commented Mar 29, 2017

Yes, we currently have very similar logic for roll in xarray.

Provides a function that performs the same operation as NumPy's roll
except on Dask Arrays. This is done by using a mixture of slicing and
concatenating. The effect is a Dask Array that is either raveled,
rolled, and reshaped or rolled along specified axes. Added a few tests
and added the function to the API doc.
@mrocklin mrocklin merged commit 95a601a into dask:master Mar 29, 2017
@mrocklin
Copy link
Copy Markdown
Member

Thanks @jakirkham !

@jakirkham jakirkham deleted the add_roll branch March 30, 2017 02:34
@sinhrks sinhrks added this to the 0.14.2 milestone May 11, 2017
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.

4 participants