Skip to content

Commit

Permalink
Fixed #44, added syntax for selecting blades of a given grade.
Browse files Browse the repository at this point in the history
  • Loading branch information
tBuLi committed May 3, 2024
1 parent 759ed6d commit ddfac6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kingdon/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,15 @@ def __len__(self):

def __iter__(self):
return iter(self.blades)

def grade(self, *grades) -> dict:
"""
Return blades of grade `grades`.
:param grades: tuple or ints, grades to select.
"""
if len(grades) == 1 and isinstance(grades[0], tuple):
grades = grades[0]

return {(blade := self.algebra.bin2canon[k]): self[blade]
for k in self.algebra.indices_for_grades[grades]}
8 changes: 8 additions & 0 deletions tests/test_kingdon.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,11 @@ def test_43():
alg = Algebra(2)
x = alg.vector(name='x')
assert x.inv() == 1 / x

def test_blades_of_grade():
alg = Algebra(4)
for indices in alg.indices_for_grades:
blades_of_grade = alg.blades.grade(*indices)
assert isinstance(blades_of_grade, dict)
assert all(label in alg.canon2bin and blade.grades[0] in indices
for label, blade in blades_of_grade.items())

0 comments on commit ddfac6e

Please sign in to comment.