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

PyTorch's flip returns a new tensor, but NumPy's flip returns a view #38271

Open
mruberry opened this issue May 11, 2020 · 3 comments
Open

PyTorch's flip returns a new tensor, but NumPy's flip returns a view #38271

mruberry opened this issue May 11, 2020 · 3 comments
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@mruberry
Copy link
Collaborator

mruberry commented May 11, 2020

PyTorch's flip returns a new tensor, which is inconsistent with NumPy's behavior of flip returning a view and PyTorch's own transpose behavior.

cc @mruberry

@mruberry mruberry added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: numpy Related to numpy support, and also numpy compatibility of our operators labels May 11, 2020
@vadimkantorov
Copy link
Contributor

vadimkantorov commented May 12, 2020

I think this is another instance of "PyTorch should support negative strides": #16424 #16424 (comment)

@kshitij12345
Copy link
Collaborator

This should be documented. Also it should mention that unlike NumPy, torch.flip is not constant time Operator but O(N).

facebook-github-bot pushed a commit that referenced this issue Jan 13, 2021
…50041)

Summary:
Reference: #38271

Pull Request resolved: #50041

Reviewed By: izdeby

Differential Revision: D25883870

Pulled By: mruberry

fbshipit-source-id: 33cc28a2176e98f2f29077958782291609c7999b
@vadimkantorov
Copy link
Contributor

vadimkantorov commented May 20, 2023

It would also be great to have an inplace torch.flip_ (and even more general inplace byte swaps/shuffles): discussed here: #101925 (comment)

For small inner dims (2,3,4,5,6,7,8) - it's useful for little-big endian byte swaps and for BGR<>RGB inplace image conversion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants