diff options
author | Nao Pross <np@0hm.ch> | 2024-05-05 17:21:09 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-05-05 17:21:09 +0200 |
commit | 4bb3cb09dd619700390e3e04cd05f1b704652219 (patch) | |
tree | 2f1f24400f7190af6924c1ec16cc91724946c424 | |
parent | Create init function for PolyMatrixAsAffineExpression, fix methods (diff) | |
download | polymatrix-4bb3cb09dd619700390e3e04cd05f1b704652219.tar.gz polymatrix-4bb3cb09dd619700390e3e04cd05f1b704652219.zip |
Fix bug introduced by backwards compatibility code
Bug was introduced by 21e75589a5700bf8215ce87826c4e9daac7c4071
-rw-r--r-- | polymatrix/polymatrix/init.py | 26 |
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, |