Skip to content

Commit

Permalink
Merge pull request #47 from tBuLi/fix_44
Browse files Browse the repository at this point in the history
Fix 44
  • Loading branch information
tBuLi committed May 14, 2024
2 parents cfada70 + ddfac6e commit 34da9c2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kingdon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Martin Roelfs"""
__email__ = 'martinroelfs@yahoo.com'
__version__ = '1.0.3'
__version__ = '1.0.4'

from sympy import symbols

Expand Down
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]}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.3
current_version = 1.0.4
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/tbuli/kingdon',
version='1.0.3',
version='1.0.4',
zip_safe=False,
)
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 34da9c2

Please sign in to comment.