Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Rinternals inclusion order down #635

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 12 additions & 12 deletions inst/include/rxode2.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#define __rxode2_H__
#define rxLlikSaveSize 9


#include <stdbool.h>
#include <rxode2parse.h>
#include <R.h>
#include <Rinternals.h>
#include <Rversion.h>
#include <Rmath.h>
#include <stdbool.h>
#include <R_ext/Rdynload.h>
#include <rxode2parse.h>

#define rc_buf_read _rxode2_rc_buf_read
#define sIniTo _rxode2_sIniTo
Expand Down Expand Up @@ -78,7 +78,7 @@
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);

Expand Down Expand Up @@ -128,7 +128,7 @@
*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;
Expand Down Expand Up @@ -170,7 +170,7 @@
return (high-low)/(1+exp(-x))+low; // expit
case 3:
return exp(x);
case 2:
case 2:

Check warning on line 173 in inst/include/rxode2.h

View check run for this annotation

Codecov / codecov/patch

inst/include/rxode2.h#L173

Added line #L173 was not covered by tests
return x;
case 0:
if (lambda == 1.0) return (x+1.0);
Expand Down Expand Up @@ -351,7 +351,7 @@
case 3:
if (x <= _eps) x0 = _eps;
return -1/(x0*x0);
case 2:
case 2:

Check warning on line 354 in inst/include/rxode2.h

View check run for this annotation

Codecov / codecov/patch

inst/include/rxode2.h#L354

Added line #L354 was not covered by tests
return 0;
case 0:
if (lambda == 1.0) return 0;
Expand Down Expand Up @@ -396,7 +396,7 @@
if (xl <= _eps) hl2 = _eps;
return log(hl)-log(xl)-log(hl2);
/* return 0; */
case 3:
case 3:

Check warning on line 399 in inst/include/rxode2.h

View check run for this annotation

Codecov / codecov/patch

inst/include/rxode2.h#L399

Added line #L399 was not covered by tests
if (x <= _eps) x0 = _eps;
return -log(x0);
case 2:
Expand All @@ -415,12 +415,12 @@
// 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)
Expand Down Expand Up @@ -464,12 +464,12 @@
// 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)
Expand Down
5 changes: 1 addition & 4 deletions src/approx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
#define STRICT_R_HEADERS
#include <stdio.h>
#include <stdarg.h>
#include <R.h>
#include <Rinternals.h>
#include <Rmath.h>
#include <R_ext/Rdynload.h>
#include "../inst/include/rxode2.h"
#include <rxode2parseHandleEvid.h>
#include <rxode2parseGetTime.h>
#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)
Expand Down
8 changes: 1 addition & 7 deletions src/call_dvode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
#include "dop853.h"
#define max(a, b) ((a) > (b) ? (a) : (b))
#define STRICT_R_HEADERS
#include <R.h>
#include <Rinternals.h>
#include <Rmath.h> //Rmath includes math.
#include <R_ext/Rdynload.h>
#include <PreciseSums.h>
#include "../inst/include/rxode2.h"



//--------------------------------------------------------------------------

// These are now allocated via R structures in Rcpp.
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/cfode_static.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#define STRICT_R_HEADERS
#include <R.h>
#include <Rinternals.h>
#include "lsoda.h"
#include "common.h"
#include "cfode_static.h"
#include <R.h>
#include <Rinternals.h>

void RSprintf(const char *format, ...);

Expand Down Expand Up @@ -35,5 +35,5 @@ void printcm12(void) {
if((i + 1) % 4 == 0) RSprintf("\n ");
}
RSprintf("};\n");

}
20 changes: 10 additions & 10 deletions src/dop853.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h> /* dj: malloc.h */
#include <R.h>
#include <Rinternals.h>
/* #include <malloc.h> */
#include <limits.h>
#include <memory.h>
/* #include <malloc.h> */
#include "dop853.h"
#include <R.h>
#include <Rinternals.h>

