aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-03-07 22:47:54 +0100
committerNao Pross <np@0hm.ch>2024-03-07 22:47:54 +0100
commit3cbcde9a7f01508f28e1436fa9ab197dd401658d (patch)
treea6f9fff055927cda52d5fb5ace3d27cc2b6b2371
parentDelete mdpoly.leaves make Var, Param, Const ABCs (diff)
downloadmdpoly-3cbcde9a7f01508f28e1436fa9ab197dd401658d.tar.gz
mdpoly-3cbcde9a7f01508f28e1436fa9ab197dd401658d.zip
Finish incomplete implementation of MatVar.to_repr
-rw-r--r--mdpoly/algebra.py15
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