From 42891113a39b245b7711c1d9366040fe3bf5976b Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 3 Mar 2024 01:10:18 +0100 Subject: Fix State.from_index crash when trying to get constant term --- mdpoly/state.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mdpoly/state.py b/mdpoly/state.py index 739ec7a..6f47964 100644 --- a/mdpoly/state.py +++ b/mdpoly/state.py @@ -4,7 +4,7 @@ from dataclasses import dataclass, field if TYPE_CHECKING: from .types import Number - from .leaves import Var, Param + from .leaves import Var, Param, Const Index = int @@ -30,7 +30,11 @@ class State: return self.variables[var] - def from_index(self, index: Index) -> Var: + def from_index(self, index: Index) -> Var | Const: + if index == -1: + from .leaves import Const + return Const(value=1, name="1") + for var, idx in self.variables.items(): if idx == index: return var -- cgit v1.2.1