From 080951550e4bc08cac3ba3f76593c9adbc2ba644 Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:49:02 +0000 Subject: [PATCH] refactor: load fims modules --- NAMESPACE | 3 ++ R/FIMS-package.R | 3 ++ R/RcppExports.R | 7 ++++ inst/include/interface/init.hpp | 2 ++ src/FIMS.cpp | 4 +-- src/RcppExports.cpp | 35 +++++++++++++++++++ .../interface/rcpp => src}/rcpp_interface.hpp | 27 +++++++------- vignettes/fims-path-maturity.Rmd | 4 +-- 8 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 R/RcppExports.R create mode 100644 src/RcppExports.cpp rename {inst/include/interface/rcpp => src}/rcpp_interface.hpp (94%) diff --git a/NAMESPACE b/NAMESPACE index 0235a83d..993b1bb9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,7 +3,10 @@ export("%>%") export(FIMSFrame) export(FIMSFrameAge) +export(Population) +export(clear) export(create_fims_rcpp_interface) +export(get_fixed) export(m_agecomp) export(m_index) export(m_landings) diff --git a/R/FIMS-package.R b/R/FIMS-package.R index 4e4a1421..c8563d3e 100644 --- a/R/FIMS-package.R +++ b/R/FIMS-package.R @@ -6,5 +6,8 @@ #' @import methods #' @importFrom ggplot2 .data #' @importFrom usethis use_template ui_stop +#' @export Population +#' @export clear +#' @export get_fixed ## usethis namespace: end NULL diff --git a/R/RcppExports.R b/R/RcppExports.R new file mode 100644 index 00000000..46bc786c --- /dev/null +++ b/R/RcppExports.R @@ -0,0 +1,7 @@ +# Generated by using Rcpp::compileAttributes() -> do not edit by hand +# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +clear <- function() { + invisible(.Call(`_FIMS_clear`)) +} + diff --git a/inst/include/interface/init.hpp b/inst/include/interface/init.hpp index bc066598..f9b08e1d 100644 --- a/inst/include/interface/init.hpp +++ b/inst/include/interface/init.hpp @@ -38,10 +38,12 @@ SEXP _rcpp_module_boot_fims(); *Callback definition to load the FIMS module. * */ +/* static const R_CallMethodDef CallEntries[] = { TMB_CALLDEFS, {"_rcpp_module_boot_fims", (DL_FUNC)&_rcpp_module_boot_fims, 0}, {NULL, NULL, 0}}; +*/ /** * diff --git a/src/FIMS.cpp b/src/FIMS.cpp index be893e09..0ce90d43 100644 --- a/src/FIMS.cpp +++ b/src/FIMS.cpp @@ -1,9 +1,9 @@ #include -#include "../inst/include/interface/rcpp/rcpp_interface.hpp" +#include "rcpp_interface.hpp" #include "../inst/include/interface/interface.hpp" -#include "../inst/include/interface/init.hpp" +//#include "../inst/include/interface/init.hpp" #include "../inst/include/common/model.hpp" /// @cond diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp new file mode 100644 index 00000000..31e9c56b --- /dev/null +++ b/src/RcppExports.cpp @@ -0,0 +1,35 @@ +// Generated by using Rcpp::compileAttributes() -> do not edit by hand +// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +#include +#include + +using namespace Rcpp; + +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + +// clear +void clear(); +RcppExport SEXP _FIMS_clear() { +BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + clear(); + return R_NilValue; +END_RCPP +} + +RcppExport SEXP _rcpp_module_boot_fims(); + +static const R_CallMethodDef CallEntries[] = { + {"_FIMS_clear", (DL_FUNC) &_FIMS_clear, 0}, + {"_rcpp_module_boot_fims", (DL_FUNC) &_rcpp_module_boot_fims, 0}, + {NULL, NULL, 0} +}; + +RcppExport void R_init_FIMS(DllInfo *dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); +} diff --git a/inst/include/interface/rcpp/rcpp_interface.hpp b/src/rcpp_interface.hpp similarity index 94% rename from inst/include/interface/rcpp/rcpp_interface.hpp rename to src/rcpp_interface.hpp index ea1d7f91..29f777ba 100644 --- a/inst/include/interface/rcpp/rcpp_interface.hpp +++ b/src/rcpp_interface.hpp @@ -11,17 +11,17 @@ #ifndef FIMS_INTERFACE_RCPP_INTERFACE_HPP #define FIMS_INTERFACE_RCPP_INTERFACE_HPP -#include "rcpp_objects/rcpp_data.hpp" -#include "rcpp_objects/rcpp_fleet.hpp" -#include "rcpp_objects/rcpp_growth.hpp" -#include "rcpp_objects/rcpp_maturity.hpp" -#include "rcpp_objects/rcpp_natural_mortality.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_natural_mortality.hpp" //#include "rcpp_objects/rcpp_nll.hpp" -#include "../../common/model.hpp" -#include "rcpp_objects/rcpp_population.hpp" -#include "rcpp_objects/rcpp_recruitment.hpp" -#include "rcpp_objects/rcpp_selectivity.hpp" -#include "rcpp_objects/rcpp_tmb_distribution.hpp" +#include "../inst/include/common/model.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp" +#include "../inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp" /** * @brief Create the TMB model object and add interface objects to it. */ @@ -235,9 +235,10 @@ void clear_internal() { d0->fixed_effects_parameters.clear(); d0->random_effects_parameters.clear(); } -/** - * Clears the vector of independent variables. +/* + * Clears the vector of independent variables */ +// [[Rcpp::export]] void clear() { // rcpp_interface_base.hpp FIMSRcppInterfaceBase::fims_interface_objects.clear(); @@ -321,7 +322,7 @@ RCPP_MODULE(fims) { Rcpp::function("CreateTMBModel", &CreateTMBModel); Rcpp::function("get_fixed", &get_fixed_parameters_vector); Rcpp::function("get_random", &get_random_parameters_vector); - Rcpp::function("clear", clear); + //Rcpp::function("clear", clear); Rcpp::function("clear_logs", clear_logs); Rcpp::function("clear_fims_log", clear_fims_log); Rcpp::function("clear_info_log", clear_info_log); diff --git a/vignettes/fims-path-maturity.Rmd b/vignettes/fims-path-maturity.Rmd index 2708c9a8..577c4e94 100644 --- a/vignettes/fims-path-maturity.Rmd +++ b/vignettes/fims-path-maturity.Rmd @@ -89,7 +89,7 @@ Also restarting or closing out your R session will free up memory. ## The Rcpp Interface The fields specific to the maturity module that are accessible from R are defined in the -[rcpp_interface.hpp](https://github.com/NOAA-FIMS/FIMS/blob/main/inst/include/interface/rcpp/rcpp_interface.hpp) file in the directory [inst/include/interface/rcpp](https://github.com/NOAA-FIMS/FIMS/tree/main/inst/include/interface/rcpp): +[rcpp_interface.hpp](https://github.com/NOAA-FIMS/FIMS/blob/main/src/rcpp_interface.hpp) file in the directory [inst/include/interface/rcpp](https://github.com/NOAA-FIMS/FIMS/tree/main/inst/include/interface/rcpp): ```{Rcpp, class.source = "rcppchunk", eval = FALSE} Rcpp::class_("LogisticMaturity") @@ -157,7 +157,7 @@ class Parameter { } ``` The fields from the `Parameter` class that are accessible from R are defined in the -[rcpp_interface.hpp](https://github.com/NOAA-FIMS/FIMS/blob/main/inst/include/interface/rcpp/rcpp_interface.hpp) file in the directory [inst/include/interface/rcpp](https://github.com/NOAA-FIMS/FIMS/tree/main/inst/include/interface/rcpp): +[rcpp_interface.hpp](https://github.com/NOAA-FIMS/FIMS/blob/main/src/rcpp_interface.hpp) file in the directory [inst/include/interface/rcpp](https://github.com/NOAA-FIMS/FIMS/tree/main/inst/include/interface/rcpp): ```{Rcpp, class.source = "rcppchunk", eval = FALSE} Rcpp::class_("Parameter")