summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-06-02 15:39:32 +0200
committerNao Pross <np@0hm.ch>2024-06-02 15:39:32 +0200
commit408be59cafdad8d5058dd4d055746267de6ac4dc (patch)
tree2b0d4f155a500b6bee992d02234a5b0af694ec55
parentGive better name to member of BroadcastPolyMatrix (diff)
downloadpolymatrix-408be59cafdad8d5058dd4d055746267de6ac4dc.tar.gz
polymatrix-408be59cafdad8d5058dd4d055746267de6ac4dc.zip
Create helper PolyDict.terms_of_degree(d)
Diffstat (limited to '')
-rw-r--r--polymatrix/polymatrix/index.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/polymatrix/polymatrix/index.py b/polymatrix/polymatrix/index.py
index ba9d508..bab991f 100644
--- a/polymatrix/polymatrix/index.py
+++ b/polymatrix/polymatrix/index.py
@@ -201,6 +201,12 @@ class PolyDict(UserDict[MonomialIndex, int | float]):
# This is an alias for readability
yield from self.items()
+ def terms_of_degree(self, d: int) -> Iterable[tuple[MonomialIndex, int | float]]:
+ """ Iterate over terms of degree `d` with a non-zero coefficient. """
+ yield from ((m, coeff)
+ for m, coeff in self.terms()
+ if m.degree == d)
+
def monomials(self) -> Iterable[MonomialIndex]:
""" Get monomials that compose the polynomial. """
# This is an alias for readability