Skip to content

Added check that nu must be a scalar in MvStudentTRV #5241

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 3 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions pymc/distributions/multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ class MvStudentTRV(RandomVariable):
dtype = "floatX"
_print_name = ("MvStudentT", "\\operatorname{MvStudentT}")

def make_node(self, rng, size, dtype, nu, mu, cov):
nu = at.as_tensor_variable(nu)
if not nu.ndim == 0:
raise ValueError("nu must be a scalar (ndim=0).")

return super().make_node(rng, size, dtype, nu, mu, cov)

def __call__(self, nu, mu=None, cov=None, size=None, **kwargs):

dtype = aesara.config.floatX if self.dtype == "floatX" else self.dtype
Expand Down
13 changes: 13 additions & 0 deletions pymc/tests/test_distributions_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import functools
import itertools
import re

from typing import Callable, List, Optional

Expand Down Expand Up @@ -1115,8 +1116,20 @@ def mvstudentt_rng_fn(self, size, nu, mu, cov, rng):
"check_pymc_params_match_rv_op",
"check_pymc_draws_match_reference",
"check_rv_size",
"test_errors",
]

def test_errors(self):
msg = "nu must be a scalar (ndim=0)."
with pm.Model():
with pytest.raises(ValueError, match=re.escape(msg)):
mvstudentt = pm.MvStudentT(
"mvstudentt",
nu=np.array([1, 2]),
mu=np.ones(2),
cov=np.full((2, 2), np.ones(2)),
)


class TestMvStudentTChol(BaseTestDistribution):
pymc_dist = pm.MvStudentT
Expand Down