aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-03-08 01:54:29 +0100
committerNao Pross <np@0hm.ch>2024-03-08 01:54:29 +0100
commit625ecb0a2b22c8afb52017867bcace3d2ea8bd88 (patch)
treeed529e8d7188815ece0dd7f01885b7c059bfbec0
parentMake Expr a Merkle binary tree to allow subtree comparison (diff)
downloadmdpoly-625ecb0a2b22c8afb52017867bcace3d2ea8bd88.tar.gz
mdpoly-625ecb0a2b22c8afb52017867bcace3d2ea8bd88.zip
Fix bug that breaks PolyRingExpr.shape & cleanup
Leaf classes need to overwrite the shape abstractmethod with property but not algebra
-rw-r--r--mdpoly/algebra.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/mdpoly/algebra.py b/mdpoly/algebra.py
index d603eee..d087785 100644
--- a/mdpoly/algebra.py
+++ b/mdpoly/algebra.py
@@ -202,7 +202,8 @@ class PolyRingExpr(Expr):
@dataclassabc(frozen=True, repr=False)
class PolyVar(Var, PolyRingExpr):
""" Variable TODO: desc """
- name: str
+ name: str # overloads Leaf.name
+ shape: Shape = Shape.scalar() # ovearloads PolyRingExpr.shape
def to_repr(self, repr_type: type, state: State) -> tuple[Repr, State]:
r = repr_type()
@@ -214,8 +215,9 @@ class PolyVar(Var, PolyRingExpr):
@dataclassabc(frozen=True, repr=False)
class PolyConst(Const, PolyRingExpr):
""" Constant TODO: desc """
- value: Number
- name: str = ""
+ value: Number # overloads Const.value
+ name: str = "" # overloads Leaf.name
+ shape: Shape = Shape.scalar() # ovearloads PolyRingExpr.shape
def to_repr(self, repr_type: type, state: State) -> tuple[Repr, State]:
r = repr_type()
@@ -226,7 +228,8 @@ class PolyConst(Const, PolyRingExpr):
@dataclassabc(frozen=True, repr=False)
class PolyParam(Param, PolyRingExpr):
""" Polynomial parameter TODO: desc """
- name: str
+ name: str # overloads Leaf.name
+ shape: Shape = Shape.scalar() # overloads PolyRingExpr.shape
def to_repr(self, repr_type: type, state: State) -> tuple[Repr, State]:
if self not in state.parameters:
@@ -457,10 +460,9 @@ class MatConst(Const, MatrixExpr):
"""
A matrix constant
"""
- value: Sequence[Sequence[Number]] # Row major
- shape: Shape
- name: str = ""
- algebra: Algebra = Algebra.matrix_ring
+ value: Sequence[Sequence[Number]] # Row major, overloads Const.value
+ shape: Shape # overloads Expr.shape
+ name: str = "" # overloads Leaf.name
def to_repr(self, repr_type: type, state: State) -> tuple[Repr, State]:
r = repr_type()
@@ -487,9 +489,8 @@ class MatVar(Var, MatrixExpr):
"""
Matrix polynomial variable
"""
- name: str
- shape: Shape
- algebra: Algebra = Algebra.matrix_ring
+ name: str # overloads Leaf.name
+ shape: Shape # overloads Expr.shape
def to_scalars(self, scalar_var_type: Type[T]) -> Iterable[tuple[MatrixIndex, T]]:
for row in range(self.shape.rows):
@@ -520,7 +521,6 @@ class MatParam(Param, MatrixExpr):
"""
name: str
shape: Shape
- algebra: Algebra = Algebra.poly_ring
def to_repr(self, repr_type: type, state: State) -> tuple[Repr, State]:
if self not in state.parameters: