Skip to content

Commit

Permalink
Minor edit
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithJF82 committed Mar 6, 2024
1 parent 9389c1a commit d338de1
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 5 deletions.
4 changes: 4 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ dust_cpu_SEIRV_Model_simulate <- function(ptr, time_end) {
.Call(`_YEP_dust_cpu_SEIRV_Model_simulate`, ptr, time_end)
}

dust_cpu_SEIRV_Model_run_adjoint <- function(ptr) {
.Call(`_YEP_dust_cpu_SEIRV_Model_run_adjoint`, ptr)
}

dust_cpu_SEIRV_Model_set_index <- function(ptr, r_index) {
.Call(`_YEP_dust_cpu_SEIRV_Model_set_index`, ptr, r_index)
}
Expand Down
18 changes: 16 additions & 2 deletions R/dust.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Generated by dust (version 0.14.10) - do not edit
## Generated by dust (version 0.15.1) - do not edit
SEIRV_Model <- R6::R6Class(
"dust",
cloneable = FALSE,
Expand Down Expand Up @@ -47,6 +47,7 @@ SEIRV_Model <- R6::R6Class(
alloc = dust_cpu_SEIRV_Model_alloc,
run = dust_cpu_SEIRV_Model_run,
simulate = dust_cpu_SEIRV_Model_simulate,
run_adjoint = dust_cpu_SEIRV_Model_run_adjoint,
set_index = dust_cpu_SEIRV_Model_set_index,
n_state = dust_cpu_SEIRV_Model_n_state,
update_state = dust_cpu_SEIRV_Model_update_state,
Expand Down Expand Up @@ -105,6 +106,19 @@ SEIRV_Model <- R6::R6Class(
m
},

run_adjoint = function() {
res <- private$methods_$run_adjoint(private$ptr_)
## This approach may want to change, because it won't cope well
## with cases where are gradient is structured with respect to
## some parameters, but perhaps it's still a reasonable thing to
## do? While we have array-free models it's fine though.
nms <- private$info_$adjoint
if (!is.null(nms) && length(nms) == length(res$gradient)) {
names(res$gradient) <- nms
}
res
},

set_index = function(index) {
private$methods_$set_index(private$ptr_, index)
private$index_ <- index
Expand Down Expand Up @@ -267,7 +281,7 @@ SEIRV_Model <- R6::R6Class(
}
))
class(SEIRV_Model) <- c("dust_generator", class(SEIRV_Model))
## Generated by odin.dust (version 0.3.8) - do not edit
## Generated by odin.dust (version 0.3.10) - do not edit
SEIRV_Model$set("public", "transform_variables", function(y) {
info <- self$info()
set_dim <- function(x, dimx) {
Expand Down
7 changes: 6 additions & 1 deletion inst/dust/SEIRV_Model.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Generated by odin.dust (version 0.3.8) - do not edit
// Generated by odin.dust (version 0.3.10) - do not edit
template <typename real_type, typename container>
__host__ __device__ real_type odin_sum1(const container x, size_t from, size_t to);
template <typename real_type, typename container>
__host__ __device__ real_type odin_sum2(const container x, int from_i, int to_i, int from_j, int to_j, int dim_x_1);
template <typename real_type, typename T, typename U>
__host__ __device__ real_type fintdiv(T x, U y) {
return std::floor(x / y);
}

template <typename real_type, typename T, typename U>
__host__ __device__ real_type fmodr(T x, U y) {
real_type tmp = std::fmod(static_cast<real_type>(x),
Expand Down
3 changes: 3 additions & 0 deletions inst/odin/SEIRV_Model.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ inv_P_nV[1:N_age] <- 1.0/P_nV[i]
P[1:N_age] <- P_nV[i] + V[i] #Total population by age group (excluding E+I)
P_tot <- sum(P) #Total overall population (excluding E+I)
inv_P[1:N_age] <- 1.0/P[i]

vacc_rate[1:N_age] <- vacc_rate_daily[i,as.integer(year_i)]*vaccine_efficacy*dt*P[i] #Total no. vaccinations by age


Expand Down Expand Up @@ -133,6 +134,7 @@ dim(R_new) <- N_age




dim(P_nV) <- N_age
dim(inv_P_nV) <- N_age
dim(P) <- N_age
Expand All @@ -151,3 +153,4 @@ dim(dP2_all) <- c(N_age, n_years)
dim(vacc_rate_daily) <- c(N_age, n_years)



16 changes: 14 additions & 2 deletions src/SEIRV_Model.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dust (version 0.14.10) - do not edit
// Generated by dust (version 0.15.1) - do not edit
#include <cpp11.hpp>

[[cpp11::register]]
Expand All @@ -18,6 +18,9 @@ SEXP dust_cpu_SEIRV_Model_run(SEXP ptr, cpp11::sexp r_time_end);
[[cpp11::register]]
SEXP dust_cpu_SEIRV_Model_simulate(SEXP ptr, cpp11::sexp time_end);

[[cpp11::register]]
SEXP dust_cpu_SEIRV_Model_run_adjoint(SEXP ptr);

[[cpp11::register]]
SEXP dust_cpu_SEIRV_Model_set_index(SEXP ptr, cpp11::sexp r_index);

Expand Down Expand Up @@ -69,11 +72,16 @@ void dust_cpu_SEIRV_Model_set_stochastic_schedule(SEXP ptr, SEXP time);
SEXP dust_cpu_SEIRV_Model_ode_statistics(SEXP ptr);
#include <dust/r/dust.hpp>

// Generated by odin.dust (version 0.3.8) - do not edit
// Generated by odin.dust (version 0.3.10) - do not edit
template <typename real_type, typename container>
__host__ __device__ real_type odin_sum1(const container x, size_t from, size_t to);
template <typename real_type, typename container>
__host__ __device__ real_type odin_sum2(const container x, int from_i, int to_i, int from_j, int to_j, int dim_x_1);
template <typename real_type, typename T, typename U>
__host__ __device__ real_type fintdiv(T x, U y) {
return std::floor(x / y);
}

template <typename real_type, typename T, typename U>
__host__ __device__ real_type fmodr(T x, U y) {
real_type tmp = std::fmod(static_cast<real_type>(x),
Expand Down Expand Up @@ -702,6 +710,10 @@ SEXP dust_cpu_SEIRV_Model_simulate(SEXP ptr, cpp11::sexp r_time_end) {
return dust::r::dust_simulate<model_cpu>(ptr, r_time_end);
}

SEXP dust_cpu_SEIRV_Model_run_adjoint(SEXP ptr) {
return dust::r::dust_run_adjoint<model_cpu>(ptr);
}

SEXP dust_cpu_SEIRV_Model_set_index(SEXP ptr, cpp11::sexp r_index) {
dust::r::dust_set_index<model_cpu>(ptr, r_index);
return R_NilValue;
Expand Down
Binary file modified src/SEIRV_Model.o
Binary file not shown.
Binary file modified src/YEP.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ extern "C" SEXP _YEP_dust_cpu_SEIRV_Model_simulate(SEXP ptr, SEXP time_end) {
END_CPP11
}
// SEIRV_Model.cpp
SEXP dust_cpu_SEIRV_Model_run_adjoint(SEXP ptr);
extern "C" SEXP _YEP_dust_cpu_SEIRV_Model_run_adjoint(SEXP ptr) {
BEGIN_CPP11
return cpp11::as_sexp(dust_cpu_SEIRV_Model_run_adjoint(cpp11::as_cpp<cpp11::decay_t<SEXP>>(ptr)));
END_CPP11
}
// SEIRV_Model.cpp
SEXP dust_cpu_SEIRV_Model_set_index(SEXP ptr, cpp11::sexp r_index);
extern "C" SEXP _YEP_dust_cpu_SEIRV_Model_set_index(SEXP ptr, SEXP r_index) {
BEGIN_CPP11
Expand Down Expand Up @@ -162,6 +169,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_YEP_dust_cpu_SEIRV_Model_resample", (DL_FUNC) &_YEP_dust_cpu_SEIRV_Model_resample, 2},
{"_YEP_dust_cpu_SEIRV_Model_rng_state", (DL_FUNC) &_YEP_dust_cpu_SEIRV_Model_rng_state, 3},
{"_YEP_dust_cpu_SEIRV_Model_run", (DL_FUNC) &_YEP_dust_cpu_SEIRV_Model_run, 2},
{"_YEP_dust_cpu_SEIRV_Model_run_adjoint", (DL_FUNC) &_YEP_dust_cpu_SEIRV_Model_run_adjoint, 1},
{"_YEP_dust_cpu_SEIRV_Model_set_data", (DL_FUNC) &_YEP_dust_cpu_SEIRV_Model_set_data, 3},
{"_YEP_dust_cpu_SEIRV_Model_set_index", (DL_FUNC) &_YEP_dust_cpu_SEIRV_Model_set_index, 2},
{"_YEP_dust_cpu_SEIRV_Model_set_n_threads", (DL_FUNC) &_YEP_dust_cpu_SEIRV_Model_set_n_threads, 2},
Expand Down
Binary file modified src/cpp11.o
Binary file not shown.

0 comments on commit d338de1

Please sign in to comment.