diff --git a/stan/math/prim/err/check_cholesky_factor.hpp b/stan/math/prim/err/check_cholesky_factor.hpp index 099d2bc3986..2cb2c2d0db5 100644 --- a/stan/math/prim/err/check_cholesky_factor.hpp +++ b/stan/math/prim/err/check_cholesky_factor.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -34,7 +35,7 @@ inline void check_cholesky_factor(const char* function, const char* name, const Mat& y) { check_less_or_equal(function, "columns and rows of Cholesky factor", y.cols(), y.rows()); - check_positive(function, "columns of Cholesky factor", y.cols()); + check_nonnegative(function, "columns of Cholesky factor", y.cols()); auto&& y_ref = to_ref(value_of_rec(y)); check_lower_triangular(function, name, y_ref); check_positive(function, name, y_ref.diagonal()); diff --git a/test/unit/math/prim/prob/lkj_corr_test.cpp b/test/unit/math/prim/prob/lkj_corr_test.cpp index 220f19eb828..e379642999b 100644 --- a/test/unit/math/prim/prob/lkj_corr_test.cpp +++ b/test/unit/math/prim/prob/lkj_corr_test.cpp @@ -3,6 +3,19 @@ #include #include +TEST(ProbDistributionsLkjCorr, testZero) { + boost::random::mt19937 rng; + unsigned int K = 0; + Eigen::MatrixXd Sigma(K, K); + Sigma.setZero(); + Sigma.diagonal().setOnes(); + double eta = stan::math::uniform_rng(0, 2, rng); + double f = stan::math::do_lkj_constant(eta, K); + EXPECT_FLOAT_EQ(0, stan::math::lkj_corr_cholesky_lpdf(Sigma, eta)); + eta = 1.0; + EXPECT_FLOAT_EQ(0, stan::math::lkj_corr_cholesky_lpdf(Sigma, eta)); +} + TEST(ProbDistributionsLkjCorr, testIdentity) { boost::random::mt19937 rng; unsigned int K = 4;