Skip to content

Commit

Permalink
Merge pull request #863 from stan-dev/fix-hpp-generation
Browse files Browse the repository at this point in the history
Add dedicated hpp generation step for future cmdstan compatibility
  • Loading branch information
rok-cesnovar authored Jan 8, 2024
2 parents 48a2b3e + 447f5f7 commit 187ede9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ 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

Expand Down Expand Up @@ -720,10 +722,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,
Expand Down
10 changes: 5 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -800,23 +800,23 @@ 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(),
tbb_path()
),
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
Expand Down

0 comments on commit 187ede9

Please sign in to comment.