File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -964,6 +964,7 @@ def add_coord(
964
964
if name in self .coords :
965
965
if not np .array_equal (values , self .coords [name ]):
966
966
raise ValueError (f"Duplicate and incompatible coordinate: { name } ." )
967
+ return
967
968
if length is not None and not isinstance (length , int | Variable ):
968
969
raise ValueError (
969
970
f"The `length` passed for the '{ name } ' coord must be an int, PyTensor Variable or None."
Original file line number Diff line number Diff line change 33
33
import scipy .stats as st
34
34
35
35
from pytensor .graph import graph_inputs
36
+ from pytensor .graph .basic import get_var_by_name
36
37
from pytensor .raise_op import Assert
37
38
from pytensor .tensor .random .op import RandomVariable
38
39
from pytensor .tensor .variable import TensorConstant
@@ -858,6 +859,19 @@ def test_nested_model_coords():
858
859
assert set (m2 .named_vars_to_dims ) < set (m1 .named_vars_to_dims )
859
860
860
861
862
+ def test_multiple_add_coords_with_same_name ():
863
+ coord = {"dim1" : ["a" , "b" , "c" ]}
864
+ with pm .Model (coords = coord ) as m :
865
+ a = pm .Normal ("a" , dims = "dim1" )
866
+ with pm .Model (coords = coord ) as nested_m :
867
+ b = pm .Normal ("b" , dims = "dim1" )
868
+ m .add_coords (coord )
869
+ c = pm .Normal ("c" , dims = "dim1" )
870
+ d = pm .Deterministic ("d" , a + b + c )
871
+ variables = get_var_by_name ([d ], "dim1" )
872
+ assert len (variables ) == 1 and variables [0 ] is m .dim_lengths ["dim1" ]
873
+
874
+
861
875
class TestSetUpdateCoords :
862
876
def test_shapeerror_from_set_data_dimensionality (self ):
863
877
with pm .Model () as pmodel :
You can’t perform that action at this time.
0 commit comments