seed = NA results in a clang-UBSAN error on CRAN
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Hi,
Bit of a niche issue but thought I would post it just to make others aware. Apparently if you set the seed in STAN to NA it results in clang's UBSAN checks (as run by CRAN) throwing an error. A reproducible example can be found by running the following code:
library(rstan)
stancode <- "
data { real y[100]; }
parameters { real mu; real<lower=0> sigma; }
model { y ~ normal(mu,sigma); }
"
model <- stan_model(model_code = stancode)
fit <- sampling(
model,
list(y = rnorm(100, 1.6, 0.2)),
iter = 200,
chains = 2,
refresh = 0,
seed = NA
)
/opt/R/4.1.3/lib64/R/library/Rcpp/include/Rcpp/internal/caster.h:30:25: runtime error: nan is outside the range of representable values of type 'unsigned int'
#0 0x7fae25c75e4d (/tmp/Rtmpb2eTru/file197f05cd19.so+0x2a4e4d)
#1 0x7fae25c70c57 (/tmp/Rtmpb2eTru/file197f05cd19.so+0x29fc57)
#2 0x7fae25c46921 (/tmp/Rtmpb2eTru/file197f05cd19.so+0x275921)
#3 0x7fae2fae733e (/opt/R/4.1.3/lib64/R/library/Rcpp/libs/Rcpp.so+0x11733e)
#4 0x7fae36dd6335 (/opt/R/4.1.3/lib64/R/lib/libR.so+0x5b9335)
#5 0x7fae36f515ba (/opt/R/4.1.3/lib64/R/lib/libR.so+0x7345ba)
#6 0x7fae36f3086b (/opt/R/4.1.3/lib64/R/lib/libR.so+0x71386b)
#7 0x7fae36f9d429 (/opt/R/4.1.3/lib64/R/lib/libR.so+0x780429)
#8 0x7fae36f99872 (/opt/R/4.1.3/lib64/R/lib/libR.so+0x77c872)
#9 0x7fae36f55cd0 (/opt/R/4.1.3/lib64/R/lib/libR.so+0x738cd0)
#10 0x7fae36f3086b (/opt/R/4.1.3/lib64/R/lib/libR.so+0x71386b)
......
My expectation would have been that an assertion in R throws an error if seed=NA is not supported.
RStan Version:
2.21.3
R Version:
R version 4.1.3 (2022-03-10) - compiled from source using flags specified by the CRAN team
I put together a dockerfile to re-create this environment here
Operating System:
Fedora 34
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the sampling(..., seed = NA) example from the issue, using the linked Fedora CRAN UBSAN Dockerfile if needed. Trace the seed handling around the RStan sampling entry point and the reported Rcpp caster error. Done means seed = NA produces a supported, explicit result without the clang-UBSAN runtime error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100