Add the basic parity tensor class and its arithmetic operators. - #2
Conversation
db6994f to
17a277e
Compare
17a277e to
6bf1100
Compare
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>
There was a problem hiding this comment.
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
ParityTensorwith 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__.pymodule
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) |
There was a problem hiding this comment.
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.
| self._validate_edge_compatibility(other) | |
| self._validate_edge_compatibility(other) | |
| self._validate_parity_structure(other) |
| return ParityTensor( | ||
| edges=self.edges, | ||
| tensor=self.tensor / other.tensor, | ||
| ) |
There was a problem hiding this comment.
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.
| 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 |
| return ParityTensor( | ||
| edges=self.edges, | ||
| tensor=self.tensor + other.tensor, | ||
| ) |
There was a problem hiding this comment.
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.
| ) | |
| ) | |
| if not isinstance(other, (int, float, torch.Tensor)): | |
| raise TypeError(f"Unsupported operand type(s) for +: 'ParityTensor' and '{type(other).__name__}'") |
# This is the 1st commit message: dev(identity): add support for identity - Add support for identity - Add self multiplication verification for `identity` - Add taylor expansion verification for `exponentiation` - Add assertation test for `exponentiation` and `identity` - Modify the arrow processing logic for `expoenntiation` - Fix an issue where the arrow was incorrect when reshaping to one dimension or all one dimensions # This is the commit message #2: fix(svd): Fix code coverage fix(contract): fix code coverage fix(contract): fix contract code coverage
No description provided.