Skip to content

Commit d40fffe

Browse files
committed
add integration test
1 parent 694660c commit d40fffe

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/sampling/test_forward.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,36 @@ def test_mutable_coords_volatile(self):
428428
"offsets",
429429
}
430430

431+
def test_length_coords_volatile(self):
432+
with pm.Model() as model:
433+
model.add_coord("trial", length=3)
434+
x = pm.Normal("x", dims="trial")
435+
y = pm.Deterministic("y", x.mean())
436+
437+
# Same coord length -- `x` is not volatile
438+
trace_same_len = az_from_dict(
439+
posterior={"x": [[[np.pi] * 3]]},
440+
coords={"trial": range(3)},
441+
dims={"x": ["trial"]},
442+
)
443+
with model:
444+
pp_same_len = pm.sample_posterior_predictive(
445+
trace_same_len, var_names=["y"]
446+
).posterior_predictive
447+
assert pp_same_len["y"] == np.pi
448+
449+
# Coord length changed -- `x` is volatile
450+
trace_diff_len = az_from_dict(
451+
posterior={"x": [[[np.pi] * 2]]},
452+
coords={"trial": range(2)},
453+
dims={"x": ["trial"]},
454+
)
455+
with model:
456+
pp_diff_len = pm.sample_posterior_predictive(
457+
trace_diff_len, var_names=["y"]
458+
).posterior_predictive
459+
assert pp_diff_len["y"] != np.pi
460+
431461

432462
class TestSamplePPC:
433463
def test_normal_scalar(self):

0 commit comments

Comments
 (0)