Empty Fit Object

Operating System: OS X 10.12.6, R version 3.4.2
Interface Version: 2.17.2
Output of writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))):

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined

CXX=clang++ -arch x86_64 -ftemplate-depth-256

I’m trying to fit the relatively simple model

data {
  int N;
  int R;

generated quantities {
  real<lower=0> lambda[R];
  int y[R, N];

  for (r in 1:R) {
		lambda[r] = fabs(normal_rng(0, 5));
    for (n in 1:N) 
      y[r, n] = poisson_rng(lambda[r]);

with the command

R <- 10000
N <- 1000

simu_data <- list("N" = N, "R" = R)

fit <- stan(file=‘example.stan', data=simu_data, iter=1,
            chains=1, seed=4938483, algorithm="Fixed_param")

It’s a hefty array but should no problem fitting in memory. But when the call to stan returns an empty fit object and if I try to run again the R OS X application crashes.

Any ideas what’s up?

I can at least confirm that I also get an empty object (no crash though) on Ubuntu so it’s not an OS X thing.

I don’t know what’s up. I just tried it and it crashed RStudio on my Mac before returning anything. Then I ran it again in the terminal and it doesn’t crash but doesn’t assign anything to fit at all, not even an empty object.

What happens if iter=2?

The underlying error message is in the tempdir and is

Error: segfault from C stack overflow

I think there is something about the way that integer arrays get stored in rstan that puts them on the stack instead of the heap.

1 Like

Free beer says it’s the same bug with RCpp’s list destructor.

Quite possibly. It can be worked around with

fit <- stan("example.stan", chains = 1, iter = 1, algorithm = "Fixed_param", 
            sample_file = "draws.csv", pars = c("y", "lambda"), include = FALSE)

and then possibly read draws.csv off the disk in one of various ways. But I crash reading off the disk.