summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--polymatrix/polymatrix/mixins.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/polymatrix/polymatrix/mixins.py b/polymatrix/polymatrix/mixins.py
index 44f1e07..bb971b9 100644
--- a/polymatrix/polymatrix/mixins.py
+++ b/polymatrix/polymatrix/mixins.py
@@ -6,6 +6,7 @@ import math
import numpy as np
from abc import ABC, abstractmethod
+from collections import Counter
from numpy.typing import NDArray
from typing import Iterable, Sequence, Callable, cast, TYPE_CHECKING
from typing_extensions import override
@@ -445,15 +446,8 @@ class PolyMatrixAsAffineExpressionMixin(PolyMatrixMixin, ABC):
for key, val in compute_with_triangles(self.degree, x).items():
# See comment above for structure of key
# Count occurrences to convert to MonomialIndex
- new_key: dict[int, int] = {}
- for e in key:
- if e in new_key:
- new_key[e] += 1
- else:
- new_key[e] = 1
-
- index = MonomialIndex(VariableIndex(self.variable_indices[k], v)
- for k, v in new_key.items())
+ index = MonomialIndex(sorted(VariableIndex(self.variable_indices[k], v)
+ for k, v in Counter(key).items()))
monomial_values[index] = val
# Sort the values by monomial index, which have a total order
@@ -530,7 +524,7 @@ class PolyMatrixAsAffineExpressionMixin(PolyMatrixMixin, ABC):
# efficiency gain is useless if most of the computed terms are not
# used.
# TODO: tune heuristic
- if len(self.slices) > n:
+ if len(self.slices) > 0:
# Compute all powers of x up to degree d
all_monomials = self.monomials_eval_all(x)
monomials = {