233 int nvar, nvarv, nevent, npar, nrep, ntimes;
234 SEXP statenames, paramnames, covarnames;
236 int nzeros = LENGTH(accumvars);
238 SEXP
X, zindex, vindex;
239 int *sidx, *pidx, *cidx, *zidx, *vidx;
240 SEXP
fn,
Snames, Pnames, Cnames, Vnames;
245 dim = INTEGER(GET_DIM(xstart)); nvar = dim[0]; nrep = dim[1];
246 dim = INTEGER(GET_DIM(
params)); npar = dim[0];
247 dim = INTEGER(GET_DIM(vmatrix)); nvarv = dim[0]; nevent = dim[1];
250 err(
"number of state variables must equal the number of rows in 'v'.");
252 ntimes = LENGTH(times);
254 PROTECT(tstart = AS_NUMERIC(tstart));
255 PROTECT(times = AS_NUMERIC(times));
256 t0 = *(REAL(tstart));
257 if (t0 > *(REAL(times)))
err(
"'t0' must be no later than 'times[1]'.");
259 PROTECT(
Snames = GET_ROWNAMES(GET_DIMNAMES(xstart)));
260 PROTECT(Pnames = GET_ROWNAMES(GET_DIMNAMES(
params)));
262 PROTECT(Vnames = GET_ROWNAMES(GET_DIMNAMES(vmatrix)));
266 PROTECT(statenames = GET_SLOT(func,install(
"statenames")));
267 PROTECT(paramnames = GET_SLOT(func,install(
"paramnames")));
268 PROTECT(covarnames = GET_SLOT(func,install(
"covarnames")));
271 hasvnames = !isNull(Vnames);
273 PROTECT(hmax = AS_NUMERIC(hmax));
283 err(
"unrecognized 'mode' %d",
mode);
287 *((
void **) (&(
RXR))) = R_ExternalPtrAddr(
fn);
306 xdim[0] = nvar; xdim[1] = nrep; xdim[2] = ntimes;
310 sidx = INTEGER(GET_SLOT(func,install(
"stateindex")));
311 pidx = INTEGER(GET_SLOT(func,install(
"paramindex")));
312 cidx = INTEGER(GET_SLOT(func,install(
"covarindex")));
315 PROTECT(zindex =
MATCHROWNAMES(xstart,accumvars,
"state variables")); nprotect++;
316 zidx = INTEGER(zindex);
322 PROTECT(vindex =
MATCHROWNAMES(xstart,Vnames,
"state variables")); nprotect++;
323 vidx = INTEGER(vindex);
331 for (i = 0; i < nrep; i++) {
332 SSA(
RXR,i,nvar,nevent,npar,nrep,ntimes,
333 REAL(xstart),t0,REAL(times),REAL(
params),
334 REAL(
X),REAL(vmatrix),
335 nzeros,zidx,sidx,pidx,
ncovars,cidx,hasvnames,vidx,
336 covdim,&covariate_table,REAL(hmax));
lookup_table_t make_covariate_table(SEXP, int *)
SEXP pomp_fun_handler(SEXP, SEXP, pompfunmode *, SEXP, SEXP, SEXP, SEXP)
SEXP get_covariate_names(SEXP)
double pomp_ssa_rate_fn(int event, double t, const double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars)
#define MATCHROWNAMES(X, N, W)
static R_INLINE void setrownames(SEXP x, SEXP names, int rank)
static R_INLINE SEXP makearray(int rank, const int *dim)
static void SSA(pomp_ssa_rate_fn *ratefun, int irep, int nvar, int nevent, int npar, int nrep, int ntimes, double *xstart, double t, const double *times, const double *params, double *xout, const double *v, int nzero, const int *izero, const int *istate, const int *ipar, int ncovar, const int *icovar, Rboolean hasvname, const int *ivmat, int mcov, lookup_table_t *tab, const double *hmax)
static double __pomp_Rfun_ssa_ratefn(int j, double t, const double *x, const double *p, int *stateindex, int *parindex, int *covindex, double *c)
static R_INLINE SEXP add_args(SEXP args, SEXP Snames, SEXP Pnames, SEXP Cnames)