Repository: tBuLi/kingdon (language: python)

Issue:
make algebra.blades_of_grade(n)
 `blades_of_grade = lambda self,n: [k for k in self.blades.values() if k.grades==(n,)]`


Discussion / hints:

Fix patch:
diff --git a/kingdon/__init__.py b/kingdon/__init__.py
index d424f36..22d9b20 100644
--- a/kingdon/__init__.py
+++ b/kingdon/__init__.py
@@ -2,7 +2,7 @@
 
 __author__ = """Martin Roelfs"""
 __email__ = 'martinroelfs@yahoo.com'
-__version__ = '1.0.3'
+__version__ = '1.0.4'
 
 from sympy import symbols
 
diff --git a/kingdon/algebra.py b/kingdon/algebra.py
index 19b198f..8637594 100644
--- a/kingdon/algebra.py
+++ b/kingdon/algebra.py
@@ -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]}
diff --git a/setup.cfg b/setup.cfg
index a7e00db..49ed794 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 1.0.3
+current_version = 1.0.4
 commit = True
 tag = True
 
diff --git a/setup.py b/setup.py
index d03bafb..3165b23 100644
--- a/setup.py
+++ b/setup.py
@@ -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,
 )


Test patch:
diff --git a/tests/test_kingdon.py b/tests/test_kingdon.py
index 0d97461..a8836b6 100644
--- a/tests/test_kingdon.py
+++ b/tests/test_kingdon.py
@@ -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())