#ifdef ENABLE_NLS
#include <libintl.h>
Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/forder.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#define USE_FC_LEN_T
#define STRICT_R_HEADERS
#include "rxomp.h"
#include <R.h>
#include <Rversion.h>
#include <Rinternals.h>
#include <algorithm>
#include "../inst/include/rxode2.h"
#define min2( a , b ) ( (a) < (b) ? (a) : (b) )
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/handle_evid.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <R.h>
#include <Rinternals.h>
#include <Rmath.h> //Rmath includes math.
#include <R_ext/Rdynload.h>
#include "../inst/include/rxode2.h"
#include "strncmp.h"
#include <rxode2parseHandleEvid.h>
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(String) dgettext ("rxode2", String)
/* replace pkg as appropriate */
#else
#define _(String) (String)
#endif
#include "../inst/include/rxode2.h"
#include <rxode2parseHandleEvid.h>


int handle_evidL(int evid, double *yp, double xout, int id, rx_solving_options_ind *ind) {
Expand Down
5 changes: 1 addition & 4 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <R.h>
#include <Rinternals.h>
#include <stdlib.h> // for NULL
#include <R_ext/Rdynload.h>
#include "../inst/include/rxode2.h"
#define __DOINIT__
#include "cbindThetaOmega.h"
//#include "seed.h"
#include "../inst/include/rxode2.h"
#include <rxode2parseGetTime.h>

SEXP _rxHasOpenMp(void);
Expand Down
7 changes: 4 additions & 3 deletions src/intdy.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define USE_FC_LEN_T
#define STRICT_R_HEADERS
#include <R.h>
#include <Rinternals.h>
#include <stdio.h>
#include <math.h>
#include "lsoda.h"
Expand All @@ -16,6 +14,10 @@
#define _(String) (String)
#endif

#include <R.h>
#include <Rinternals.h>


void RSprintf(const char *format, ...);

int intdy(struct lsoda_context_t * ctx, double t, int k, double *dky)
Expand Down Expand Up @@ -80,4 +82,3 @@ int intdy(struct lsoda_context_t * ctx, double t, int k, double *dky)
dky[i] *= r;
return 0;
} /* end intdy */

7 changes: 4 additions & 3 deletions src/lsoda.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define USE_FC_LEN_T
#define STRICT_R_HEADERS
#include <R.h>
#include <Rinternals.h>
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(String) dgettext ("rxode2", String)
Expand All @@ -10,6 +8,9 @@
#define _(String) (String)
#endif

#include <R.h>
#include <Rinternals.h>

void RSprintf(const char *format, ...);

/*
Expand Down Expand Up @@ -127,7 +128,7 @@ tam@wri.com
ctx->state = -3 ; \
return ctx->state; \
}


/* Terminate lsoda due to various error conditions. */
#define softfailure(code, fmt,...) \
Expand Down
10 changes: 3 additions & 7 deletions src/par_solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <R.h>
#include <Rinternals.h>
#include <string>
#include <Rmath.h> //Rmath includes math.
#include <R_ext/Rdynload.h>
#include "../inst/include/rxode2.h"
#include "strncmp.h"
#include <rxode2parseHandleEvid.h>
#include <rxode2parseGetTime.h>
//#include "seed.h"
#include <timsort.h>
#include "../inst/include/rxode2.h"
#include <rxode2parseHandleEvid.h>
#include <rxode2parseGetTime.h>
#define SORT gfx::timsort
#define isSameTimeOp(xout, xp) (op->stiff == 0 ? isSameTimeDop(xout, xp) : isSameTime(xout, xp))
// dop853 is same time
Expand Down
5 changes: 2 additions & 3 deletions src/solsy.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#define USE_FC_LEN_T
#define STRICT_R_HEADERS
#include <R.h>
#include <Rinternals.h>
#include "lsoda.h"
#include "lsoda_internal.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include "blas.h"
#include <R.h>
#include <Rinternals.h>

int solsy(struct lsoda_context_t * ctx, double *y)

Expand All @@ -32,4 +32,3 @@ int solsy(struct lsoda_context_t * ctx, double *y)
return 1;

}

Loading
Loading