Skip to content

Commit

Permalink
Add test for interactions between missing, default and explicit updat…
Browse files Browse the repository at this point in the history
…es in `compile_pymc`
  • Loading branch information
ricardoV94 authored and twiecki committed Mar 25, 2022
1 parent e4a07c1 commit 7aa520c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pymc/tests/test_aesaraf.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,26 @@ def test_compile_pymc_with_updates():
f = compile_pymc([], x, updates={x: x + 1})
assert f() == 0
assert f() == 1


def test_compile_pymc_missing_default_explicit_updates():
rng = aesara.shared(np.random.default_rng(0))
x = pm.Normal.dist(rng=rng)

# By default, compile_pymc should update the rng of x
f = compile_pymc([], x)
assert f() != f()

# An explicit update should override the default_update, like aesara.function does
# For testing purposes, we use an update that leaves the rng unchanged
f = compile_pymc([], x, updates={rng: rng})
assert f() == f()

# If we specify a custom default_update directly it should use that instead.
rng.default_update = rng
f = compile_pymc([], x)
assert f() == f()

# And again, it should be overridden by an explicit update
f = compile_pymc([], x, updates={rng: x.owner.outputs[0]})
assert f() != f()

0 comments on commit 7aa520c

Please sign in to comment.