diff --git a/stan/math/prim/constraint/cholesky_corr_free.hpp b/stan/math/prim/constraint/cholesky_corr_free.hpp index 334895546c4..fc2e689e554 100644 --- a/stan/math/prim/constraint/cholesky_corr_free.hpp +++ b/stan/math/prim/constraint/cholesky_corr_free.hpp @@ -16,10 +16,9 @@ inline auto cholesky_corr_free(const T& x) { using Eigen::Matrix; using std::sqrt; - check_square("cholesky_corr_free", "x", x); - // should validate lower-triangular, unit lengths - const auto& x_ref = to_ref(x); + check_cholesky_factor_corr("cholesky_corr_free", "x", x_ref); + int K = (x.rows() * (x.rows() - 1)) / 2; Matrix, Dynamic, 1> z(K); int k = 0; diff --git a/stan/math/prim/constraint/cov_matrix_free.hpp b/stan/math/prim/constraint/cov_matrix_free.hpp index 4d71f179665..81b614ca162 100644 --- a/stan/math/prim/constraint/cov_matrix_free.hpp +++ b/stan/math/prim/constraint/cov_matrix_free.hpp @@ -38,8 +38,7 @@ template * = nullptr> inline Eigen::Matrix, Eigen::Dynamic, 1> cov_matrix_free( const T& y) { const auto& y_ref = to_ref(y); - check_square("cov_matrix_free", "y", y_ref); - check_nonzero_size("cov_matrix_free", "y", y_ref); + check_cov_matrix("cov_matrix_free", "y", y_ref); using std::log; int K = y_ref.rows(); diff --git a/test/unit/math/prim/constraint/cholesky_corr_transform_test.cpp b/test/unit/math/prim/constraint/cholesky_corr_transform_test.cpp index 4f6deed1af4..5644fcb446c 100644 --- a/test/unit/math/prim/constraint/cholesky_corr_transform_test.cpp +++ b/test/unit/math/prim/constraint/cholesky_corr_transform_test.cpp @@ -6,8 +6,9 @@ TEST(ProbTransform, CholeskyCorrelation4) { using Eigen::Dynamic; using Eigen::Matrix; Matrix L(4, 4); - L << 1, 0, 0, 0, -0.2, 0.9797959, 0, 0, 0.5, -0.3, 0.8124038, 0, 0.7, -0.2, - 0.6, 0.3316625; + L << 1., 0., 0., 0., 0.137406408, 0.990514755, 0., 0., 0.182409918, + 0.217317336, 0.958905521, 0., -0.13727584, 0.443593876, 0.837969972, + 0.286681258; Matrix y = stan::math::cholesky_corr_free(L); @@ -103,7 +104,8 @@ TEST(ProbTransform, CholeskyCorrelationRoundTrips) { test_cholesky_correlation_values(L2); Matrix L4(4, 4); - L4 << 1, 0, 0, 0, -0.2, 0.9797959, 0, 0, 0.5, -0.3, 0.8124038, 0, 0.7, -0.2, - 0.6, 0.3316625; + L4 << 1., 0., 0., 0., 0.14489293, 0.98944734, 0., 0., -0.050876204, + -0.884785168, 0.463213577, 0., -0.412684102, -0.49899983, -0.67896005, + 0.345983023; test_cholesky_correlation_values(L4); }