Skip to content

Conversation

@hzhangxyz
Copy link
Member

No description provided.

@hzhangxyz hzhangxyz requested a review from Copilot July 30, 2025 16:58
Copy link
Contributor

Copilot AI left a 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 permute method 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_after is unclear. Consider renaming to dims or permutation to 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.
Copy link

Copilot AI Jul 30, 2025

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.

Suggested change
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]])

Copilot uses AI. Check for mistakes.
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]),
Copy link

Copilot AI Jul 30, 2025

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.

Copilot uses AI. Check for mistakes.
@hzhangxyz hzhangxyz merged commit 1d4f421 into main Jul 30, 2025
6 checks passed
@hzhangxyz hzhangxyz mentioned this pull request Jul 30, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants