Skip to content

Commit 059bc65

Browse files
dmiltr3The Meridian Authors
authored andcommitted
Cast numeric parameters to float in distributions_are_equal before comparing.
PiperOrigin-RevId: 956020619
1 parent a0e93ad commit 059bc65

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

meridian/model/prior_distribution.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,12 +1247,19 @@ def distributions_are_equal(
12471247
if a_params.keys() != b_params.keys():
12481248
return False
12491249

1250+
def _maybe_cast_to_float(val):
1251+
dtype = getattr(val, 'dtype', type(val))
1252+
if 'int' in backend.standardize_dtype(dtype):
1253+
return backend.to_tensor(val, dtype=backend.float_dtype)
1254+
return val
1255+
12501256
for key in a_params.keys():
12511257
if isinstance(
12521258
a_params[key], (backend.Tensor, np.ndarray, float, int)
12531259
) and isinstance(b_params[key], (backend.Tensor, np.ndarray, float, int)):
1254-
a_val = backend.cast(a_params[key], backend.float_dtype)
1255-
b_val = backend.cast(b_params[key], backend.float_dtype)
1260+
a_val = _maybe_cast_to_float(a_params[key])
1261+
b_val = _maybe_cast_to_float(b_params[key])
1262+
12561263
if not backend.allclose(a_val, b_val):
12571264
return False
12581265
else:

0 commit comments

Comments
 (0)