Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/mtimehx #1119

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions inst/base/mrgsolv.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ struct evdata {
amt = 0.0;
rate = 0.0;
now = false;
check_unique = true;
}
double time;
int evid;
int cmt;
double amt;
double rate;
bool now;
bool check_unique;
};

// Some functions for reporting values during a
Expand Down
3 changes: 2 additions & 1 deletion inst/include/datarecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class datarecord {


bool CompByTimePosRec(const rec_ptr& a, const rec_ptr& b);
bool CompEqual(const reclist& a, double time, unsigned int evid, int cmt);
bool CompEqual(const reclist& a, double time, unsigned int evid, int cmt,
double amt);

/**
* @brief Functor for sorting data records in <code>reclist</code>.
Expand Down
22 changes: 22 additions & 0 deletions inst/maintenance/unit-cpp/test-cpp.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ test_that("ev history is reset", {
expect_true(all(out3$FLAG==1))
})

code <- '
$PARAM CHECK = 1
$CMT A
$TABLE
if(TIME==1) {
mrg::evdata ev(1.1, 1);
ev.amt = 100;
ev.check_unique = CHECK;
self.mevector.push_back(ev);
self.mevector.push_back(ev);
self.mevector.push_back(ev);
}
'

test_that("control multiple doses", {
mod <- mcode("test-cpp-multi-dose", code, end = 2)
out <- mrgsim_df(mod)
expect_equal(max(out$A), 100)

out <- mrgsim_df(mod, param = list(CHECK = 0))
expect_equal(max(out$A), 300)
})

# Test events from within the model
code <- '
Expand Down
5 changes: 3 additions & 2 deletions src/datarecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ bool CompByTimePosRec(const rec_ptr& a, const rec_ptr& b) {
return res;
}

bool CompEqual(const reclist& a, double time, unsigned int evid, int cmt) {
bool CompEqual(const reclist& a, double time, unsigned int evid, int cmt,
double amt) {
for(size_t i = 0; i < a.size(); ++i) {
if(a[i]->time() != time) continue;
if((a[i]->evid()==evid) && (a[i]->cmt()==cmt)) {
if((a[i]->evid()==evid) && (a[i]->cmt()==cmt) && (a[i]->amt()==amt)) {
return true;
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/devtran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,13 @@ Rcpp::List DEVTRAN(const Rcpp::List parin,
std::sort(a[i].begin()+j+1,a[i].end(),CompRec());
}
} else {
bool foo = CompEqual(mtimehx,this_time,this_evid,this_cmt);
if(!foo) {
bool do_mt_ev = true;
if((mt[mti].check_unique)) {
bool found = CompEqual(mtimehx,this_time,this_evid,this_cmt,
this_amt);
do_mt_ev = do_mt_ev && !found;
}
if(do_mt_ev) {
a[i].push_back(new_ev);
std::sort(a[i].begin()+j+1,a[i].end(),CompRec());
mtimehx.push_back(new_ev);
Expand Down