From 38fe86d9c9633406981d0053682631e541850705 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 9 May 2024 19:17:10 +0200 Subject: Check for uniqueness of names in ExpressionState --- polymatrix/expressionstate/mixins.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/polymatrix/expressionstate/mixins.py b/polymatrix/expressionstate/mixins.py index 9b4817b..f5a0c25 100644 --- a/polymatrix/expressionstate/mixins.py +++ b/polymatrix/expressionstate/mixins.py @@ -39,9 +39,16 @@ class ExpressionStateMixin( if not isinstance(var, Variable): raise ValueError("State can only index object of type Variable!") - # Check if already in there - if var in self.indices.keys(): - return self, self.indices[var] + for v, irange in self.indices.items(): + # Check if already in there + if v == var: + return self, irange + + # Check that there is not another variable with the same name + if v.name == var.name: + raise ValueError("Variable must have unique names! " + f"There is already a variable named {var.name} " + f"with shape {v.shape}") # If not save new index size = prod(var.shape) -- cgit v1.2.1