Skip to content

refactor: move _precition_mv_normal_logp into a seperate function #7895

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions pymc/distributions/multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,22 @@ def rv_op(cls, mean, tau, *, method: str = "cholesky", rng=None, size=None):
method=method,
)(rng, size, mean, tau)


@_logprob.register
def precision_mv_normal_logp(op: PrecisionMvNormalRV, value, rng, size, mean, tau, **kwargs):
[value] = value
def _precision_mv_normal_logp(value, mean, tau):
k = value.shape[-1].astype("floatX")

delta = value - mean
quadratic_form = delta.T @ tau @ delta
logdet, posdef = _logdet_from_cholesky(nan_lower_cholesky(tau))
logp = -0.5 * (k * pt.log(2 * np.pi) + quadratic_form) + logdet

return logp, posdef

@_logprob.register
def precision_mv_normal_logp(op: PrecisionMvNormalRV, value, rng, size, mean, tau, **kwargs):
[value] = value

logp, posdef = _precision_mv_normal_logp(value, mean, tau)

return check_parameters(
logp,
posdef,
Expand Down