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

Faster CSV read with multiple chains #419

Merged
merged 9 commits into from
Jan 4, 2021
Merged

Faster CSV read with multiple chains #419

merged 9 commits into from
Jan 4, 2021

Conversation

rok-cesnovar
Copy link
Member

Summary

We should not be running posterior::bind_draws when looping over the chains but instead call it a single time once we read in all chains.

For this example:

library(cmdstanr)
model_code <- "
parameters {
  real k;
}

transformed parameters {
  real x[20000] = rep_array(k, 20000);
}

model {
  k ~ normal(0, 1);
}
"
model_file <- write_stan_file(model_code)
mod <- cmdstan_model(model_file)
fit <- mod$sample(iter_sampling = 2000, validate_csv = FALSE, chains = 4)

start <- Sys.time()
f <- fit$draws()
print(Sys.time() - start)

the $draws() call goes from 28s to 19s. There is no difference for 1 chain.

Copyright and Licensing

Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Rok Češnovar

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

@codecov-io
Copy link

codecov-io commented Dec 26, 2020

Codecov Report

Merging #419 (ef3d394) into master (aa9bb61) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #419      +/-   ##
==========================================
- Coverage   91.77%   91.72%   -0.06%     
==========================================
  Files          12       12              
  Lines        2773     2768       -5     
==========================================
- Hits         2545     2539       -6     
- Misses        228      229       +1     
Impacted Files Coverage Δ
R/csv.R 98.95% <100.00%> (-0.03%) ⬇️
R/fit.R 98.37% <100.00%> (-0.39%) ⬇️
R/utils.R 91.89% <100.00%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa9bb61...ef3d394. Read the comment docs.

@jgabry
Copy link
Member

jgabry commented Jan 4, 2021

Awesome! Looks good.

@jgabry jgabry merged commit a27d933 into master Jan 4, 2021
@jgabry jgabry deleted the faster_CSV_read branch January 4, 2021 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants