|
23 | 23 | import pytest
|
24 | 24 | import scipy.sparse as sps
|
25 | 25 |
|
26 |
| -from aesara.graph.basic import Constant, Variable, ancestors |
| 26 | +from aesara.graph.basic import Constant, Variable, ancestors, equal_computations |
27 | 27 | from aesara.tensor.random.basic import normal, uniform
|
28 | 28 | from aesara.tensor.random.op import RandomVariable
|
29 | 29 | from aesara.tensor.subtensor import AdvancedIncSubtensor, AdvancedIncSubtensor1
|
@@ -529,3 +529,24 @@ def test_rvs_to_value_vars():
|
529 | 529 | assert a_value_var in res_ancestors
|
530 | 530 | assert b_value_var in res_ancestors
|
531 | 531 | assert c_value_var in res_ancestors
|
| 532 | + |
| 533 | + |
| 534 | +def test_rvs_to_value_vars_nested(): |
| 535 | + # Test that calling rvs_to_value_vars in models with nested transformations |
| 536 | + # does not change the original rvs in place. See issue #5172 |
| 537 | + with pm.Model() as m: |
| 538 | + one = pm.LogNormal("one", mu=0) |
| 539 | + two = pm.LogNormal("two", mu=at.log(one)) |
| 540 | + |
| 541 | + # We add potentials or deterministics that are not in topological order |
| 542 | + pm.Potential("two_pot", two) |
| 543 | + pm.Potential("one_pot", one) |
| 544 | + |
| 545 | + before = aesara.clone_replace(m.free_RVs) |
| 546 | + |
| 547 | + # This call would change the model free_RVs in place in #5172 |
| 548 | + res, _ = rvs_to_value_vars(m.potentials, apply_transforms=True) |
| 549 | + |
| 550 | + after = aesara.clone_replace(m.free_RVs) |
| 551 | + |
| 552 | + assert equal_computations(before, after) |
0 commit comments