Skip to content

Conversation

ramonmedel
Copy link
Contributor

@ramonmedel ramonmedel commented Jul 19, 2022

Description

Inverse operations on Tensordicts can return the original data. This is currently not the case for tensordict.permute.

We need to return the original tensordict when calling tensordict.permute(a, b, c) we get an instance of a PermutedTensorDict and if we call again the same method with the same parameters in the resulting PermutedTensorDict

assert tensordict.permute(dims_list, dim).permute(dims_list, dim) is tensordict

Motivation and Context

close #278

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of examples)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 19, 2022
@ramonmedel ramonmedel changed the title moved result to a variable [Issue-278] Return tensordict if permutation results is the same tensordict Jul 19, 2022
@vmoens vmoens changed the title [Issue-278] Return tensordict if permutation results is the same tensordict [Feature] Truly invertible tensordict permutation of dimensions Jul 20, 2022
@vmoens vmoens added the enhancement New feature or request label Jul 20, 2022
Copy link
Collaborator

@vmoens vmoens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use something like the test function i put in the comment instead?
Otherwise it looks great thanks for this!

Copy link
Collaborator

@vmoens vmoens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for contributing!

@vmoens vmoens merged commit a0af473 into pytorch:main Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Make tensordict.permute(2, 1, 0).permute(0, 1, 2) return the original tensordict
3 participants