Skip to content

Commit

Permalink
modify c++ function
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Nov 1, 2024
1 parent 04d70b0 commit 8b1ce43
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by cpp11: do not edit by hand

convert_log2_scale_inverse_cpp <- function(dt, vars_to_transform) {
.Call(`_epikinetics_convert_log2_scale_inverse_cpp`, dt, vars_to_transform)
convert_log2_scale_inverse_cpp <- function(dt, vars_to_transform, lower_limit) {
.Call(`_epikinetics_convert_log2_scale_inverse_cpp`, dt, vars_to_transform, lower_limit)
}

simulate_trajectories_cpp <- function(person_params) {
Expand Down
5 changes: 3 additions & 2 deletions src/convert_log_scale_inverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ using namespace cpp11;

[[cpp11::register]]
cpp11::data_frame convert_log2_scale_inverse_cpp(cpp11::writable::list dt,
cpp11::strings vars_to_transform) {
cpp11::strings vars_to_transform,
double lower_limit) {

for (int i = 0; i < vars_to_transform.size(); i++) {
std::string var = vars_to_transform[i];
Expand All @@ -13,7 +14,7 @@ cpp11::data_frame convert_log2_scale_inverse_cpp(cpp11::writable::list dt,

// Apply the inverse transformation
for (int j = 0; j < col.size(); j++) {
col[j] = 2 * pow(2, col[j]);
col[j] = lower_limit * pow(2, col[j]);
}

// Replace the column
Expand Down
8 changes: 4 additions & 4 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <R_ext/Visibility.h>

// convert_log_scale_inverse.cpp
cpp11::data_frame convert_log2_scale_inverse_cpp(cpp11::writable::list dt, cpp11::strings vars_to_transform);
extern "C" SEXP _epikinetics_convert_log2_scale_inverse_cpp(SEXP dt, SEXP vars_to_transform) {
cpp11::data_frame convert_log2_scale_inverse_cpp(cpp11::writable::list dt, cpp11::strings vars_to_transform, double lower_limit);
extern "C" SEXP _epikinetics_convert_log2_scale_inverse_cpp(SEXP dt, SEXP vars_to_transform, SEXP lower_limit) {
BEGIN_CPP11
return cpp11::as_sexp(convert_log2_scale_inverse_cpp(cpp11::as_cpp<cpp11::decay_t<cpp11::writable::list>>(dt), cpp11::as_cpp<cpp11::decay_t<cpp11::strings>>(vars_to_transform)));
return cpp11::as_sexp(convert_log2_scale_inverse_cpp(cpp11::as_cpp<cpp11::decay_t<cpp11::writable::list>>(dt), cpp11::as_cpp<cpp11::decay_t<cpp11::strings>>(vars_to_transform), cpp11::as_cpp<cpp11::decay_t<double>>(lower_limit)));
END_CPP11
}
// simulate_trajectories.cpp
Expand All @@ -22,7 +22,7 @@ extern "C" SEXP _epikinetics_simulate_trajectories_cpp(SEXP person_params) {

extern "C" {
static const R_CallMethodDef CallEntries[] = {
{"_epikinetics_convert_log2_scale_inverse_cpp", (DL_FUNC) &_epikinetics_convert_log2_scale_inverse_cpp, 2},
{"_epikinetics_convert_log2_scale_inverse_cpp", (DL_FUNC) &_epikinetics_convert_log2_scale_inverse_cpp, 3},
{"_epikinetics_simulate_trajectories_cpp", (DL_FUNC) &_epikinetics_simulate_trajectories_cpp, 1},
{NULL, NULL, 0}
};
Expand Down

0 comments on commit 8b1ce43

Please sign in to comment.