diff --git a/rstan/rstan/R/misc.R b/rstan/rstan/R/misc.R index 0038aa8a5..8a673b8ed 100644 --- a/rstan/rstan/R/misc.R +++ b/rstan/rstan/R/misc.R @@ -1602,8 +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 + # 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 <- 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) @@ -1706,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) } - 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);