seed = NA results in a clang-UBSAN error on CRAN
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
Hi,
I recently faced a similar problem where setting the seed in STAN to a negative integer results in clang's UBSAN checks (as run by CRAN) throwing the same error.