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

Change isBlade to work on degenerate metrics #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Oct 22, 2019

>>> import clifford
>>> layout, _ = clifford.Cl(3, 0, 1, firstIdx=0)
>>> locals().update(layout.blades)
>>> e0.isBlade()
True
>>> e0.isBlade(invertible=True)
False

Fixes #145.


This exposes that .factorise() and .basis() both fail on non-invertible blades. I'm not sure exactly how to fix that, other than being sure I don't want to do it in this PR.

Comment on lines 690 to 689
# applying a versor (and hence an invertible blade) to a vector should
# not change the grade
if not all(
grades_present(Vhat*e*Vrev, 0.000001) == {1}
grade_cmp(grades_present(Vhat*e*Vrev, 0.000001), {1})
for e in cf.basis_vectors(self.layout).values()
):
Copy link
Member Author

@eric-wieser eric-wieser Oct 22, 2019

Choose a reason for hiding this comment

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

This condition is relaxed when invertible=False to allow only the removal of grades, but not the addition of any new ones

Comment on lines 683 to 680
# Test if the versor inverse (~V)/(V * ~V) is truly the inverse of the
# multivector V
if grades_present(Vhat*Vinv, 0.000001) != {0}:
if not grade_cmp(grades_present(Vhat*Vinv, 0.000001), {0}):
return False
Copy link
Member Author

Choose a reason for hiding this comment

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

This condition is relaxed to allow Vhat*Vinv == 0 to be considered

Comment on lines +674 to +675
mag = (self*Vrev)[()]
if mag != 0:
# not strictly necessary, just scales to make eps appropriate below
Vinv = Vrev / mag
elif invertible:
return False
else:
Vinv = Vrev
Copy link
Member Author

Choose a reason for hiding this comment

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

Changes here are to:

  • bail out early without a divide-by-zero if not allowing non-invertible blades
  • avoiding the division if it is zero, since that shouldn't affect the results below significantly
  • Use [()] instead of [0], which is a little more reliable for pulling out the scalar part

@eric-wieser eric-wieser changed the title Change isBlade to work on denegerate metrics Change isBlade to work on degenerate metrics Jun 9, 2020
```python
>>> import clifford
>>> layout, _ = clifford.Cl(3, 0, 1, firstIdx=0)
>>> locals().update(layout.blades)
>>> e0.isBlade()
True
>>> e0.isBlade(invertible=True)
False
```
@eric-wieser eric-wieser marked this pull request as ready for review July 27, 2020 17:31
@codecov
Copy link

codecov bot commented Jul 27, 2020

Codecov Report

Merging #162 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #162      +/-   ##
==========================================
+ Coverage   70.37%   70.43%   +0.05%     
==========================================
  Files          69       69              
  Lines        9025     9050      +25     
  Branches     1177     1182       +5     
==========================================
+ Hits         6351     6374      +23     
- Misses       2507     2508       +1     
- Partials      167      168       +1     
Impacted Files Coverage Δ
clifford/_multivector.py 80.86% <100.00%> (+0.37%) ⬆️
clifford/test/test_clifford.py 99.06% <100.00%> (+0.01%) ⬆️
clifford/test/test_degenerate.py 100.00% <100.00%> (ø)
clifford/tools/g3c/model_matching.py 41.56% <0.00%> (-1.21%) ⬇️
clifford/test/test_g3c_tools.py 82.47% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a37bb85...bd449ba. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isBlade fails on degenerate metrics
1 participant