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