stan icon indicating copy to clipboard operation
stan copied to clipboard

corr_matrix of size 0 fails

Open ecmerkle opened this issue 5 years ago • 3 comments

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.

ecmerkle avatar Sep 30 '20 03:09 ecmerkle

Thanks for reporting this issue!

syclik avatar Sep 30 '20 04:09 syclik

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

syclik avatar Sep 30 '20 05:09 syclik

This also happens with corr_matrix[1].

syclik avatar Sep 30 '20 05:09 syclik