Skip to content

Commit

Permalink
update with newest rstantools
Browse files Browse the repository at this point in the history
  • Loading branch information
helske committed Jul 25, 2023
1 parent 819bd9e commit 42bfc8d
Show file tree
Hide file tree
Showing 13 changed files with 7,695 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ LinkingTo:
SystemRequirements: C++14, GNU make
Biarch: true
VignetteBuilder: knitr
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
ByteCompile: true
URL: https://github.com/helske/walker
BugReports: https://github.com/helske/walker/issues
Expand Down
28 changes: 28 additions & 0 deletions R/stanmodels.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by rstantools. Do not edit by hand.

# names of stan models
stanmodels <- c("rw1_model", "rw1_model_naive", "walker_glm", "walker_lm")

# load each stan module
Rcpp::loadModule("stan_fit4rw1_model_mod", what = TRUE)
Rcpp::loadModule("stan_fit4rw1_model_naive_mod", what = TRUE)
Rcpp::loadModule("stan_fit4walker_glm_mod", what = TRUE)
Rcpp::loadModule("stan_fit4walker_lm_mod", what = TRUE)

# instantiate each stanmodel object
stanmodels <- sapply(stanmodels, function(model_name) {
# create C++ code for stan model
stan_file <- if(dir.exists("stan")) "stan" else file.path("inst", "stan")
stan_file <- file.path(stan_file, paste0(model_name, ".stan"))
stanfit <- rstan::stanc_builder(stan_file,
allow_undefined = TRUE,
obfuscate_model_name = FALSE)
stanfit$model_cpp <- list(model_cppname = stanfit$model_name,
model_cppcode = stanfit$cppcode)
# create stanmodel object
methods::new(Class = "stanmodel",
model_name = stanfit$model_name,
model_code = stanfit$model_code,
model_cpp = stanfit$model_cpp,
mk_cppmodule = function(x) get(paste0("rstantools_model_", model_name)))
})
5 changes: 3 additions & 2 deletions man/walker.Rd

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

11 changes: 11 additions & 0 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Generated by rstantools. Do not edit by hand.

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

STANC_FLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(ifelse(utils::packageVersion('rstan') >= '2.26', '-DUSE_STANC3',''))")
PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DRCPP_PARALLEL_USE_TBB=1 $(STANC_FLAGS) -D_HAS_AUTO_PTR_ETC=0
PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()")
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")

CXX_STD = CXX17
PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
9 changes: 9 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ BEGIN_RCPP
END_RCPP
}

RcppExport SEXP _rcpp_module_boot_stan_fit4rw1_model_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4rw1_model_naive_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4walker_glm_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4walker_lm_mod();

static const R_CallMethodDef CallEntries[] = {
{"_walker_predict_walker", (DL_FUNC) &_walker_predict_walker, 13},
{"_walker_predict_walker_glm", (DL_FUNC) &_walker_predict_walker_glm, 15},
{"_rcpp_module_boot_stan_fit4rw1_model_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4rw1_model_mod, 0},
{"_rcpp_module_boot_stan_fit4rw1_model_naive_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4rw1_model_naive_mod, 0},
{"_rcpp_module_boot_stan_fit4walker_glm_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4walker_glm_mod, 0},
{"_rcpp_module_boot_stan_fit4walker_lm_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4walker_lm_mod, 0},
{NULL, NULL, 0}
};

Expand Down
32 changes: 32 additions & 0 deletions src/stanExports_rw1_model.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Generated by rstantools. Do not edit by hand.

#include <Rcpp.h>
using namespace Rcpp ;
#include "stanExports_rw1_model.h"

RCPP_MODULE(stan_fit4rw1_model_mod) {


class_<rstan::stan_fit<stan_model, boost::random::ecuyer1988> >("rstantools_model_rw1_model")

.constructor<SEXP,SEXP,SEXP>()


.method("call_sampler", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::call_sampler)
.method("param_names", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_names)
.method("param_names_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_names_oi)
.method("param_fnames_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_fnames_oi)
.method("param_dims", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_dims)
.method("param_dims_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_dims_oi)
.method("update_param_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::update_param_oi)
.method("param_oi_tidx", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_oi_tidx)
.method("grad_log_prob", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::grad_log_prob)
.method("log_prob", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::log_prob)
.method("unconstrain_pars", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::unconstrain_pars)
.method("constrain_pars", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::constrain_pars)
.method("num_pars_unconstrained", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::num_pars_unconstrained)
.method("unconstrained_param_names", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::unconstrained_param_names)
.method("constrained_param_names", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::constrained_param_names)
.method("standalone_gqs", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::standalone_gqs)
;
}
Loading

0 comments on commit 42bfc8d

Please sign in to comment.