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

Commit

Permalink
Use getTime_ inlined function most everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Sep 16, 2023
1 parent 5887010 commit 0badd40
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 178 deletions.
128 changes: 64 additions & 64 deletions inst/include/rxode2parseHandleSs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,81 +15,81 @@ static inline int handleExtraDose(double *yp,
int *i,
rx_solving_options *op,
rx_solving_options_ind *ind) {
if (ind->extraDoseN[0] > ind->idxExtra) {
if (ind->extraSorted == 0) {
// do sort
SORT(ind->extraDoseTimeIdx + ind->idxExtra, ind->extraDoseTimeIdx + ind->extraDoseN[0],
[ind](int a, int b){
double timea = ind->extraDoseTime[a],
timeb = ind->extraDoseTime[b];
if (timea == timeb) {
int evida = ind->extraDoseEvid[a],
evidb = ind->extraDoseEvid[b];
if (evida == evidb){
return a < b;
}
return evida < evidb;
if (ind->extraDoseN[0] > ind->idxExtra) {
if (ind->extraSorted == 0) {
// do sort
SORT(ind->extraDoseTimeIdx + ind->idxExtra, ind->extraDoseTimeIdx + ind->extraDoseN[0],
[ind](int a, int b){
double timea = ind->extraDoseTime[a],
timeb = ind->extraDoseTime[b];
if (timea == timeb) {
int evida = ind->extraDoseEvid[a],
evidb = ind->extraDoseEvid[b];
if (evida == evidb){
return a < b;
}
return timea < timeb;
});
ind->extraSorted=1;
ind->idxExtra=0;
}
// Use "real" xout for handle_evid functions.
int idx = ind->idx;
int ixds = ind->ixds;
int trueIdx = ind->extraDoseTimeIdx[ind->idxExtra];
return evida < evidb;
}
return timea < timeb;
});
ind->extraSorted=1;
ind->idxExtra=0;
}
// Use "real" xout for handle_evid functions.
int idx = ind->idx;
int ixds = ind->ixds;
int trueIdx = ind->extraDoseTimeIdx[ind->idxExtra];
ind->idx = -1-trueIdx;
double time = getAllTimes(ind, ind->idx);
while (!isSameTimeOp(time, xp) && time < xp && ind->idxExtra < ind->extraDoseN[0]) {
ind->idxExtra++;
trueIdx = ind->extraDoseTimeIdx[ind->idxExtra];
ind->idx = -1-trueIdx;
double time = getAllTimes(ind, ind->idx);
while (!isSameTimeOp(time, xp) && time < xp && ind->idxExtra < ind->extraDoseN[0]) {
ind->idxExtra++;
trueIdx = ind->extraDoseTimeIdx[ind->idxExtra];
ind->idx = -1-trueIdx;
time = getAllTimes(ind, ind->idx);
}
if ((isSameTimeOp(time, xp) || time > xp) && (isSameTimeOp(time, xout) || time <= xout)) {
bool ignore = true;
while (ignore && time <= xout) {
ignore=false;
for (int i = 0; i < ind->ignoredDosesN[0]; ++i) {
int curIdx = ind->ignoredDoses[i];
if (curIdx < 0 && -1-curIdx == trueIdx) {
ignore = true;
break;
}
}
if (ignore) {
ind->idxExtra++;
if (ind->idxExtra < ind->extraDoseN[0]) {
trueIdx = ind->extraDoseTimeIdx[ind->idxExtra];
ind->idx = -1-trueIdx;
time = getAllTimes(ind, ind->idx);
} else {
ind->idxExtra--;
break;
}
} else {
time = getAllTimes(ind, ind->idx);
}
if ((isSameTimeOp(time, xp) || time > xp) && (isSameTimeOp(time, xout) || time <= xout)) {
bool ignore = true;
while (ignore && time <= xout) {
ignore=false;
for (int i = 0; i < ind->ignoredDosesN[0]; ++i) {
int curIdx = ind->ignoredDoses[i];
if (curIdx < 0 && -1-curIdx == trueIdx) {
ignore = true;
break;
}
}
if (ignore) {
ind->idx = idx;
ind->ixds = ixds;
return 0;
ind->idxExtra++;
if (ind->idxExtra < ind->extraDoseN[0]) {
trueIdx = ind->extraDoseTimeIdx[ind->idxExtra];
ind->idx = -1-trueIdx;
time = getAllTimes(ind, ind->idx);
} else {
ind->idxExtra--;
break;
}
} else {
ind->extraDoseNewXout = time;
ind->idx = idx;
ind->ixds = ixds;
// REprintf("time: %f; xp: %f; xout: %f; handleExtra\n", time, xp, xout);
return 1;
break;
}
}
ind->idx = idx;
ind->ixds = ixds;
return 0;
if (ignore) {
ind->idx = idx;
ind->ixds = ixds;
return 0;
} else {
ind->extraDoseNewXout = time;
ind->idx = idx;
ind->ixds = ixds;
// REprintf("time: %f; xp: %f; xout: %f; handleExtra\n", time, xp, xout);
return 1;
}
}
ind->idx = idx;
ind->ixds = ixds;
return 0;
}
return 0;
}
#undef SORT

extern "C" {
Expand Down Expand Up @@ -914,7 +914,7 @@ extern "C" {
dur2 = curIi-dur;
if (isModeled && isSsLag) {
// adjust start time for modeled w/ssLag
startTimeD = getTime(ind->idose[infFixds],ind);
startTimeD = getTime_(ind->idose[infFixds],ind);
}
solveSSinf(yp,
&xout, xp,
Expand Down
13 changes: 7 additions & 6 deletions src/comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ void solveSSinf8_lin(double *yp,
switch(rx->linNcmt) {
case 3:
comp3ssInf8(yp + linCmt, lin->rate,
&(lin->ka), &(lin->k10), &(lin->k12), &(lin->k21),
&(lin->k13), &(lin->k31));
&(lin->ka), &(lin->k10), &(lin->k12), &(lin->k21),
&(lin->k13), &(lin->k31));
break;
case 2:
comp2ssInf8(yp + linCmt,lin->rate, &(lin->ka), &(lin->k10), &(lin->k12), &(lin->k21));
Expand Down Expand Up @@ -273,12 +273,13 @@ double linCmtCompA(rx_solve *rx, unsigned int id, double _t, int linCmt,
int oral0 = (d_ka > 0) ? 1 : 0;
void *ctx = &(lin);
if (ind->idx == 0) {
// initialization
xp = xout = getTime(ind->ix[ind->idx], ind);
// initializationu

xp = xout = getTime_(ind->ix[ind->idx], ind);
yp = ypLast = Alast0;
} else {
xp = (ind->idx == 0 ? 0.0 : getTime(ind->ix[ind->idx-1], ind));
xout = getTime(ind->ix[ind->idx], ind);
xp = (ind->idx == 0 ? 0.0 : getTime_(ind->ix[ind->idx-1], ind));
xout = getTime_(ind->ix[ind->idx], ind);
ypLast=getAdvan(ind->idx-1);
}
yp = getAdvan(ind->idx);
Expand Down
Loading

0 comments on commit 0badd40

Please sign in to comment.