Skip to content

Commit

Permalink
Re-add missing checks, revert test changes from #3007
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian authored and syclik committed Feb 23, 2024
1 parent e4f5889 commit c1c2960
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 8 deletions.
7 changes: 5 additions & 2 deletions stan/math/prim/prob/inv_wishart_cholesky_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ return_type_t<T_y, T_dof, T_scale> inv_wishart_cholesky_lpdf(
static const char* function = "inv_wishart_cholesky_lpdf";
Eigen::Index k = L_Y.rows();
check_greater(function, "Degrees of freedom parameter", nu, k - 1);
check_size_match(function, "Rows of random variable", L_Y.rows(),
"columns of scale parameter", L_S.rows());

check_square(function, "Cholesky random variable", L_Y);
check_square(function, "Cholesky Scale parameter", L_S);
check_size_match(function, "side length of random variable", L_Y.rows(),
"side length of scale parameter", L_S.rows());

T_L_Y_ref L_Y_ref = L_Y;
check_cholesky_factor(function, "Cholesky random variable", L_Y_ref);
Expand Down
1 change: 1 addition & 0 deletions stan/math/prim/prob/inv_wishart_cholesky_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ inline Eigen::MatrixXd inv_wishart_cholesky_rng(double nu,
using Eigen::MatrixXd;
static const char* function = "inv_wishart_cholesky_rng";
index_type_t<MatrixXd> k = L_S.rows();
check_square(function, "Cholesky Scale matrix", L_S);
check_greater(function, "degrees of freedom > dims - 1", nu, k - 1);
check_cholesky_factor(function, "Cholesky Scale matrix", L_S);

Expand Down
4 changes: 3 additions & 1 deletion stan/math/prim/prob/multi_normal_cholesky_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ return_type_t<T_y, T_loc, T_covar> multi_normal_cholesky_lpdf(
"size of location parameter", size_mu);
check_size_match(function, "Size of random variable", size_y,
"rows of covariance parameter", L.rows());

check_size_match(function, "Size of random variable", size_y,
"columns of covariance parameter", L.cols());

for (size_t i = 0; i < size_vec; i++) {
check_finite(function, "Location parameter", mu_vec[i]);
check_not_nan(function, "Random variable", y_vec[i]);
Expand Down
7 changes: 5 additions & 2 deletions stan/math/prim/prob/wishart_cholesky_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ return_type_t<T_y, T_dof, T_scale> wishart_cholesky_lpdf(const T_y& L_Y,
Eigen::Index k = L_Y.rows();

check_greater(function, "Degrees of freedom parameter", nu, k - 1);
check_size_match(function, "Rows of random variable", L_Y.rows(),
"columns of scale parameter", L_S.rows());

check_square(function, "Cholesky random variable", L_Y);
check_square(function, "Cholesky scale parameter", L_S);
check_size_match(function, "side length of random variable", L_Y.rows(),
"side length of scale parameter", L_S.rows());

T_L_Y_ref L_Y_ref = L_Y;
check_cholesky_factor(function, "Cholesky random variable", L_Y_ref);
Expand Down
1 change: 1 addition & 0 deletions stan/math/prim/prob/wishart_cholesky_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ inline Eigen::MatrixXd wishart_cholesky_rng(double nu,
static const char* function = "wishart_cholesky_rng";
index_type_t<MatrixXd> k = L_S.rows();
check_greater(function, "degrees of freedom > dims - 1", nu, k - 1);
check_square(function, "Cholesky Scale matrix", L_S);
check_cholesky_factor(function, "Cholesky Scale matrix", L_S);

MatrixXd B = MatrixXd::Zero(k, k);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/prim/prob/inv_wishart_cholesky_rng_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ TEST(ProbDistributionsInvWishartCholesky, rng) {
boost::random::mt19937 rng;

MatrixXd omega(3, 4);
EXPECT_THROW(inv_wishart_cholesky_rng(3.0, omega, rng), std::domain_error);
EXPECT_THROW(inv_wishart_cholesky_rng(3.0, omega, rng),
std::invalid_argument);

MatrixXd sigma(3, 3);
sigma << 9.0, -3.0, 0.0, -3.0, 4.0, 1.0, 0.0, 1.0, 3.0;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/prim/prob/wishart_cholesky_rng_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TEST(ProbDistributionsWishartCholesky, rng) {
boost::random::mt19937 rng;

MatrixXd omega(3, 4);
EXPECT_THROW(wishart_cholesky_rng(3.0, omega, rng), std::domain_error);
EXPECT_THROW(wishart_cholesky_rng(3.0, omega, rng), std::invalid_argument);

MatrixXd sigma(3, 3);
sigma << 9.0, -3.0, 0.0, -3.0, 4.0, 1.0, 0.0, 1.0, 3.0;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/prim/prob/wishart_cholesky_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ TEST(ProbDistributionsWishartCholesky, error) {
nu = 5;
MatrixXd Y(2, 1);
EXPECT_THROW(wishart_cholesky_lpdf(Y, nu, MatrixXd::Identity(2, 2)),
std::domain_error);
std::invalid_argument);

nu = 5;
EXPECT_THROW(wishart_cholesky_lpdf(MatrixXd::Identity(3, 3), nu,
Expand Down

0 comments on commit c1c2960

Please sign in to comment.