summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--polymatrix/polymatrix/init.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/polymatrix/polymatrix/init.py b/polymatrix/polymatrix/init.py
index f9a3de1..a2d28f2 100644
--- a/polymatrix/polymatrix/init.py
+++ b/polymatrix/polymatrix/init.py
@@ -20,14 +20,15 @@ def init_poly_matrix(
):
# This is here because the old code in expression.mixins usually gives raw dictionaries
if not isinstance(data, PolyMatrixDict):
- data = PolyMatrixDict({
- MatrixIndex(*entry): PolyDict({
- MonomialIndex(VariableIndex(*v) for v in monomial): coeff
- })
- for entry, poly in data.items()
- for monomial, coeff in poly.items()
- })
-
+ wrapped = PolyMatrixDict.empty()
+ for entry, poly in data.items():
+ p = PolyDict.empty()
+ for monomial, coeff in poly.items():
+ idx = MonomialIndex(VariableIndex(*v) for v in monomial)
+ p[idx] = coeff
+ wrapped[*entry] = p
+ data = wrapped
+
return PolyMatrixImpl(
data=data,
shape=shape,
@@ -40,10 +41,11 @@ def init_broadcast_poly_matrix(
) -> BroadcastPolyMatrixMixin:
# This is here because the old code in expression.mixins usually gives raw dictionaries
if not isinstance(data, PolyDict):
- data = PolyDict({
- MonomialIndex(VariableIndex(*v) for v in monomial): coeff
- for monomial, coeff in data.items()
- })
+ p = PolyDict.empty()
+ for monomial, coeff in data.items():
+ idx = MonomialIndex(VariableIndex(*v) for v in monomial)
+ p[idx] = coeff
+ data = p
return BroadcastPolyMatrixImpl(
data=data,