cholesky_corr_free only checks squareness. A lower-triangular matrix with positive diagonal but non-unit row norms is accepted, and the round trip returns a different matrix:
Eigen::MatrixXd L(2, 2);
L << 1, 0, 0.5, 0.5; // row 2 norm is sqrt(0.5), not 1
Eigen::VectorXd z = stan::math::cholesky_corr_free(L); // no throw
// z = [0.549306] (= atanh(0.5))
Eigen::MatrixXd back = stan::math::cholesky_corr_constrain(z, 2);
// back(1,1) = 0.866025 — not the 0.5 in the input
There is a comment in the source noting the missing validation (// should validate lower-triangular, unit lengths), and check_cholesky_factor_corr already exists and is the natural seam.
Reachable from user code through the unconstraining path, same as #3379
Environment:
- Ubuntu 22.04.5 LTS (WSL2, kernel 6.18.33.2-microsoft-standard-WSL2), x86_64
- stan-dev/math develop @ d20b238
- g++ 11.4.0 (Ubuntu 22.04), -std=c++17
Related to #1700 (cholesky_corr_* housekeeping ask, closed without a fix). The in-source comment above is still unresolved.
cholesky_corr_freeonly checks squareness. A lower-triangular matrix with positive diagonal but non-unit row norms is accepted, and the round trip returns a different matrix:There is a comment in the source noting the missing validation (
// should validate lower-triangular, unit lengths), andcheck_cholesky_factor_corralready exists and is the natural seam.Reachable from user code through the unconstraining path, same as #3379
Environment:
Related to #1700 (cholesky_corr_* housekeeping ask, closed without a fix). The in-source comment above is still unresolved.