stan-dev / stan-dev/stan

corr_matrix of size 0 fails

Open
#2,958 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.8k
Forks
388
Avg merge
2d 17h
Merged PRs (30d)
15

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the R and Stan files in corrmat.zip with rstan or CmdStan to reproduce the zero-sized corr_matrix failure. Trace how corr_matrix handles a size of 0 and verify the model can initialize and sample successfully without std::bad_alloc or an improper-posterior error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, r
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.