26{
27
29 SEXP
X, copy, rproc,
args, accumvars, covar;
30 SEXP dimXstart, dimP;
31 const char *dimnm[3] = {"name",".id","time"};
32
33 PROTECT(gnsi = duplicate(gnsi));
34
35 PROTECT(tstart = AS_NUMERIC(tstart));
36
37 PROTECT(times = AS_NUMERIC(times));
38 ntimes = length(times);
39 if (ntimes < 1) {
40 err(
"length(times) < 1: no work to do.");
41 }
42
44 PROTECT(dimXstart = GET_DIM(xstart));
45 xdim = INTEGER(dimXstart);
46 nvars = xdim[0]; nrepsx = xdim[1];
47
49 PROTECT(dimP = GET_DIM(
params));
50 xdim = INTEGER(dimP);
52
53 int nprotect = 7;
54
56 if (nrepsx %
nreps != 0) {
57 err(
"the larger number of replicates is not a multiple of smaller.");
58 } else {
59 double *src, *tgt;
60 int dims[2];
61 int j, k;
62 dims[0] =
npars; dims[1] = nrepsx;
63 PROTECT(copy = duplicate(
params));
65 nprotect += 2;
67 src = REAL(copy);
69 for (j = 0; j < nrepsx; j++) {
70 for (k = 0; k <
npars; k++, tgt++) {
72 }
73 }
74 }
76 }
else if (nrepsx <
nreps) {
77 if (
nreps % nrepsx != 0) {
78 err(
"the larger number of replicates is not a multiple of smaller.");
79 } else {
80 double *src, *tgt;
81 int dims[2];
82 int j, k;
84 PROTECT(copy = duplicate(xstart));
86 nprotect += 2;
87 setrownames(xstart,GET_ROWNAMES(GET_DIMNAMES(copy)),2);
88 src = REAL(copy);
89 tgt = REAL(xstart);
90 for (j = 0; j <
nreps; j++) {
91 for (k = 0; k <
nvars; k++, tgt++) {
92 *tgt = src[k+
nvars*(j%nrepsx)];
93 }
94 }
95 }
96 }
97
98 PROTECT(rproc = GET_SLOT(object,install("rprocess")));
99 PROTECT(
args = GET_SLOT(
object,install(
"userdata")));
100 PROTECT(accumvars = GET_SLOT(object,install("accumvars")));
101 PROTECT(covar = GET_SLOT(object,install("covar")));
102
103 nprotect += 4;
104
105
106 type = *(INTEGER(GET_SLOT(rproc,install("type"))));
107 switch (type) {
109 {
111 double deltat = 1.0;
112 PROTECT(
fn = GET_SLOT(rproc,install(
"step.fn")));
114 accumvars,covar,
args,gnsi));
115 nprotect += 2;
116 }
117 break;
119 {
121 double deltat;
122 PROTECT(
fn = GET_SLOT(rproc,install(
"step.fn")));
123 deltat = *(REAL(AS_NUMERIC(GET_SLOT(rproc,install("delta.t")))));
125 accumvars,covar,
args,gnsi));
126 nprotect += 2;
127 }
128 break;
130 {
131 SEXP
fn, vmatrix, hmax;
132 PROTECT(
fn = GET_SLOT(rproc,install(
"rate.fn")));
133 PROTECT(vmatrix = GET_SLOT(rproc,install("v")));
134 PROTECT(hmax = GET_SLOT(rproc,install("hmax")));
136 accumvars,hmax,
args,gnsi));
137 nprotect += 4;
138 }
139 break;
142 nprotect++;
143 break;
144 }
145
147 UNPROTECT(nprotect);
149
150}
SEXP euler_simulator(SEXP, SEXP, SEXP, SEXP, SEXP, double, rprocmode, SEXP, SEXP, SEXP, SEXP)
SEXP SSA_simulator(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)
static R_INLINE void fixdimnames(SEXP x, const char **names, int n)
static R_INLINE void setrownames(SEXP x, SEXP names, int rank)
static R_INLINE SEXP makearray(int rank, const int *dim)
static R_INLINE SEXP as_matrix(SEXP x)
static SEXP pomp_default_rprocess(SEXP xstart, int nvars, int nreps, int ntimes)