Skip to content

Add test for Blockwise logp regression #6995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tests/distributions/test_multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
# limitations under the License.

import functools as ft
import re
import warnings

import numpy as np
import numpy.random as npr
import numpy.testing as npt
import pytensor
import pytensor.tensor as pt
import pytest
import scipy.special as sp
import scipy.stats as st

from pytensor import tensor as pt
from pytensor.tensor import TensorVariable
from pytensor.tensor.blockwise import Blockwise
from pytensor.tensor.random.utils import broadcast_params
from pytensor.tensor.slinalg import Cholesky

Expand Down Expand Up @@ -2314,6 +2313,21 @@ def test_mvnormal_no_cholesky_in_model_logp():
assert not contains_cholesky_op(logp_dlogp._pytensor_function.maker.fgraph)


def test_mvnormal_blockwise_solve_opt():
"""Check that no blockwise show up in the d/logp graph of a 2D MvNormal with a single covariance.

See #6993
"""
with pm.Model() as m:
pm.MvNormal("y", mu=0, cov=pt.diag([2, 2]), shape=(3, 2))

logp = m.logp()
dlogp = pytensor.grad(logp, wrt=m.value_vars[0])
fn = m.compile_fn(inputs=m.value_vars, outs=[logp, dlogp], point_fn=False)

assert not any(isinstance(node.op, Blockwise) for node in fn.maker.fgraph.apply_nodes)


def test_mvnormal_mu_convenience():
"""Test that mu is broadcasted to the length of cov and provided a default of zero"""
x = pm.MvNormal.dist(cov=np.eye(3))
Expand Down