Skip to content

[sol upstream candidate] cholesky_corr_free accepts matrices that are not correlation Cholesky factors #25

Description

@sims1253

cholesky_corr_free() checks only that its input is square. It does not verify
that the matrix is lower triangular, has a positive diagonal, or has unit row
norms. The source already notes the missing validation, and
check_cholesky_factor_corr() implements the required checks.

Minimal repro against develop at 344d7167a:

Eigen::MatrixXd bad(2, 2);
bad << 1.0, 0.0,
       0.5, 0.5;  // second row does not have unit norm
auto z = stan::math::cholesky_corr_free(bad);
auto roundtrip = stan::math::cholesky_corr_constrain(z, 2);
std::cout << (roundtrip - bad).cwiseAbs().maxCoeff();

Actual result:

0.366025

The inverse transform accepts a value outside its domain and returns an
unconstrained vector that does not reconstruct the input. Other invalid inputs
can reach square roots with negative arguments.

Call check_cholesky_factor_corr() before the transform. Add rejection tests for
a nonzero upper triangle, nonpositive diagonal, non-unit row, excessive partial
row norm, and nonfinite entries, plus a valid round-trip test.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions