From 34b5b8f6b433afe24c8d26a77307417f50ec0ff1 Mon Sep 17 00:00:00 2001 From: "Hamada S. Badr" Date: Tue, 20 Apr 2021 12:33:46 -0400 Subject: [PATCH 1/5] Update stan submodule --- .gitmodules | 2 +- StanHeaders/inst/include/upstream | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index a53093317..5fcb11d5f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "stan"] path = StanHeaders/inst/include/upstream - url = https://github.com/stan-dev/stan.git + url = https://github.com/hsbadr/stan.git ignore = dirty branch = develop diff --git a/StanHeaders/inst/include/upstream b/StanHeaders/inst/include/upstream index 0e12400b1..3eca708c2 160000 --- a/StanHeaders/inst/include/upstream +++ b/StanHeaders/inst/include/upstream @@ -1 +1 @@ -Subproject commit 0e12400b15c8795cfcbe57254f89fe02233b8e84 +Subproject commit 3eca708c231a9641480c103635806e2a3cd1dd11 From 0c2cb197a8deb0ae2e7978f8472b0c7741718fa9 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 20 Apr 2021 15:56:43 -0400 Subject: [PATCH 2/5] changes parse_data() for the cpp file to remove trailing double underscores and regex matches to numerics for working with Eigen::Map types in the stan model --- rstan/rstan/R/misc.R | 4 ++++ rstan/rstan/inst/include/rstan/stan_fit.hpp | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rstan/rstan/R/misc.R b/rstan/rstan/R/misc.R index 0038aa8a5..32e14f4b8 100644 --- a/rstan/rstan/R/misc.R +++ b/rstan/rstan/R/misc.R @@ -1604,6 +1604,10 @@ parse_data <- function(cppcode) { cppcode[private:public]) # get them from the calling environment objects <- objects[nzchar(trimws(objects))] + # Remove model internal name underscores in case of Eigen::Maps + objects = gsub("([0-9A-Za-z_]+)__", "\\1", objects) + # Remove any bad regex matches that found the end of an Eigen::Map. + objects = objects[suppressWarnings(is.na(as.numeric(objects)))] stuff <- list() for (int in seq_along(objects)) { stuff[[objects[int]]] <- dynGet(objects[int], inherits = FALSE, ifnotfound = NULL) diff --git a/rstan/rstan/inst/include/rstan/stan_fit.hpp b/rstan/rstan/inst/include/rstan/stan_fit.hpp index c2646b392..dfba5d523 100644 --- a/rstan/rstan/inst/include/rstan/stan_fit.hpp +++ b/rstan/rstan/inst/include/rstan/stan_fit.hpp @@ -411,12 +411,12 @@ int command(stan_args& args, Model& model, Rcpp::List& holder, "model that has no parameters."); int refresh = args.get_refresh(); unsigned int id = args.get_chain_id(); - + std::ostream nullout(nullptr); std::ostream& c_out = refresh ? Rcpp::Rcout : nullout; std::ostream& c_err = refresh ? rstan::io::rcerr : nullout; - stan::callbacks::stream_logger_with_chain_id + stan::callbacks::stream_logger_with_chain_id logger(c_out, c_out, c_out, c_err, c_err, id); R_CheckUserInterrupt_Functor interrupt; @@ -1016,7 +1016,7 @@ class stan_fit { get_all_flatnames(names_oi_, dims_oi_, fnames_oi_, true); // get_all_indices_col2row(dims_, midx_for_col2row); } - + stan_fit(SEXP data, SEXP seed, SEXP cxxf) : data_(data), model_(data_, Rcpp::as(seed), &rstan::io::rcout), @@ -1221,7 +1221,7 @@ class stan_fit { return __sexp_result; END_RCPP } - + SEXP standalone_gqs(SEXP pars, SEXP seed) { BEGIN_RCPP Rcpp::List holder; @@ -1229,7 +1229,7 @@ class stan_fit { R_CheckUserInterrupt_Functor interrupt; stan::callbacks::stream_logger logger(Rcpp::Rcout, Rcpp::Rcout, Rcpp::Rcout, rstan::io::rcerr, rstan::io::rcerr); - + const Eigen::Map draws(Rcpp::as >(pars)); std::unique_ptr sample_writer_ptr; @@ -1248,7 +1248,7 @@ class stan_fit { gq_size, draws.rows(), 0, gq_idx)); - + int ret = stan::services::error_codes::CONFIG; ret = stan::services::standalone_generate(model_, draws, Rcpp::as(seed), interrupt, logger, *sample_writer_ptr); From 871c32230b4e7923eeef43ea8c1979c2f0ec9a31 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 20 Apr 2021 16:06:14 -0400 Subject: [PATCH 3/5] update upstream to match 2.25 branch --- StanHeaders/inst/include/upstream | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StanHeaders/inst/include/upstream b/StanHeaders/inst/include/upstream index 3eca708c2..0e12400b1 160000 --- a/StanHeaders/inst/include/upstream +++ b/StanHeaders/inst/include/upstream @@ -1 +1 @@ -Subproject commit 3eca708c231a9641480c103635806e2a3cd1dd11 +Subproject commit 0e12400b15c8795cfcbe57254f89fe02233b8e84 From 6c22e0484f7b302ac838eea2371700be955ef677 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 20 Apr 2021 16:07:06 -0400 Subject: [PATCH 4/5] update gitmodules --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 5fcb11d5f..a53093317 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "stan"] path = StanHeaders/inst/include/upstream - url = https://github.com/hsbadr/stan.git + url = https://github.com/stan-dev/stan.git ignore = dirty branch = develop From 9ce95d5ab691fd816c55db8401c9bb11c9b23f3e Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 20 Apr 2021 16:41:11 -0400 Subject: [PATCH 5/5] Update rstan/rstan/R/misc.R Co-authored-by: Hamada S. Badr --- rstan/rstan/R/misc.R | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rstan/rstan/R/misc.R b/rstan/rstan/R/misc.R index 32e14f4b8..8a673b8ed 100644 --- a/rstan/rstan/R/misc.R +++ b/rstan/rstan/R/misc.R @@ -1602,12 +1602,14 @@ parse_data <- function(cppcode) { # pull out object names from the data block objects <- gsub("^.* ([0-9A-Za-z_]+).*;.*$", "\\1", cppcode[private:public]) - # get them from the calling environment - objects <- objects[nzchar(trimws(objects))] # Remove model internal name underscores in case of Eigen::Maps - objects = gsub("([0-9A-Za-z_]+)__", "\\1", objects) + objects <- gsub("([0-9A-Za-z_]+)__", "\\1", objects) # Remove any bad regex matches that found the end of an Eigen::Map. - objects = objects[suppressWarnings(is.na(as.numeric(objects)))] + objects <- gsub("^[[:digit:]]+", "\\1", objects) + # Remove empty characters and trim whitespaces + objects <- objects[nzchar(trimws(objects))] + + # Get them from the calling environment stuff <- list() for (int in seq_along(objects)) { stuff[[objects[int]]] <- dynGet(objects[int], inherits = FALSE, ifnotfound = NULL) @@ -1710,4 +1712,3 @@ test_221 <- function(cppcode) { grepl("Code generated by Stan version 2.2", cppcode, fixed = TRUE) || grepl("Code generated by Stan version 3", cppcode, fixed = TRUE) } -