From 33f7e8137f79b7df15e4a7254a874e5a3df34e87 Mon Sep 17 00:00:00 2001 From: "Matthew L. Fidler" Date: Tue, 12 Dec 2023 06:50:13 -0600 Subject: [PATCH] Move Rinternals inclusion order down --- DESCRIPTION | 2 +- inst/include/rxode2.h | 24 ++++++++++++------------ src/approx.c | 5 +---- src/call_dvode.c | 8 +------- src/cfode_static.c | 6 +++--- src/dop853.c | 20 ++++++++++---------- src/forder.cpp | 5 +---- src/handle_evid.c | 8 ++------ src/init.c | 5 +---- src/intdy.c | 7 ++++--- src/lsoda.c | 7 ++++--- src/par_solve.cpp | 10 +++------- src/solsy.c | 5 ++--- src/utilc.c | 16 ++++++---------- 14 files changed, 51 insertions(+), 77 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d8bb5b0a3..ccec6811e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: rxode2 -Version: 2.1.0 +Version: 2.1.1 Title: Facilities for Simulating from ODE-Based Models Authors@R: c( person("Matthew L.","Fidler", diff --git a/inst/include/rxode2.h b/inst/include/rxode2.h index 231afe911..7b59a5659 100644 --- a/inst/include/rxode2.h +++ b/inst/include/rxode2.h @@ -5,13 +5,13 @@ #define __rxode2_H__ #define rxLlikSaveSize 9 - +#include +#include #include #include +#include #include -#include #include -#include #define rc_buf_read _rxode2_rc_buf_read #define sIniTo _rxode2_sIniTo @@ -78,7 +78,7 @@ typedef void (*t_dydt_lsoda_dum)(int *neq, double *t, double *A, double *DADT); typedef void (*t_jdum_lsoda)(int *neq, double *t, double *A,int *ml, int *mu, double *JAC, int *nrowpd); typedef int (*t_dydt_liblsoda)(double t, double *y, double *ydot, void *data); typedef void (*t_ode_current)(void); - + typedef void (*t_set_solve)(rx_solve *); typedef rx_solve *(*t_get_solve)(void); @@ -128,7 +128,7 @@ static inline void _splitYj(int *yj, int *dist, int *trans) { *trans = *yj - *dist*10; *dist = *dist + 1; } -// Inverse +// Inverse static inline double _powerDi(double x, double lambda, int yj0, double low, double high) __attribute__((unused)); static inline double _powerDi(double x, double lambda, int yj0, double low, double high){ if (!R_finite(x)) return NA_REAL; @@ -170,7 +170,7 @@ static inline double _powerDi(double x, double lambda, int yj0, double low, doub return (high-low)/(1+exp(-x))+low; // expit case 3: return exp(x); - case 2: + case 2: return x; case 0: if (lambda == 1.0) return (x+1.0); @@ -351,7 +351,7 @@ static inline double _powerDDD(double x, double lambda, int yj0, double low, dou case 3: if (x <= _eps) x0 = _eps; return -1/(x0*x0); - case 2: + case 2: return 0; case 0: if (lambda == 1.0) return 0; @@ -396,7 +396,7 @@ static inline double _powerL(double x, double lambda, int yj0, double low, doubl if (xl <= _eps) hl2 = _eps; return log(hl)-log(xl)-log(hl2); /* return 0; */ - case 3: + case 3: if (x <= _eps) x0 = _eps; return -log(x0); case 2: @@ -415,12 +415,12 @@ static inline double _powerL(double x, double lambda, int yj0, double low, doubl // logLik approximation // y^(lambda)/lambda - 1/lambda // dh/dy = y^(lambda-1) - // log(dh/dy) = (lambda-1)*log(y) + log(lambda) + // log(dh/dy) = (lambda-1)*log(y) + log(lambda) // // (x + 1.0)^(lambda)/lambda - 1/lambda // dh/dy = (x+1.0)^(lambda-1) // log(dh/dy) = (lambda-1)*log(x+1.0) - + // For negative values yj becomes // (-x+1)^(2-lambda)/(2-lambda) - 1/(2-lambda) // dh/dy = (-x+1)^(1-lambda) @@ -464,12 +464,12 @@ static inline double _powerDL(double x, double lambda, int yj0, double low, doub // logLik approximation // y^(lambda)/lambda - 1/lambda // dh/dy = y^(lambda-1) - // log(dh/dy) = (lambda-1)*log(y) + log(lambda) + // log(dh/dy) = (lambda-1)*log(y) + log(lambda) // // (x + 1.0)^(lambda)/lambda - 1/lambda // dh/dy = (x+1.0)^(lambda-1) // log(dh/dy) = (lambda-1)*log(x+1.0) - + // For negative values yj becomes // (-x+1)^(2-lambda)/(2-lambda) - 1/(2-lambda) // dh/dy = (-x+1)^(1-lambda) diff --git a/src/approx.c b/src/approx.c index 1e8b33ced..557b67263 100644 --- a/src/approx.c +++ b/src/approx.c @@ -2,14 +2,11 @@ #define STRICT_R_HEADERS #include #include -#include -#include -#include -#include #include "../inst/include/rxode2.h" #include #include #include "seed.h" + #define safe_zero(a) ((a) == 0 ? DBL_EPSILON : (a)) #define _as_zero(a) (fabs(a) < sqrt(DBL_EPSILON) ? 0.0 : a) #define _as_dbleps(a) (fabs(a) < sqrt(DBL_EPSILON) ? ((a) < 0 ? -sqrt(DBL_EPSILON) : sqrt(DBL_EPSILON)) : a) diff --git a/src/call_dvode.c b/src/call_dvode.c index c06e8ad32..401b8c983 100644 --- a/src/call_dvode.c +++ b/src/call_dvode.c @@ -6,15 +6,9 @@ #include "dop853.h" #define max(a, b) ((a) > (b) ? (a) : (b)) #define STRICT_R_HEADERS -#include -#include -#include //Rmath includes math. -#include #include #include "../inst/include/rxode2.h" - - //-------------------------------------------------------------------------- // These are now allocated via R structures in Rcpp. @@ -39,7 +33,7 @@ extern void rxode2_assign_fn_pointers(SEXP mv){ if (rxode2_current_fn_pointer_id_ != cur){ rxAssignPtrC(mv); rxode2_current_fn_pointer_id_ = cur; - } + } } SEXP rxModelVarsC(char *ptr); diff --git a/src/cfode_static.c b/src/cfode_static.c index 99c92a426..31996f7d1 100644 --- a/src/cfode_static.c +++ b/src/cfode_static.c @@ -1,9 +1,9 @@ #define STRICT_R_HEADERS -#include -#include #include "lsoda.h" #include "common.h" #include "cfode_static.h" +#include +#include void RSprintf(const char *format, ...); @@ -35,5 +35,5 @@ void printcm12(void) { if((i + 1) % 4 == 0) RSprintf("\n "); } RSprintf("};\n"); - + } diff --git a/src/dop853.c b/src/dop853.c index 92bb89939..c0fb04baf 100644 --- a/src/dop853.c +++ b/src/dop853.c @@ -3,12 +3,12 @@ #include #include #include /* dj: malloc.h */ -#include -#include -/* #include */ #include #include +/* #include */ #include "dop853.h" +#include +#include #ifdef ENABLE_NLS #include @@ -390,13 +390,13 @@ static int dopcor (int *nptr, FcnEqDiff fcn, double x, double* y, double xend, nfcn += 2; reject = 0; xold = x; - + if (iout) { irtrn = 1; hout = 1.0; xout = x; - solout (naccpt+1, xold, x, y, nptr, &irtrn); + solout (naccpt+1, xold, x, y, nptr, &irtrn); if (irtrn < 0) { /* if (fileout) */ @@ -482,7 +482,7 @@ static int dopcor (int *nptr, FcnEqDiff fcn, double x, double* y, double xend, b10*k10[i] + b11*k2[i] + b12*k3[i]; k5[i] = y[i] + h * k4[i]; } - + /* error estimation */ err = 0.0; err2 = 0.0; @@ -531,7 +531,7 @@ static int dopcor (int *nptr, FcnEqDiff fcn, double x, double* y, double xend, naccpt++; fcn (nptr, xph, k5, k4); nfcn++; - + /* stiffness detection */ if (!(naccpt % nstiff) || (iasti > 0)) { @@ -552,7 +552,7 @@ static int dopcor (int *nptr, FcnEqDiff fcn, double x, double* y, double xend, iasti++; if (iasti == 15) { - Rprintf (_("the problem seems to become stiff at x = %.16e\n"), x); + Rprintf (_("the problem seems to become stiff at x = %.16e\n"), x); xout = x; hout = h; return -4; @@ -565,7 +565,7 @@ static int dopcor (int *nptr, FcnEqDiff fcn, double x, double* y, double xend, iasti = 0; } } - + /* final preparation for dense output */ if (iout == 2) { @@ -654,7 +654,7 @@ static int dopcor (int *nptr, FcnEqDiff fcn, double x, double* y, double xend, } } - memcpy (k1, k4, n * sizeof(double)); + memcpy (k1, k4, n * sizeof(double)); memcpy (y, k5, n * sizeof(double)); xold = x; x = xph; diff --git a/src/forder.cpp b/src/forder.cpp index 036447f47..84fd72cb3 100644 --- a/src/forder.cpp +++ b/src/forder.cpp @@ -1,9 +1,6 @@ #define USE_FC_LEN_T #define STRICT_R_HEADERS #include "rxomp.h" -#include -#include -#include #include #include "../inst/include/rxode2.h" #define min2( a , b ) ( (a) < (b) ? (a) : (b) ) @@ -93,7 +90,7 @@ extern "C" int getRxThreads(const int64_t n, const bool throttle) { // this is the main getter used by all parallel regions; they specify num_threads(n, true|false). // Keep this light, simple and robust. rxSetThreads() ensures 1 <= rxThreads <= omp_get_num_proc() // throttle introduced in 1.12.10 (see NEWS item); #4484 - // throttle==true : a number of iterations per thread (rxThrottle) is applied before a second thread is utilized + // throttle==true : a number of iterations per thread (rxThrottle) is applied before a second thread is utilized // throttle==false : parallel region is already pre-chunked such as in fread; e.g. two batches intended for two threads if (n<1) return 1; // 0 or negative could be deliberate in calling code for edge cases where loop is not intended to run at all int64_t ans = throttle ? 1+(n-1)/rxThrottle : // 1 thread for n<=2, 2 thread for n<=4, etc diff --git a/src/handle_evid.c b/src/handle_evid.c index 5414a3fc7..3053f48d8 100644 --- a/src/handle_evid.c +++ b/src/handle_evid.c @@ -3,13 +3,7 @@ #include #include #include -#include -#include -#include //Rmath includes math. -#include -#include "../inst/include/rxode2.h" #include "strncmp.h" -#include #ifdef ENABLE_NLS #include #define _(String) dgettext ("rxode2", String) @@ -17,6 +11,8 @@ #else #define _(String) (String) #endif +#include "../inst/include/rxode2.h" +#include int handle_evidL(int evid, double *yp, double xout, int id, rx_solving_options_ind *ind) { diff --git a/src/init.c b/src/init.c index b76245d75..4371c3f33 100644 --- a/src/init.c +++ b/src/init.c @@ -3,14 +3,11 @@ #include #include #include -#include -#include #include // for NULL -#include -#include "../inst/include/rxode2.h" #define __DOINIT__ #include "cbindThetaOmega.h" //#include "seed.h" +#include "../inst/include/rxode2.h" #include SEXP _rxHasOpenMp(void); diff --git a/src/intdy.c b/src/intdy.c index 8670339f0..d76d701f1 100644 --- a/src/intdy.c +++ b/src/intdy.c @@ -1,7 +1,5 @@ #define USE_FC_LEN_T #define STRICT_R_HEADERS -#include -#include #include #include #include "lsoda.h" @@ -16,6 +14,10 @@ #define _(String) (String) #endif +#include +#include + + void RSprintf(const char *format, ...); int intdy(struct lsoda_context_t * ctx, double t, int k, double *dky) @@ -80,4 +82,3 @@ int intdy(struct lsoda_context_t * ctx, double t, int k, double *dky) dky[i] *= r; return 0; } /* end intdy */ - diff --git a/src/lsoda.c b/src/lsoda.c index fcd853fb1..26a77f252 100644 --- a/src/lsoda.c +++ b/src/lsoda.c @@ -1,7 +1,5 @@ #define USE_FC_LEN_T #define STRICT_R_HEADERS -#include -#include #ifdef ENABLE_NLS #include #define _(String) dgettext ("rxode2", String) @@ -10,6 +8,9 @@ #define _(String) (String) #endif +#include +#include + void RSprintf(const char *format, ...); /* @@ -127,7 +128,7 @@ tam@wri.com ctx->state = -3 ; \ return ctx->state; \ } - + /* Terminate lsoda due to various error conditions. */ #define softfailure(code, fmt,...) \ diff --git a/src/par_solve.cpp b/src/par_solve.cpp index 31a828423..908352e41 100644 --- a/src/par_solve.cpp +++ b/src/par_solve.cpp @@ -4,17 +4,13 @@ #include #include #include -#include -#include #include -#include //Rmath includes math. -#include -#include "../inst/include/rxode2.h" #include "strncmp.h" -#include -#include //#include "seed.h" #include +#include "../inst/include/rxode2.h" +#include +#include #define SORT gfx::timsort #define isSameTimeOp(xout, xp) (op->stiff == 0 ? isSameTimeDop(xout, xp) : isSameTime(xout, xp)) // dop853 is same time diff --git a/src/solsy.c b/src/solsy.c index dbec8cdfa..e8f5ed8f2 100644 --- a/src/solsy.c +++ b/src/solsy.c @@ -1,13 +1,13 @@ #define USE_FC_LEN_T #define STRICT_R_HEADERS -#include -#include #include "lsoda.h" #include "lsoda_internal.h" #include "common.h" #include #include #include "blas.h" +#include +#include int solsy(struct lsoda_context_t * ctx, double *y) @@ -32,4 +32,3 @@ int solsy(struct lsoda_context_t * ctx, double *y) return 1; } - diff --git a/src/utilc.c b/src/utilc.c index c3c4bec96..ba889e016 100644 --- a/src/utilc.c +++ b/src/utilc.c @@ -1,16 +1,12 @@ #define USE_FC_LEN_T #define STRICT_R_HEADERS -#include +#include #include #include #include #include #include /* dj: import intptr_t */ #include -#include -#include -#include -#include #ifdef ENABLE_NLS #include #define _(String) dgettext ("rxode2", String) @@ -46,7 +42,7 @@ extern void RSprintf(const char *format, ...) { va_start(args, format); Rvprintf(format, args); va_end(args); - } + } } } @@ -242,7 +238,7 @@ SEXP _uppergamma(SEXP a, SEXP z) { } else { Rf_errorcall(R_NilValue, _("'z' needs to be a number")); } - + if (lena == lenz) { ret = PROTECT(Rf_allocVector(REALSXP, lena));pro++; double *retD = REAL(ret); @@ -299,7 +295,7 @@ SEXP _gammapDer(SEXP a, SEXP z) { } else { Rf_errorcall(R_NilValue, _("'z' needs to be a number")); } - + if (lena == lenz) { ret = PROTECT(Rf_allocVector(REALSXP, lena));pro++; double *retD = REAL(ret); @@ -355,7 +351,7 @@ SEXP _gammapInv(SEXP a, SEXP z) { } else { Rf_errorcall(R_NilValue, _("'z' needs to be a number")); } - + if (lena == lenz) { ret = PROTECT(Rf_allocVector(REALSXP, lena));pro++; double *retD = REAL(ret); @@ -411,7 +407,7 @@ SEXP _gammapInva(SEXP a, SEXP z) { } else { Rf_errorcall(R_NilValue, _("'z' needs to be a number")); } - + if (lena == lenz) { ret = PROTECT(Rf_allocVector(REALSXP, lena));pro++; double *retD = REAL(ret);