Add support for reverse. - #29
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #29 +/- ##
==========================================
- Coverage 38.57% 37.56% -1.02%
==========================================
Files 3 3
Lines 197 205 +8
Branches 26 26
==========================================
+ Hits 76 77 +1
- Misses 121 128 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
94bf028 to
aa0f211
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new reverse method to the GrassmannTensor class that allows reversing specified indices while maintaining proper Grassmann algebra sign conventions.
- Implements tensor index reversal with automatic sign handling for Grassmann tensors
- Validates input indices for uniqueness and bounds checking
- Calculates and applies parity-based sign corrections according to Grassmann algebra rules
| assert len(set(indices)) == len(indices), f"Indices must be unique. Got {indices}." | ||
| assert all(0 <= i < self.tensor.dim() for i in indices), f"Indices must be within tensor dimensions. Got {indices}." | ||
|
|
||
| arrow = tuple(self.arrow[i] ^ i in indices for i in range(self.tensor.dim())) |
There was a problem hiding this comment.
[nitpick] The expression i in indices should be parenthesized for clarity. The current precedence could be confusing. Consider: arrow = tuple(self.arrow[i] ^ (i in indices) for i in range(self.tensor.dim()))
| arrow = tuple(self.arrow[i] ^ i in indices for i in range(self.tensor.dim())) | |
| arrow = tuple(self.arrow[i] ^ (i in indices) for i in range(self.tensor.dim())) |
|
|
||
| total_parity = functools.reduce( | ||
| torch.logical_xor, | ||
| (self._unsqueeze(parity, index, self.tensor.dim()) for index, parity in enumerate(self.parity) if index in indices and self.arrow[index]), |
There was a problem hiding this comment.
[nitpick] The condition index in indices and self.arrow[index] should be parenthesized for clarity: (index in indices) and self.arrow[index]
| (self._unsqueeze(parity, index, self.tensor.dim()) for index, parity in enumerate(self.parity) if index in indices and self.arrow[index]), | |
| (self._unsqueeze(parity, index, self.tensor.dim()) for index, parity in enumerate(self.parity) if (index in indices and self.arrow[index])), |
No description provided.