From 386aa21b57c6d0709f636988d5074482224b18cb Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 1 Oct 2023 17:35:47 +0300 Subject: [PATCH 1/2] Add dedicated hpp generation step --- R/model.R | 7 ++++--- R/utils.R | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/R/model.R b/R/model.R index c8d6ea60..3031aed9 100644 --- a/R/model.R +++ b/R/model.R @@ -626,10 +626,13 @@ compile <- function(quiet = TRUE, } stancflags_standalone <- c("--standalone-functions", stancflags_val, stancflags_combined) self$functions$hpp_code <- get_standalone_hpp(temp_stan_file, stancflags_standalone) + private$model_methods_env_ <- new.env() + private$model_methods_env_$hpp_code_ <- get_standalone_hpp(temp_stan_file, c(stancflags_val, stancflags_combined)) self$functions$external <- !is.null(user_header) self$functions$existing_exe <- FALSE - stancflags_val <- paste0("STANCFLAGS += ", stancflags_val, paste0(" ", stancflags_combined, collapse = " ")) + all_stancflags <- paste0(stancflags_val, paste0(" ", stancflags_combined, collapse = " ")) + stancflags_val <- paste0("STANCFLAGS += ", all_stancflags) if (!dry_run) { @@ -712,10 +715,8 @@ compile <- function(quiet = TRUE, private$precompile_cpp_options_ <- NULL private$precompile_stanc_options_ <- NULL private$precompile_include_paths_ <- NULL - private$model_methods_env_ <- new.env() if(!dry_run) { - suppressWarnings(private$model_methods_env_$hpp_code_ <- readLines(private$hpp_file_, warn = FALSE)) if (compile_model_methods) { expose_model_methods(env = private$model_methods_env_, verbose = !quiet, diff --git a/R/utils.R b/R/utils.R index 4f40ca0c..be03344b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -800,6 +800,10 @@ create_skeleton <- function(param_metadata, model_variables, } get_standalone_hpp <- function(stan_file, stancflags) { + name <- strip_ext(basename(stan_file)) + path <- dirname(stan_file) + hpp_path <- file.path(path, paste0(name, ".hpp")) + status <- withr::with_path( c( toolchain_PATH_env_var(), @@ -807,16 +811,12 @@ get_standalone_hpp <- function(stan_file, stancflags) { ), wsl_compatible_run( command = stanc_cmd(), - args = c(stan_file, - stancflags), + args = c(paste0("--o=", hpp_path), stancflags, stan_file), wd = cmdstan_path(), error_on_status = FALSE ) ) if (status$status == 0) { - name <- strip_ext(basename(stan_file)) - path <- dirname(stan_file) - hpp_path <- file.path(path, paste0(name, ".hpp")) hpp <- suppressWarnings(readLines(hpp_path, warn = FALSE)) unlink(hpp_path) hpp From d180e4e275a58f315aca687aa32474ce2e266d2a Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 1 Oct 2023 17:39:14 +0300 Subject: [PATCH 2/2] Stray change --- R/model.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/model.R b/R/model.R index 3031aed9..c061e9ac 100644 --- a/R/model.R +++ b/R/model.R @@ -631,8 +631,7 @@ compile <- function(quiet = TRUE, self$functions$external <- !is.null(user_header) self$functions$existing_exe <- FALSE - all_stancflags <- paste0(stancflags_val, paste0(" ", stancflags_combined, collapse = " ")) - stancflags_val <- paste0("STANCFLAGS += ", all_stancflags) + stancflags_val <- paste0("STANCFLAGS += ", stancflags_val, paste0(" ", stancflags_combined, collapse = " ")) if (!dry_run) {