Skip to content

Commit 36fa553

Browse files
authored
Merge pull request #1 from SteveBronder/fix/data-checking
changes parse_data() to remove trailing double underscores
2 parents d43aeb7 + 9ce95d5 commit 36fa553

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

rstan/rstan/R/misc.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,8 +1602,14 @@ parse_data <- function(cppcode) {
16021602
# pull out object names from the data block
16031603
objects <- gsub("^.* ([0-9A-Za-z_]+).*;.*$", "\\1",
16041604
cppcode[private:public])
1605-
# get them from the calling environment
1605+
# Remove model internal name underscores in case of Eigen::Maps
1606+
objects <- gsub("([0-9A-Za-z_]+)__", "\\1", objects)
1607+
# Remove any bad regex matches that found the end of an Eigen::Map.
1608+
objects <- gsub("^[[:digit:]]+", "\\1", objects)
1609+
# Remove empty characters and trim whitespaces
16061610
objects <- objects[nzchar(trimws(objects))]
1611+
1612+
# Get them from the calling environment
16071613
stuff <- list()
16081614
for (int in seq_along(objects)) {
16091615
stuff[[objects[int]]] <- dynGet(objects[int], inherits = FALSE, ifnotfound = NULL)
@@ -1706,4 +1712,3 @@ test_221 <- function(cppcode) {
17061712
grepl("Code generated by Stan version 2.2", cppcode, fixed = TRUE) ||
17071713
grepl("Code generated by Stan version 3", cppcode, fixed = TRUE)
17081714
}
1709-

rstan/rstan/inst/include/rstan/stan_fit.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,12 @@ int command(stan_args& args, Model& model, Rcpp::List& holder,
411411
"model that has no parameters.");
412412
int refresh = args.get_refresh();
413413
unsigned int id = args.get_chain_id();
414-
414+
415415
std::ostream nullout(nullptr);
416416
std::ostream& c_out = refresh ? Rcpp::Rcout : nullout;
417417
std::ostream& c_err = refresh ? rstan::io::rcerr : nullout;
418418

419-
stan::callbacks::stream_logger_with_chain_id
419+
stan::callbacks::stream_logger_with_chain_id
420420
logger(c_out, c_out, c_out, c_err, c_err, id);
421421

422422
R_CheckUserInterrupt_Functor interrupt;
@@ -1016,7 +1016,7 @@ class stan_fit {
10161016
get_all_flatnames(names_oi_, dims_oi_, fnames_oi_, true);
10171017
// get_all_indices_col2row(dims_, midx_for_col2row);
10181018
}
1019-
1019+
10201020
stan_fit(SEXP data, SEXP seed, SEXP cxxf) :
10211021
data_(data),
10221022
model_(data_, Rcpp::as<boost::uint32_t>(seed), &rstan::io::rcout),
@@ -1221,15 +1221,15 @@ class stan_fit {
12211221
return __sexp_result;
12221222
END_RCPP
12231223
}
1224-
1224+
12251225
SEXP standalone_gqs(SEXP pars, SEXP seed) {
12261226
BEGIN_RCPP
12271227
Rcpp::List holder;
12281228

12291229
R_CheckUserInterrupt_Functor interrupt;
12301230
stan::callbacks::stream_logger logger(Rcpp::Rcout, Rcpp::Rcout, Rcpp::Rcout,
12311231
rstan::io::rcerr, rstan::io::rcerr);
1232-
1232+
12331233
const Eigen::Map<Eigen::MatrixXd> draws(Rcpp::as<Eigen::Map<Eigen::MatrixXd> >(pars));
12341234

12351235
std::unique_ptr<rstan_sample_writer> sample_writer_ptr;
@@ -1248,7 +1248,7 @@ class stan_fit {
12481248
gq_size,
12491249
draws.rows(), 0,
12501250
gq_idx));
1251-
1251+
12521252
int ret = stan::services::error_codes::CONFIG;
12531253
ret = stan::services::standalone_generate(model_, draws,
12541254
Rcpp::as<unsigned int>(seed), interrupt, logger, *sample_writer_ptr);

0 commit comments

Comments
 (0)