corr_matrix of size 0 fails
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.
Thanks for reporting this issue!
I verified this issue. Happens with v2.24.0 and also with current develop. (I'm not sure it's in Math.)
This also happens with corr_matrix[1].