Skip to content
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

Non-commutative inner product support #437

Merged
merged 3 commits into from
Dec 12, 2024
Merged

Conversation

trundev
Copy link
Contributor

@trundev trundev commented Dec 8, 2024

Add separate MultiVector.__ror__ (based on __or__), to calculate inner product from swapped operands.
The inner product is NOT a commutative operation.\

Fixes #426

Add separate `MultiVector.__ror__` (based on `__or__`), to calculate
inner product from swapped operands. This is NOT commutative operation.
@eric-wieser eric-wieser changed the title Non-commutative inner product support (pygae#426) Non-commutative inner product support Dec 9, 2024
Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me; can you add a test?

Add test to cover swapped operand operations on MultiVector-s.
Esp. the fix for pygae#426.
@trundev
Copy link
Contributor Author

trundev commented Dec 9, 2024

I added a TestBasicAlgebra.test_swapped_operands() (test/test_clifford.py).
It uses the MVArray <op> MultiVector trick to force use of MultiVector.__r<op>__. Covers multiple swapped operand operations, like __radd__, __rsub__, ... __ror__.

Possibly, this is a little bit of overshoot, please comment.

@trundev
Copy link
Contributor Author

trundev commented Dec 11, 2024

Hi @arsenovic,
After the CI is now fixed, this should be easier to merge this - it should pass all the CI pytest-s (if merged to latest master).
Sorry for the inconvenience!

Add "noqa: F811" comment similar to other tests with `rng`.
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Project coverage is 71.13%. Comparing base (1102eba) to head (568087f).
Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
clifford/_multivector.py 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #437      +/-   ##
==========================================
- Coverage   71.35%   71.13%   -0.23%     
==========================================
  Files          73       74       +1     
  Lines        9461     9437      -24     
  Branches     1313     1211     -102     
==========================================
- Hits         6751     6713      -38     
- Misses       2539     2551      +12     
- Partials      171      173       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

operator.or_, # inner product
])
def test_swapped_operands(self, algebra, rng, func): # noqa: F811
layout = algebra
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it's sufficient to just test g3 here, assuming that elements with non-commutative inner products exist there.

Comment on lines +754 to +755
mv = layout.randomMV(rng=rng)
mv2 = layout.randomMV(rng=rng)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I'd be tempted to just pick two elements here on which all the products are non-commutative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that ok: trundev@b2418f0

I did not push this in fix-pygae-426 branch to avoid history pollution (if something is not ok, it can be simply amended).

BTW, there is still no test coverage for the second return inside __ror__ (similar in __or__): https://github.com/trundev/clifford/blob/dcaa727/clifford/_multivector.py#L233
I'm not sure what cases it is intended to handle. Scalar multiplication is handled as if it is a multi-vector (converted by _checkOther).

@arsenovic arsenovic merged commit 57e9e49 into pygae:master Dec 12, 2024
11 of 13 checks passed
@trundev
Copy link
Contributor Author

trundev commented Dec 12, 2024

@eric-wieser, please note that the "Simplify swapped operand operations pytest" commit was NOT included here.
I can create another PR, if something like it is preferred.

@trundev trundev deleted the fix-pygae-426 branch December 12, 2024 14:21
@eric-wieser
Copy link
Member

If you've already written the code, please do!

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.

Deviation between MultiVector and MVArray calculation
3 participants