From 3cbcde9a7f01508f28e1436fa9ab197dd401658d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 7 Mar 2024 22:47:54 +0100 Subject: Finish incomplete implementation of MatVar.to_repr --- mdpoly/algebra.py | 15 ++++++++------- 1 file 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 -- cgit v1.2.1