Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of matching_variables and remaining_columns_to_read is inefficient and can cause hangs #735

Closed
sbfnk opened this issue Feb 2, 2023 · 0 comments · Fixed by #736
Labels
bug Something isn't working

Comments

@sbfnk
Copy link
Contributor

sbfnk commented Feb 2, 2023

Describe the bug
The draws() function becomes prohibitively slow when used with many variables, e.g. large arrays. This is due to looping over all variables for matching in matching_variables and remaining_columns_to_read from read_cmdstan_csv.

To Reproduce
Example:

library("cmdstanr")

model_code <- '
parameters {
  array[100, 1000] real x;
}

model {
  for (i in 1:100) {
    for (j in 1:1000) {
      x[i, j] ~ std_normal();
    }
  }
}
'

stan_file <- tempfile(fileext = ".stan")
writeLines(model_code, stan_file)

model <- cmdstan_model(stan_file)

sim <- model$sample(chains = 1, iter_sampling = 1, fixed_param = TRUE)

dr <- R.utils::withTimeout(sim$draws(), timeout = 120)

running into a timeout in my instance.

Expected behavior
Ideally: improved run times.

CmdStanR version number
0.5.3

@sbfnk sbfnk added the bug Something isn't working label Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant