summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-05-09 19:17:10 +0200
committerNao Pross <np@0hm.ch>2024-05-09 19:17:10 +0200
commit38fe86d9c9633406981d0053682631e541850705 (patch)
tree749653e2aab203e8ee03715326a5e20659c77b2c
parentRemove redundant case in FromStateMonadMixin (diff)
downloadpolymatrix-38fe86d9c9633406981d0053682631e541850705.tar.gz
polymatrix-38fe86d9c9633406981d0053682631e541850705.zip
Check for uniqueness of names in ExpressionState
-rw-r--r--polymatrix/expressionstate/mixins.py13
1 files 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)