stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.58k stars 368 forks source link

corr_matrix of size 0 fails #2958

Open ecmerkle opened 4 years ago

ecmerkle commented 4 years ago

Summary:

Defining a size 0 correlation matrix leads to std::bad_alloc in rstan. This is related to #2588, where it is suggested that corr_matrix and related types should be able to work for size 0. #2588 was closed, but I think the "allow size 0" issue was never addressed.

Reproducible Steps:

This zip file contains an R file and stan file (run with rstan), illustrating the issue: corrmat.zip

Current Output:

std::bad_alloc if the corr_matrix size is 0.

Expected Output:

Optimally, this model would still sample when the corr_matrix size is 0.

Current Version:

I am using rstan 2.21.2 with R 4.0.2. I also reproduced with CmdStan 2.24.0, which reported:

Exception initializing step size. Posterior is improper. Please check your model.

syclik commented 4 years ago

Thanks for reporting this issue!

syclik commented 4 years ago

I verified this issue. Happens with v2.24.0 and also with current develop. (I'm not sure it's in Math.)

syclik commented 4 years ago

This also happens with corr_matrix[1].