-
Notifications
You must be signed in to change notification settings - Fork 0
Add support to permute a tensor. #12
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
Conversation
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.
Pull Request Overview
This PR adds support for permuting tensor dimensions in the ParityTensor class. The implementation handles the complex parity calculations required when indices are reordered, ensuring that the mathematical properties of the parity tensor are preserved.
- Adds a
permutemethod that reorders tensor dimensions according to a given permutation - Implements parity sign correction logic to handle index swaps
- Preserves all tensor properties (edges, parity, mask) through the permutation
Comments suppressed due to low confidence (1)
parity_tensor/parity_tensor.py:66
- The parameter name
before_by_afteris unclear. Consider renaming todimsorpermutationto match PyTorch's convention and make the purpose more obvious.
def permute(self, before_by_after: tuple[int, ...]) -> ParityTensor:
|
|
||
| def permute(self, before_by_after: tuple[int, ...]) -> ParityTensor: | ||
| """ | ||
| Permute the indices of the parity tensor. |
Copilot
AI
Jul 30, 2025
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.
The docstring is incomplete. It should include parameter descriptions, return value description, and example usage for a public API method.
| Permute the indices of the parity tensor. | |
| Permute the indices of the parity tensor. | |
| This method rearranges the dimensions of the tensor and its associated metadata | |
| (edges, parity, and mask) according to the specified permutation. | |
| Parameters: | |
| ---------- | |
| before_by_after : tuple[int, ...] | |
| A tuple specifying the new order of the dimensions. Each element in the tuple | |
| represents the index of the original dimension that should appear in the | |
| corresponding position in the new order. | |
| Returns: | |
| ------- | |
| ParityTensor | |
| A new `ParityTensor` instance with permuted indices, updated edges, parity, | |
| and mask. | |
| Example: | |
| -------- | |
| >>> tensor = torch.tensor([[1, 2], [3, 4]]) | |
| >>> edges = ((0, 1), (1, 0)) | |
| >>> parity_tensor = ParityTensor(_edges=edges, _tensor=tensor) | |
| >>> permuted_tensor = parity_tensor.permute((1, 0)) | |
| >>> print(permuted_tensor.tensor) | |
| tensor([[1, 3], | |
| [2, 4]]) |
| torch.logical_and(parity[i], parity[j]) | ||
| for j in range(self.tensor.dim()) | ||
| for i in range(0, j) # all 0 <= i < j < dim | ||
| if before_by_after[i] > before_by_after[j]), |
Copilot
AI
Jul 30, 2025
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.
The method lacks input validation. It should verify that before_by_after contains valid indices (0 to tensor.dim()-1) and that all indices are unique to prevent runtime errors.
No description provided.