Skip to content
Open
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
5 changes: 2 additions & 3 deletions stan/math/prim/constraint/cholesky_corr_free.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<value_type_t<T>, Dynamic, 1> z(K);
int k = 0;
Expand Down
3 changes: 1 addition & 2 deletions stan/math/prim/constraint/cov_matrix_free.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ template <typename T, require_eigen_t<T>* = nullptr>
inline Eigen::Matrix<value_type_t<T>, 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();
Expand Down
10 changes: 6 additions & 4 deletions test/unit/math/prim/constraint/cholesky_corr_transform_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ TEST(ProbTransform, CholeskyCorrelation4) {
using Eigen::Dynamic;
using Eigen::Matrix;
Matrix<double, Dynamic, Dynamic> 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<double, Dynamic, 1> y = stan::math::cholesky_corr_free(L);

Expand Down Expand Up @@ -103,7 +104,8 @@ TEST(ProbTransform, CholeskyCorrelationRoundTrips) {
test_cholesky_correlation_values(L2);

Matrix<double, Dynamic, Dynamic> 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);
}
Loading