diff options
author | Nao Pross <np@0hm.ch> | 2024-03-07 22:47:54 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-03-07 22:47:54 +0100 |
commit | 3cbcde9a7f01508f28e1436fa9ab197dd401658d (patch) | |
tree | a6f9fff055927cda52d5fb5ace3d27cc2b6b2371 | |
parent | Delete mdpoly.leaves make Var, Param, Const ABCs (diff) | |
download | mdpoly-3cbcde9a7f01508f28e1436fa9ab197dd401658d.tar.gz mdpoly-3cbcde9a7f01508f28e1436fa9ab197dd401658d.zip |
Finish incomplete implementation of MatVar.to_repr
-rw-r--r-- | mdpoly/algebra.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/mdpoly/algebra.py b/mdpoly/algebra.py index a715b7e..d603eee 100644 --- a/mdpoly/algebra.py +++ b/mdpoly/algebra.py @@ -206,7 +206,7 @@ class PolyVar(Var, PolyRingExpr): def to_repr(self, repr_type: type, state: State) -> tuple[Repr, State]: r = repr_type() - idx = PolyVarIndex.from_var(self, state), + idx = PolyVarIndex.from_var(self, state), # important comma! r.set(MatrixIndex.scalar(), PolyIndex(idx), 1) return r, state @@ -491,20 +491,21 @@ class MatVar(Var, MatrixExpr): shape: Shape algebra: Algebra = Algebra.matrix_ring - def to_scalars(self, scalar_type: Type[T]) -> Iterable[tuple[MatrixIndex, T]]: + def to_scalars(self, scalar_var_type: Type[T]) -> Iterable[tuple[MatrixIndex, T]]: for row in range(self.shape.rows): for col in range(self.shape.cols): - var = scalar_type(name=f"{self.name}_[{row},{col}]") - idx = MatrixIndex(row, col) + var = scalar_var_type(name=f"{self.name}_[{row},{col}]") + entry = MatrixIndex(row, col) - yield idx, var + yield entry, var def to_repr(self, repr_type: type, state: State) -> tuple[Repr, State]: r = repr_type() # FIXME: do not hardcode scalar type - for idx, var in self.to_scalars(Var): - ... + for entry, var in self.to_scalars(PolyVar): + idx = PolyVarIndex.from_var(var, state), # important comma! + r.set(entry, PolyIndex(idx), 1) return r, state |