From 76b012a7c615da5678bf7e8373bf39010c8bb0b4 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 2 Mar 2024 18:59:24 +0100 Subject: Fix bug with PolyIndex and Variable.to_repr --- mdpoly/leaves.py | 2 +- mdpoly/types.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mdpoly/leaves.py b/mdpoly/leaves.py index 4032ead..8a018e6 100644 --- a/mdpoly/leaves.py +++ b/mdpoly/leaves.py @@ -49,7 +49,7 @@ class Var(Leaf, HasRepr): def to_repr(self, repr_type: type[T], state: State) -> T: r = repr_type() - idx = PolyVarIndex(varindex=state.index(self), power=1) + idx = PolyVarIndex.of_var(self, state), r.set(MatrixIndex.scalar, PolyIndex(idx), 1) return r, state diff --git a/mdpoly/types.py b/mdpoly/types.py index a0ea671..0a4c68e 100644 --- a/mdpoly/types.py +++ b/mdpoly/types.py @@ -70,18 +70,18 @@ class PolyVarIndex(NamedTuple): Concretely this represents things like x^2, y^4 """ - varindex: int + var_idx: int # Index in State.variables, not variable! power: Number @classmethod @property def constant(cls): """ Special index for constants, which have no variable """ - return cls(varindex=-1, power=0) + return cls(var_idx=-1, power=0) @classmethod def of_var(cls, variable: Var, state: State, power: Number =1) -> Self: - return cls(varindex=state.index(variable), power=power) + return cls(var_idx=state.index(variable), power=power) class PolyIndex(tuple[PolyVarIndex]): -- cgit v1.2.1