Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
One interface for handling events, lag, dur, f, and rate; fix test 17
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Jan 23, 2024
1 parent c51fccf commit 044b886
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 123 deletions.
13 changes: 2 additions & 11 deletions inst/include/rxode2parseGetTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ extern "C" {
return time;
}
if (cmt < 0) return time;
if (cmt >= op->neq) {
return ind->linCmtLag[cmt - op->neq]+time;
}
double ret = LAG(id, cmt, time);
if (ISNA(ret)) {
op->badSolve = 1;
Expand All @@ -50,9 +47,6 @@ extern "C" {
static inline double getRate(rx_solving_options_ind *ind, int id, int cmt, double dose, double t){
rx_solving_options *op = &op_global;
returnBadTime(t);
if (cmt >= op->neq) {
return ind->linCmtRate[cmt - op->neq];
}
double ret = RATE(id, cmt, dose, t);
if (ISNA(ret)){
op->badSolve=1;
Expand All @@ -65,9 +59,6 @@ extern "C" {
rx_solving_options *op = &op_global;
returnBadTime(t);
if (ISNA(t)) return t;
if (cmt >= op->neq) {
return ind->linCmtDur[cmt - op->neq];
}
double ret = DUR(id, cmt, dose, t);
if (ISNA(ret)){
op->badSolve=1;
Expand Down Expand Up @@ -103,7 +94,7 @@ extern "C" {
} else {
rx_solve *rx = &rx_global;
rx_solving_options *op = &op_global;
if (ind->cmt < op->neq){
if (ind->cmt < op->neq) {
if (rx->needSort & 4){
if (!(ind->err & 16)){
ind->err += 16;
Expand Down Expand Up @@ -135,7 +126,7 @@ extern "C" {
rx_solve *rx;
rx = &rx_global;
rx_solving_options *op = &op_global;
if (ind->cmt < op->neq){
if (ind->cmt < op->neq) {
if (rx->needSort & 8){
if (!(ind->err & 2)){
ind->err += 2;
Expand Down
5 changes: 1 addition & 4 deletions inst/include/rxode2parseHandleEvid.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ extern "C" {
static inline double getAmt(rx_solving_options_ind *ind, int id, int cmt, double dose, double t, double *y) {
// AMT handles the bioavailibility
rx_solving_options *op = &op_global;
if (cmt >= op->neq) {
return dose * ind->linCmtF[cmt - op->neq];
}
double ret = AMT(id, cmt, dose, t, y);
if (ISNA(ret)){
rx_solving_options *op = &op_global;
Expand Down Expand Up @@ -586,7 +583,7 @@ extern "C" {
ind->ixds++;
ind->solved = ind->idx;
return 0;
}// else if (!ind->doSS) {
} // else if (!ind->doSS) {
// REprintf("handle evid %d dose at time %f is value %f (ind->ixds: %d; ind->idx: %d)\n",
// evid, xout, getDoseIndex(ind, ind->idx), ind->ixds, ind->idx);
// }
Expand Down
104 changes: 100 additions & 4 deletions inst/include/rxode2parseStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,106 @@ extern "C" {
op->nLlik = 0;
}

typedef struct {
int idx;
double p1;
double v1;
double p2;
double p3;
double p4;
double p5;
double d_tlag;
double d_F;
double d_rate1;
double d_dur1;
// Oral parameters
double d_ka;
double d_tlag2;
double d_F2;
double d_rate2;
double d_dur2;
} rx_solving_linCmt_dose_single;

typedef struct {
rx_solving_linCmt_dose_single *pars;
int n;
int nAlloc;
} rx_solving_linCmt_doses;

#define iniLinCmtAlloc 2

static inline void iniLinCmtDoses(rx_solving_linCmt_doses *doses) {
doses->n = 0;
doses->pars = (rx_solving_linCmt_dose_single*)(malloc(iniLinCmtAlloc*sizeof(rx_solving_linCmt_dose_single)));
if (doses->pars == NULL) {
Rf_error("ran out of memory");
}
doses->nAlloc = iniLinCmtAlloc;
}

static inline rx_solving_linCmt_dose_single* getLinCmtDoses(rx_solving_linCmt_doses *doses, int idx) {
rx_solving_linCmt_dose_single *single;
for (int i = 0; i < doses->n; ++i) {
single = &(doses->pars[i]);
if (single->idx == idx) {
return single;
}
}
return NULL;
}

static inline rx_solving_linCmt_dose_single* pushLinCmtDose(rx_solving_linCmt_doses *doses, int idx,
double p1, double v1,
double p2, double p3,
double p4, double p5,
double d_tlag, double d_F, double d_rate1,
double d_dur1,
// Oral parameters
double d_ka, double d_tlag2,
double d_F2, double d_rate2, double d_dur2) {
rx_solving_linCmt_dose_single* single = getLinCmtDoses(doses, idx);
if (single == NULL) {
if (doses->nAlloc <= doses->n + 1) {
int size = doses->n + iniLinCmtAlloc + 1;
rx_solving_linCmt_dose_single* n = (rx_solving_linCmt_dose_single*)(realloc(doses->pars, size*sizeof(rx_solving_linCmt_dose_single)));
if (n == NULL) {
Rf_error("ran out of memory");
}
doses->pars = n;
doses->nAlloc = size;
}
single = &(doses->pars[doses->n]);
doses->n++;
}
single->idx = idx;
single->p1 = p1;
single->v1 = v1;
single->p2 = p2;
single->p3 = p3;
single->p4 = p4;
single->p4 = p5;
single->d_tlag = d_tlag;
single->d_F = d_F;
single->d_rate1 = d_rate1;
single->d_dur1 = d_dur1;
single->d_ka = d_ka;
single->d_tlag2 = d_tlag2;
single->d_F2 = d_tlag2;
single->d_rate2 = d_rate2;
single->d_dur2 = d_dur2;
return single;
}

static inline void resetLinCmtDose(rx_solving_linCmt_doses *doses) {
doses->n = 0;
}

static inline void freeLinCmtDoses(rx_solving_linCmt_doses *doses) {
doses->n = 0;
free(doses->pars);
doses->nAlloc = 0;
}

typedef struct {
double bT;
int *slvr_counter;
Expand Down Expand Up @@ -291,10 +391,6 @@ extern "C" {
bool lastIsSs2;
double *timeThread;
// linear compartmental solve
double *linCmtLag;
double *linCmtF;
double *linCmtDur;
double *linCmtRate;
} rx_solving_options_ind;

typedef struct {
Expand Down
Loading

0 comments on commit 044b886

Please sign in to comment.