diff options
author | Nao Pross <np@0hm.ch> | 2024-05-06 17:10:18 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-05-06 17:17:41 +0200 |
commit | 5e0aae41ecbfd149d4f6d250fc52af94ddcfc371 (patch) | |
tree | fc1f868db49d57a14c1d14acbdf48c48cc090b00 | |
parent | Cache degree in PolyMatrixAsAffineExpressionMixin (diff) | |
download | polymatrix-5e0aae41ecbfd149d4f6d250fc52af94ddcfc371.tar.gz polymatrix-5e0aae41ecbfd149d4f6d250fc52af94ddcfc371.zip |
Fix MonomialIndex ordering and MonomialIndex.is_constant
Diffstat (limited to '')
-rw-r--r-- | polymatrix/polymatrix/index.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/polymatrix/polymatrix/index.py b/polymatrix/polymatrix/index.py index 79b8161..384feb8 100644 --- a/polymatrix/polymatrix/index.py +++ b/polymatrix/polymatrix/index.py @@ -1,7 +1,8 @@ from __future__ import annotations + from typing import NamedTuple, Iterable, cast from collections import UserDict -from itertools import filterfalse +from itertools import dropwhile # TODO: remove these types, they are here for backward compatiblity MonomialData = tuple[tuple[int, int], ...] @@ -56,9 +57,11 @@ class MonomialIndex(tuple[VariableIndex]): # they have the same degree the index counts if self.degree == other.degree: # Assumes that monomialindex is sorted! - # FIXME: if the first variable is also the same continue until one + # if the first variable is also the same continue until one # finishes or the values differ. - return self[0] < other[0] + # FIXME: check that return value is not none + s, o = next(dropwhile(lambda t: t[0] == t[1], zip(self, other))) + return s < o return self.degree < other.degree @@ -75,7 +78,7 @@ class MonomialIndex(tuple[VariableIndex]): @staticmethod def is_constant(index: MonomialIndex) -> bool: """ Returns true if it is indexing a constant monomial. """ - return len(index) > 1 + return len(index) == 0 @staticmethod def sort(index: MonomialIndex) -> MonomialIndex: |