Skip to content

Commit

Permalink
Merge pull request #1 from SteveBronder/fix/data-checking
Browse files Browse the repository at this point in the history
changes parse_data() to remove trailing double underscores
  • Loading branch information
hsbadr authored Apr 20, 2021
2 parents d43aeb7 + 9ce95d5 commit 36fa553
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions rstan/rstan/R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

12 changes: 6 additions & 6 deletions rstan/rstan/inst/include/rstan/stan_fit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<boost::uint32_t>(seed), &rstan::io::rcout),
Expand Down Expand Up @@ -1221,15 +1221,15 @@ class stan_fit {
return __sexp_result;
END_RCPP
}

SEXP standalone_gqs(SEXP pars, SEXP seed) {
BEGIN_RCPP
Rcpp::List holder;

R_CheckUserInterrupt_Functor interrupt;
stan::callbacks::stream_logger logger(Rcpp::Rcout, Rcpp::Rcout, Rcpp::Rcout,
rstan::io::rcerr, rstan::io::rcerr);

const Eigen::Map<Eigen::MatrixXd> draws(Rcpp::as<Eigen::Map<Eigen::MatrixXd> >(pars));

std::unique_ptr<rstan_sample_writer> sample_writer_ptr;
Expand All @@ -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<unsigned int>(seed), interrupt, logger, *sample_writer_ptr);
Expand Down

0 comments on commit 36fa553

Please sign in to comment.