Skip to content

Commit

Permalink
Merge pull request #773 from nlmixr2/733-no-abi-defs
Browse files Browse the repository at this point in the history
Some of the #defines call the abi
  • Loading branch information
mattfidler authored Aug 21, 2024
2 parents 27183f8 + 37105c3 commit 6812c3b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions inst/include/rxode2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@

#include "rxode2_control.h"
#include <stdint.h> // for uint64_t rather than unsigned long long

#ifndef __RXODE2PTR_H__ // directly refer to abi need to be excluded
#define getAdvan(idx) ind->solve + (op->neq + op->nlin)*(idx) + op->neq
#define getSolve(idx) ind->solve + (op->neq + op->nlin)*(idx)
#endif

#ifdef _isrxode2_

Expand Down
7 changes: 7 additions & 0 deletions inst/include/rxode2parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
#define __rxode2parse_H__
#define rxLlikSaveSize 9

#ifndef __RXODE2PTR_H__ // these refer to abi and should not be used.
#define getAdvan(idx) ind->solve + (op->neq + op->nlin)*(idx) + op->neq
#define getSolve(idx) ind->solve + (op->neq + op->nlin)*(idx)
#endif // __RXODE2PTR_H__


#define isDose(evid) ((evid) == 3 || (evid) >= 100)
#define isObs(evid) ((evid) == 0 || (evid) == 2 || ((evid) >= 9 && (evid) <= 99))

#ifndef __RXODE2PTR_H__ // these refer to abi and should not be used.
#define getEvid(ind, idx) (idx >= 0 ? ind->evid[idx] : ind->extraDoseEvid[-1-idx])
#define getEvidP1(ind, idx) (idx >= 0 ? ind->evid[idx+1] : ind->extraDoseEvid[-idx])
#define getEvidM1(ind, idx) (idx >= 0 ? ind->evid[idx-1] : ind->extraDoseEvid[-2-idx])
Expand All @@ -30,6 +35,8 @@
#define getAllTimesM1(ind, idx) (idx >= 0 ? ind->all_times[idx-1] : ind->extraDoseTime[-2-idx])

#define setAllTimesP1(ind, idx, val) if (idx>= 0) {ind->all_times[idx+1] = val;} else {ind->extraDoseTime[-idx] = val;}
#endif // __RXODE2PTR_H__

#include <R.h>
#include <stdbool.h>

Expand Down
5 changes: 5 additions & 0 deletions inst/include/rxode2ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ extern "C" {
typedef int (*getRxNobs2_t)(rx_solve *rx);
extern getRxNobs2_t getRxNobs2;

typedef double * (*getOpIndSolve_t)(rx_solving_options* op, rx_solving_options_ind* ind, int idx);
extern getOpIndSolve_t getOpIndSolve;

static inline SEXP iniRxodePtrs0(SEXP p) {
if (_rxode2_rxRmvnSEXP_ == NULL) {
_rxode2_rxRmvnSEXP_ = (_rxode2_rxRmvnSEXP_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 0));
Expand Down Expand Up @@ -210,6 +213,7 @@ extern "C" {
getRxNall = (getRxNall_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 44));
getRxNobs = (getRxNobs_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 45));
getRxNobs2 = (getRxNobs2_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 46));
getOpIndSolve = (getOpIndSolve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 47));
}
return R_NilValue;
}
Expand Down Expand Up @@ -262,6 +266,7 @@ extern "C" {
getRxNall_t getRxNall = NULL; \
getRxNobs_t getRxNobs = NULL; \
getRxNobs2_t getRxNobs2 = NULL; \
getOpIndSolve_t getOpIndSolve = NULL; \
SEXP iniRxodePtrs(SEXP ptr) { \
return iniRxodePtrs0(ptr); \
} \
Expand Down
5 changes: 4 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,10 @@ SEXP _rxode2_rxode2Ptr(void) {
SEXP rxode2getRxNall = PROTECT(R_MakeExternalPtrFn((DL_FUNC)&getRxNall, R_NilValue, R_NilValue)); pro++;
SEXP rxode2getRxNobs = PROTECT(R_MakeExternalPtrFn((DL_FUNC)&getRxNobs, R_NilValue, R_NilValue)); pro++;
SEXP rxode2getRxNobs2 = PROTECT(R_MakeExternalPtrFn((DL_FUNC)&getRxNobs2, R_NilValue, R_NilValue)); pro++;
SEXP rxode2getOpIndSolve = PROTECT(R_MakeExternalPtrFn((DL_FUNC)&getOpIndSolve, R_NilValue, R_NilValue)); pro++;


#define nVec 47
#define nVec 48

SEXP ret = PROTECT(Rf_allocVector(VECSXP, nVec)); pro++;
SET_VECTOR_ELT(ret, 0, rxode2rxRmvnSEXP);
Expand Down Expand Up @@ -474,6 +475,7 @@ SEXP _rxode2_rxode2Ptr(void) {
SET_VECTOR_ELT(ret, 44, rxode2getRxNall);
SET_VECTOR_ELT(ret, 45, rxode2getRxNobs);
SET_VECTOR_ELT(ret, 46, rxode2getRxNobs2);
SET_VECTOR_ELT(ret, 47, rxode2getOpIndSolve);

SEXP retN = PROTECT(Rf_allocVector(STRSXP, nVec)); pro++;
SET_STRING_ELT(retN, 0, Rf_mkChar("rxode2rxRmvnSEXP"));
Expand Down Expand Up @@ -523,6 +525,7 @@ SEXP _rxode2_rxode2Ptr(void) {
SET_STRING_ELT(retN, 44, Rf_mkChar("rxode2getRxNall"));
SET_STRING_ELT(retN, 45, Rf_mkChar("rxode2getRxNobs"));
SET_STRING_ELT(retN, 46, Rf_mkChar("rxode2getRxNobs2"));
SET_STRING_ELT(retN, 47, Rf_mkChar("rxode2getOpIndSolve"));

#undef nVec

Expand Down
6 changes: 6 additions & 0 deletions src/rx2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,9 @@ int getRxNobs(rx_solve *rx) {
int getRxNobs2(rx_solve *rx) {
return rx->nobs2;
}
////////////////////////////////////////////////////////////////////////
// Get solve vector for ith solve
////////////////////////////////////////////////////////////////////////
double * getOpIndSolve(rx_solving_options* op, rx_solving_options_ind* ind, int idx) {
return ind->solve + (op->neq + op->nlin)*(idx);
}
2 changes: 2 additions & 0 deletions src/rx2api.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ extern "C" {
// Get the number of observations excluding evid=2
int getRxNobs2(rx_solve *rx);

double * getOpIndSolve(rx_solving_options* op, rx_solving_options_ind* ind, int idx);

#if defined(__cplusplus)
}
#endif
Expand Down

0 comments on commit 6812c3b

Please sign in to comment.