Skip to content

Commit

Permalink
Merge pull request #122 from mclements/main
Browse files Browse the repository at this point in the history
Add plugin for using hesim inline
  • Loading branch information
dincerti authored Jul 16, 2024
2 parents e218e24 + 5d34844 commit f1c32cc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ src/*.gcda
doc
Meta
*_cache*
*~
30 changes: 30 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,33 @@ get_n_samples.array <- function(x){
stopifnot(is_3d_array(x))
return(dim(x)[1])
}

#' Code to use the hesim package inline. Not directly called by the user.
#' @param ... arguments
#' @examples
#' library(Rcpp)
#' sourceCpp(code="
#' // [[Rcpp::depends(hesim)]]
#' // [[Rcpp::depends(RcppArmadillo)]]
#' #include <hesim.h>
#' // [[Rcpp::export]]
#' double test_inline_gengamma(double mu, double sigma, double Q) {
#' hesim::stats::gengamma gg(mu, sigma, Q);
#' return gg.random();
#' }")
#' set.seed(12345)
#' test_inline_gengamma(1.0, 1.0, 1.0)
#' @keywords internal
#' @rdname plugin
inlineCxxPlugin <- function(...) {
ismacos <- Sys.info()[["sysname"]] == "Darwin"
openmpflag <- if (ismacos) "" else "$(SHLIB_OPENMP_CFLAGS)"
plugin <- Rcpp::Rcpp.plugin.maker(include.before = "#include <hesim.h>",
libs = paste(openmpflag,
"$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)"),
package = "hesim")
settings <- plugin()
settings$env$PKG_CPPFLAGS <- paste("-I../inst/include", openmpflag)
## if (!ismacos) settings$env$USE_CXX11 <- "yes"
settings
}
29 changes: 29 additions & 0 deletions man/plugin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1c32cc

Please sign in to comment.