Skip to content
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

Add support for repeat #169

Closed
davidmascharka opened this issue Dec 12, 2019 · 2 comments · Fixed by #171
Closed

Add support for repeat #169

davidmascharka opened this issue Dec 12, 2019 · 2 comments · Fixed by #171

Comments

@davidmascharka
Copy link
Collaborator

Useful for nearest interpolation, for example:

>>> np.arange(4).reshape(2, 2).repeat(2, axis=0).repeat(2, axis=1)
array([[0, 0, 1, 1],
       [0, 0, 1, 1],
       [2, 2, 3, 3],
       [2, 2, 3, 3]])
@rsokl
Copy link
Owner

rsokl commented Dec 12, 2019

This would be great to have. What is super neat is that I think sliding_window_view basically does all of the heavy-lifting here for the backprop logic:

  • repeat-size = window-size + step-size
  • sum over the windows

The fact that axis can only be an int makes it almost too-easy. We could totally have handled tuples of axes too 💪

@rsokl
Copy link
Owner

rsokl commented Dec 12, 2019

Yep! Given

x = np.arange(4).reshape(2, 2).repeat(2, axis=0)

Accumulating the grad in backprop would be:

sliding_window_view(grad, window_shape=(2, 1), step=(2, 1)).sum(axis=(-2, -1))

😎

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

Successfully merging a pull request may close this issue.

2 participants