diff options
author | Nao Pross <np@0hm.ch> | 2024-03-03 01:10:18 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-03-03 01:10:18 +0100 |
commit | 42891113a39b245b7711c1d9366040fe3bf5976b (patch) | |
tree | e557d7fa8340fa30c93c1659c16f6d5ddc90c331 | |
parent | Fix PolyIndex.is_constant (diff) | |
download | mdpoly-42891113a39b245b7711c1d9366040fe3bf5976b.tar.gz mdpoly-42891113a39b245b7711c1d9366040fe3bf5976b.zip |
Fix State.from_index crash when trying to get constant term
-rw-r--r-- | mdpoly/state.py | 8 |
1 files 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 |