Skip to content

Commit

Permalink
Use sort from rxode2parse
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Sep 6, 2023
1 parent 23f4c49 commit 62f4dfe
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 45 deletions.
1 change: 0 additions & 1 deletion inst/include/rxode2.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#pragma once
#define STRICT_R_HEADERS
#ifndef __rxode2_H__
Expand Down
4 changes: 0 additions & 4 deletions src/approx.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,3 @@ void _update_par_ptr(double t, unsigned int id, rx_solve *rx, int idxIn) {
}
ind->_update_par_ptr_in = 0;
}

/* void doSort(rx_solving_options_ind *ind); */
void sortInd(rx_solving_options_ind *ind);

42 changes: 2 additions & 40 deletions src/par_solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <rxode2parseHandleEvid.h>
#include <rxode2parseGetTime.h>
#include <rxode2parseHandleSs.h>
#include <rxode2parseSortInd.h>
//#include "seed.h"
#include <timsort.h>
#define SORT gfx::timsort
Expand Down Expand Up @@ -568,46 +569,7 @@ extern "C" double getTime(int idx, rx_solving_options_ind *ind) {

// Adapted from
extern "C" void sortInd(rx_solving_options_ind *ind) {
// #ifdef _OPENMP
// int core = omp_get_thread_num();
// #else
// int core = 0;
// #endif
rx_solve *rx = &rx_global;
rx_solving_options *op = &op_global;
// Reset times for infusion
int doSort = 1;
double *time = ind->timeThread;
ind->ixds = 0;
ind->curShift = 0;
for (int i = 0; i < ind->n_all_times; i++) {
ind->ix[i] = i;
ind->idx = i;
if (!isObs(getEvid(ind, i))) {
time[i] = getTime__(ind->ix[i], ind, 1);
ind->ixds++;
} else {
if (getEvid(ind, i) == 3) {
ind->curShift -= rx->maxShift;
}
time[i] = getTime__(ind->ix[i], ind, 1);
}
if (op->naTime == 1){
doSort=0;
break;
}
}
if (doSort) {
SORT(ind->ix, ind->ix + ind->n_all_times,
[ind, time](int a, int b){
double timea = time[a],
timeb = time[b];
if (timea == timeb) {
return a < b;
}
return timea < timeb;
});
}
rxode2parse_sortInd(ind);
}

extern "C" int iniSubjectE(int solveid, int inLhs, rx_solving_options_ind *ind, rx_solving_options *op, rx_solve *rx,
Expand Down

0 comments on commit 62f4dfe

Please sign in to comment.