-
Notifications
You must be signed in to change notification settings - Fork 0
Add field parity, and copy parity and mask in arithmetic operators. #11
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
91b028a to
ae77625
Compare
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 refactors the ParityTensor class to add a new parity field and improve encapsulation by making fields private with public property accessors. The changes enable lazy computation of parity and mask values while preserving them during arithmetic operations for better performance.
Key changes:
- Made all fields private (
_edges,_tensor,_parity,_mask) with public property accessors - Added lazy computation for
parityandmaskproperties with caching - Updated all arithmetic operators to preserve
_parityand_maskreferences from the left operand
| return ParityTensor( | ||
| edges=self.edges, | ||
| tensor=self.tensor + other.tensor, | ||
| _edges=self._edges, | ||
| _tensor=self._tensor + other._tensor, | ||
| _parity=self._parity, | ||
| _mask=self._mask, |
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 mask from self is being copied to the result of addition with another ParityTensor, but the result tensor may have different values that could invalidate this mask. The mask should be recomputed or set to None to ensure correctness.
| _edges=self._edges, | ||
| _tensor=self._tensor - other._tensor, | ||
| _parity=self._parity, | ||
| _mask=self._mask, |
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 mask from self is being copied to the result of subtraction with another ParityTensor, but the result tensor may have different values that could invalidate this mask. The mask should be recomputed or set to None to ensure correctness.
| _mask=self._mask, | |
| _mask=None, |
| _edges=self._edges, | ||
| _tensor=self._tensor * other._tensor, | ||
| _parity=self._parity, | ||
| _mask=self._mask, |
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 mask from self is being copied to the result of multiplication with another ParityTensor, but element-wise multiplication can change which elements should be zero according to the parity rules. The mask should be recomputed or set to None to ensure correctness.
| _mask=self._mask, | |
| _mask=None, |
| _edges=self._edges, | ||
| _tensor=self._tensor / other._tensor, | ||
| _parity=self._parity, | ||
| _mask=self._mask, |
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 mask from self is being copied to the result of division with another ParityTensor, but division can change which elements should be zero according to the parity rules. The mask should be recomputed or set to None to ensure correctness.
| _mask=self._mask, | |
| _mask=None, |
No description provided.