Skip to content

Conversation

@hzhangxyz
Copy link
Member

No description provided.

@hzhangxyz hzhangxyz requested a review from Copilot July 30, 2025 14:34

This comment was marked as outdated.

@hzhangxyz hzhangxyz force-pushed the dev/add-simple-arithmetic-operators branch 2 times, most recently from db6994f to 17a277e Compare July 30, 2025 14:39
@hzhangxyz hzhangxyz requested a review from Copilot July 30, 2025 14:40

This comment was marked as outdated.

@hzhangxyz hzhangxyz force-pushed the dev/add-simple-arithmetic-operators branch from 17a277e to 6bf1100 Compare July 30, 2025 14:44
@hzhangxyz hzhangxyz requested a review from Copilot July 30, 2025 14:48

This comment was marked as outdated.

hzhangxyz and others added 4 commits July 30, 2025 23:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@hzhangxyz hzhangxyz requested a review from Copilot July 30, 2025 15:04

This comment was marked as outdated.

@hzhangxyz hzhangxyz requested a review from Copilot July 30, 2025 15:28
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 introduces a basic ParityTensor class that wraps PyTorch tensors with additional edge information representing even/odd parts for each dimension, along with comprehensive arithmetic operator support.

  • Implements a dataclass-based ParityTensor with validation for edge-tensor dimension compatibility
  • Adds full arithmetic operator support (addition, subtraction, multiplication, division) with both ParityTensor and scalar operands
  • Exports the new class through the package's __init__.py module

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
parity_tensor/parity_tensor.py Implements the core ParityTensor class with edge validation and arithmetic operators
parity_tensor/init.py Exports the new ParityTensor class in the package's public API


def __mul__(self, other: typing.Any) -> ParityTensor:
if isinstance(other, ParityTensor):
self._validate_edge_compatibility(other)
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.

Element-wise multiplication between ParityTensors with the same edges may not preserve the parity structure. Consider whether multiplication should validate edge compatibility or if it should have different behavior than addition/subtraction.

Suggested change
self._validate_edge_compatibility(other)
self._validate_edge_compatibility(other)
self._validate_parity_structure(other)

Copilot uses AI. Check for mistakes.
Comment on lines +146 to +149
return ParityTensor(
edges=self.edges,
tensor=self.tensor / other.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.

Element-wise division between ParityTensors with the same edges may not preserve the parity structure. Consider whether division should validate edge compatibility or if it should have different behavior than addition/subtraction.

Suggested change
return ParityTensor(
edges=self.edges,
tensor=self.tensor / other.tensor,
)
result = ParityTensor(
edges=self.edges,
tensor=self.tensor / other.tensor,
)
result._validate_parity_preservation()
return result

Copilot uses AI. Check for mistakes.
return ParityTensor(
edges=self.edges,
tensor=self.tensor + other.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.

No input validation is performed on the 'other' parameter before attempting tensor operations. This could lead to unexpected behavior or errors if 'other' is not a valid operand for tensor arithmetic.

Suggested change
)
)
if not isinstance(other, (int, float, torch.Tensor)):
raise TypeError(f"Unsupported operand type(s) for +: 'ParityTensor' and '{type(other).__name__}'")

Copilot uses AI. Check for mistakes.
@hzhangxyz hzhangxyz merged commit ae6aaf9 into main Jul 30, 2025
6 checks passed
@hzhangxyz hzhangxyz mentioned this pull request Jul 31, 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