-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nd-rolling #4219
nd-rolling #4219
Changes from 17 commits
1dd6b35
6285476
dc113dc
9a45fc7
f74b2e8
d4990d7
531b0ec
b6cf250
425ed45
54d84e5
f7c4911
2d82e68
2e8a76f
31243b1
22ba8b9
620aca3
7404266
4b4e64a
43acf73
398638c
c4fd353
28816f6
404e78f
4cac857
4bb7804
9703e11
f44dd5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,14 @@ def rolling_window(a, axis, window, center, fill_value): | |
""" | ||
import dask.array as da | ||
|
||
# for nd-rolling. | ||
# TODO It can be more efficient. Currently, the chunks at the boundaries | ||
# will be copied, but it might be OK for many-chunked-arrays. | ||
if hasattr(axis, "__len__"): | ||
for ax, win, cen in zip(axis, window, center): | ||
a = rolling_window(a, ax, win, cen, fill_value) | ||
return a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope it is true, though I didn't check it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that ghosting breaks my expectation. I need to update the algo here. |
||
|
||
orig_shape = a.shape | ||
if axis < 0: | ||
axis = a.ndim + axis | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,14 +135,22 @@ def __setitem__(self, key, value): | |
def rolling_window(a, axis, window, center, fill_value): | ||
""" rolling window with padding. """ | ||
pads = [(0, 0) for s in a.shape] | ||
if center: | ||
start = int(window / 2) # 10 -> 5, 9 -> 4 | ||
end = window - 1 - start | ||
pads[axis] = (start, end) | ||
else: | ||
pads[axis] = (window - 1, 0) | ||
if not hasattr(axis, "__len__"): | ||
axis = [axis] | ||
window = [window] | ||
center = [center] | ||
|
||
for ax, win, cent in zip(axis, window, center): | ||
if cent: | ||
start = int(win / 2) # 10 -> 5, 9 -> 4 | ||
end = win - 1 - start | ||
pads[ax] = (start, end) | ||
else: | ||
pads[ax] = (win - 1, 0) | ||
a = np.pad(a, pads, mode="constant", constant_values=fill_value) | ||
return _rolling_window(a, window, axis) | ||
for ax, win in zip(axis, window): | ||
a = _rolling_window(a, win, ax) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very clever! I spent a while trying to figure out how it works... |
||
return a | ||
|
||
|
||
def _rolling_window(a, window, axis=-1): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types on the signature should change too (indeed, I'm surprised mypy doesn't fail)