Skip to content

Commit

Permalink
Update R API to match C++ changes to set_stat_names and set_param_names
Browse files Browse the repository at this point in the history
  • Loading branch information
apulsipher committed Dec 9, 2024
1 parent b3096c6 commit 50346c8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export(set_name_tool)
export(set_name_virus)
export(set_observed_data)
export(set_param)
export(set_param_names)
export(set_params_names)
export(set_prob_death)
export(set_prob_death_fun)
export(set_prob_death_ptr)
Expand All @@ -215,7 +215,7 @@ export(set_recovery_enhancer)
export(set_recovery_enhancer_fun)
export(set_recovery_enhancer_ptr)
export(set_simulation_fun)
export(set_stat_names)
export(set_stats_names)
export(set_summary_fun)
export(set_susceptibility_reduction)
export(set_susceptibility_reduction_fun)
Expand Down
12 changes: 6 additions & 6 deletions R/LFMCMC.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ stopifnot_lfmcmc <- function(x) {
#' )
#'
#' # Print the results
#' set_stat_names(lfmcmc_model, get_states(model_sir))
#' set_param_names(lfmcmc_model, c("Immune recovery", "Infectiousness"))
#' set_stats_names(lfmcmc_model, get_states(model_sir))
#' set_params_names(lfmcmc_model, c("Immune recovery", "Infectiousness"))
#'
#' print(lfmcmc_model)
#'
Expand Down Expand Up @@ -228,10 +228,10 @@ use_kernel_fun_gaussian <- function(lfmcmc) {
#' @param names The model parameter names
#' @returns The lfmcmc model with the parameter names added
#' @export
set_param_names <- function(lfmcmc, names) {
set_params_names <- function(lfmcmc, names) {

stopifnot_lfmcmc(lfmcmc)
set_param_names_cpp(lfmcmc, names)
set_params_names_cpp(lfmcmc, names)
invisible(lfmcmc)

}
Expand All @@ -241,10 +241,10 @@ set_param_names <- function(lfmcmc, names) {
#' @param names The model stats names
#' @returns The lfmcmc model with the stats names added
#' @export
set_stat_names <- function(lfmcmc, names) {
set_stats_names <- function(lfmcmc, names) {

stopifnot_lfmcmc(lfmcmc)
set_stat_names_cpp(lfmcmc, names)
set_stats_names_cpp(lfmcmc, names)
invisible(lfmcmc)

}
Expand Down
8 changes: 4 additions & 4 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ use_kernel_fun_gaussian_cpp <- function(lfmcmc) {
.Call(`_epiworldR_use_kernel_fun_gaussian_cpp`, lfmcmc)
}

set_param_names_cpp <- function(lfmcmc, names) {
.Call(`_epiworldR_set_param_names_cpp`, lfmcmc, names)
set_params_names_cpp <- function(lfmcmc, names) {
.Call(`_epiworldR_set_params_names_cpp`, lfmcmc, names)
}

set_stat_names_cpp <- function(lfmcmc, names) {
.Call(`_epiworldR_set_stat_names_cpp`, lfmcmc, names)
set_stats_names_cpp <- function(lfmcmc, names) {
.Call(`_epiworldR_set_stats_names_cpp`, lfmcmc, names)
}

get_mean_params_cpp <- function(lfmcmc) {
Expand Down
8 changes: 4 additions & 4 deletions inst/tinytest/test-lfmcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ expect_silent(run_lfmcmc(
seed = model_seed
))

expect_silent(set_stat_names(lfmcmc_model, get_states(model_sir)))
expect_silent(set_param_names(lfmcmc_model, c("Immune recovery", "Infectiousness")))
expect_silent(set_stats_names(lfmcmc_model, get_states(model_sir)))
expect_silent(set_params_names(lfmcmc_model, c("Immune recovery", "Infectiousness")))

# Check printing LFMCMC --------------------------------------------------------
expect_stdout(print(lfmcmc_model))
Expand Down Expand Up @@ -233,8 +233,8 @@ expect_error(set_summary_fun(not_lfmcmc, sumfun), expected_error_msg)
expect_error(set_kernel_fun(not_lfmcmc, kernelfun), expected_error_msg)
expect_error(use_kernel_fun_gaussian(not_lfmcmc), expected_error_msg)

expect_error(set_param_names(not_lfmcmc, c("Par 1", "Par 2")), expected_error_msg)
expect_error(set_stat_names(not_lfmcmc, get_states(model_sir)), expected_error_msg)
expect_error(set_params_names(not_lfmcmc, c("Par 1", "Par 2")), expected_error_msg)
expect_error(set_stats_names(not_lfmcmc, get_states(model_sir)), expected_error_msg)

expect_error(get_mean_params(not_lfmcmc), expected_error_msg)
expect_error(get_mean_stats(not_lfmcmc), expected_error_msg)
Expand Down
12 changes: 6 additions & 6 deletions man/LFMCMC.Rd

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

16 changes: 8 additions & 8 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,17 @@ extern "C" SEXP _epiworldR_use_kernel_fun_gaussian_cpp(SEXP lfmcmc) {
END_CPP11
}
// lfmcmc.cpp
SEXP set_param_names_cpp(SEXP lfmcmc, std::vector< std::string > names);
extern "C" SEXP _epiworldR_set_param_names_cpp(SEXP lfmcmc, SEXP names) {
SEXP set_params_names_cpp(SEXP lfmcmc, std::vector< std::string > names);
extern "C" SEXP _epiworldR_set_params_names_cpp(SEXP lfmcmc, SEXP names) {
BEGIN_CPP11
return cpp11::as_sexp(set_param_names_cpp(cpp11::as_cpp<cpp11::decay_t<SEXP>>(lfmcmc), cpp11::as_cpp<cpp11::decay_t<std::vector< std::string >>>(names)));
return cpp11::as_sexp(set_params_names_cpp(cpp11::as_cpp<cpp11::decay_t<SEXP>>(lfmcmc), cpp11::as_cpp<cpp11::decay_t<std::vector< std::string >>>(names)));
END_CPP11
}
// lfmcmc.cpp
SEXP set_stat_names_cpp(SEXP lfmcmc, std::vector< std::string > names);
extern "C" SEXP _epiworldR_set_stat_names_cpp(SEXP lfmcmc, SEXP names) {
SEXP set_stats_names_cpp(SEXP lfmcmc, std::vector< std::string > names);
extern "C" SEXP _epiworldR_set_stats_names_cpp(SEXP lfmcmc, SEXP names) {
BEGIN_CPP11
return cpp11::as_sexp(set_stat_names_cpp(cpp11::as_cpp<cpp11::decay_t<SEXP>>(lfmcmc), cpp11::as_cpp<cpp11::decay_t<std::vector< std::string >>>(names)));
return cpp11::as_sexp(set_stats_names_cpp(cpp11::as_cpp<cpp11::decay_t<SEXP>>(lfmcmc), cpp11::as_cpp<cpp11::decay_t<std::vector< std::string >>>(names)));
END_CPP11
}
// lfmcmc.cpp
Expand Down Expand Up @@ -1182,7 +1182,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_epiworldR_set_name_virus_cpp", (DL_FUNC) &_epiworldR_set_name_virus_cpp, 2},
{"_epiworldR_set_observed_data_cpp", (DL_FUNC) &_epiworldR_set_observed_data_cpp, 2},
{"_epiworldR_set_param_cpp", (DL_FUNC) &_epiworldR_set_param_cpp, 3},
{"_epiworldR_set_param_names_cpp", (DL_FUNC) &_epiworldR_set_param_names_cpp, 2},
{"_epiworldR_set_params_names_cpp", (DL_FUNC) &_epiworldR_set_params_names_cpp, 2},
{"_epiworldR_set_prob_death_cpp", (DL_FUNC) &_epiworldR_set_prob_death_cpp, 2},
{"_epiworldR_set_prob_death_fun_cpp", (DL_FUNC) &_epiworldR_set_prob_death_fun_cpp, 3},
{"_epiworldR_set_prob_death_ptr_cpp", (DL_FUNC) &_epiworldR_set_prob_death_ptr_cpp, 3},
Expand All @@ -1197,7 +1197,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_epiworldR_set_recovery_enhancer_fun_cpp", (DL_FUNC) &_epiworldR_set_recovery_enhancer_fun_cpp, 3},
{"_epiworldR_set_recovery_enhancer_ptr_cpp", (DL_FUNC) &_epiworldR_set_recovery_enhancer_ptr_cpp, 3},
{"_epiworldR_set_simulation_fun_cpp", (DL_FUNC) &_epiworldR_set_simulation_fun_cpp, 2},
{"_epiworldR_set_stat_names_cpp", (DL_FUNC) &_epiworldR_set_stat_names_cpp, 2},
{"_epiworldR_set_stats_names_cpp", (DL_FUNC) &_epiworldR_set_stats_names_cpp, 2},
{"_epiworldR_set_summary_fun_cpp", (DL_FUNC) &_epiworldR_set_summary_fun_cpp, 2},
{"_epiworldR_set_susceptibility_reduction_cpp", (DL_FUNC) &_epiworldR_set_susceptibility_reduction_cpp, 2},
{"_epiworldR_set_susceptibility_reduction_fun_cpp", (DL_FUNC) &_epiworldR_set_susceptibility_reduction_fun_cpp, 3},
Expand Down
8 changes: 4 additions & 4 deletions src/lfmcmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,22 @@ SEXP use_kernel_fun_gaussian_cpp(
// *************************************

[[cpp11::register]]
SEXP set_param_names_cpp(
SEXP set_params_names_cpp(
SEXP lfmcmc,
std::vector< std::string > names
) {
WrapLFMCMC(lfmcmc_ptr)(lfmcmc);
lfmcmc_ptr->set_param_names(names);
lfmcmc_ptr->set_params_names(names);
return lfmcmc;
}

[[cpp11::register]]
SEXP set_stat_names_cpp(
SEXP set_stats_names_cpp(
SEXP lfmcmc,
std::vector< std::string > names
) {
WrapLFMCMC(lfmcmc_ptr)(lfmcmc);
lfmcmc_ptr->set_stat_names(names);
lfmcmc_ptr->set_stats_names(names);
return lfmcmc;
}

Expand Down
4 changes: 2 additions & 2 deletions vignettes/likelihood-free-mcmc.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ run_lfmcmc(
)
# Print the results
set_stat_names(lfmcmc_model, get_states(model_sir))
set_param_names(lfmcmc_model, c("Immune recovery", "Infectiousness"))
set_stats_names(lfmcmc_model, get_states(model_sir))
set_params_names(lfmcmc_model, c("Immune recovery", "Infectiousness"))
print(lfmcmc_model)
```

0 comments on commit 50346c8

Please sign in to comment.