10static R_INLINE SEXP
paste0 (SEXP a, SEXP b) {
12 PROTECT(p = lang3(install(
"paste0"),a,b));
13 PROTECT(v = eval(p,R_BaseEnv));
10static R_INLINE SEXP
paste0 (SEXP a, SEXP b) {
…}
21 SEXP S1names, S2names;
26 PROTECT(s1 = mkString(
"_1"));
27 PROTECT(s2 = mkString(
"_2"));
31 PROTECT(
args = VectorToPairList(
args));
34 for (v = LENGTH(Cnames)-1; v >= 0; v--) {
39 SET_TAG(
args,installChar(STRING_ELT(Cnames,v)));
43 for (v = LENGTH(Pnames)-1; v >= 0; v--) {
48 SET_TAG(
args,installChar(STRING_ELT(Pnames,v)));
52 for (v = LENGTH(
Snames)-1; v >= 0; v--) {
58 SET_TAG(
args,installChar(STRING_ELT(S2names,v)));
64 SET_TAG(
args,installChar(STRING_ELT(S1names,v)));
73 SET_TAG(
args,install(
"t_2"));
79 SET_TAG(
args,install(
"t_1"));
89 double *t1,
double *t2,
90 double *x1,
double *x2,
int nvar,
95 SEXP var =
args, ans, ob;
98 *(REAL(CAR(var))) = *t1; var = CDR(var);
99 *(REAL(CAR(var))) = *t2; var = CDR(var);
100 for (v = 0; v < nvar; v++, x1++, x2++) {
101 *(REAL(CAR(var))) = *x1; var = CDR(var);
102 *(REAL(CAR(var))) = *x2; var = CDR(var);
104 for (v = 0; v < npar; v++, p++, var=CDR(var)) *(REAL(CAR(var))) = *p;
105 for (v = 0; v < ncov; v++, c++, var=CDR(var)) *(REAL(CAR(var))) = *c;
107 PROTECT(ob = LCONS(
fn,
args));
108 PROTECT(ans = eval(ob,CLOENV(
fn)));
117 int dim[2] = {
nreps, ntimes};
118 const char *dimnm[2] = {
".id",
"time"};
129 SEXP func, SEXP x, SEXP times, SEXP
params, SEXP covar,
130 SEXP log, SEXP
args, SEXP gnsi
136 SEXP
Snames, Pnames, Cnames;
142 ntimes = LENGTH(times);
143 dim = INTEGER(GET_DIM(x));
nvars = dim[0]; nrepsx = dim[1];
145 err(
"length(times) < 2: with no transitions, there is no work to do.");
146 if (ntimes != dim[2])
147 err(
"the length of 'times' and 3rd dimension of 'x' do not agree.");
148 dim = INTEGER(GET_DIM(
params));
npars = dim[0]; nrepsp = dim[1];
150 give_log = *(INTEGER(AS_INTEGER(log)));
153 if (nrepsx != nrepsp && nrepsx % nrepsp != 0 && nrepsp % nrepsx != 0) {
154 err(
"the larger number of replicates is not a multiple of smaller.");
156 nreps = (nrepsx > nrepsp) ? nrepsx : nrepsp;
159 PROTECT(
Snames = GET_ROWNAMES(GET_DIMNAMES(x)));
160 PROTECT(Pnames = GET_ROWNAMES(GET_DIMNAMES(
params)));
167 PROTECT(cvec = NEW_NUMERIC(
ncovars));
173 double *t1 = REAL(times), *t2 = REAL(times)+1;
174 double *x1p = REAL(x);
175 double *x2p = REAL(x)+nrepsx*
nvars;
176 double *ft = REAL(F);
184 for (
int k = 0; k < ntimes-1; k++, t1++, t2++) {
186 R_CheckUserInterrupt();
191 for (
int j = 0; j <
nreps; j++, ft++) {
194 double *x1 = x1p+
nvars*(j%nrepsx);
195 double *x2 = x2p+
nvars*(j%nrepsx);
197 PROTECT(ans =
eval_call(
fn,
args,t1,t2,x1,x2,
nvars,p,
npars,
cov,
ncovars));
198 *ft = *REAL(AS_NUMERIC(ans));
201 if (!give_log) *ft = exp(*ft);
216 int *sidx, *pidx, *cidx;
219 sidx = INTEGER(GET_SLOT(func,install(
"stateindex")));
220 pidx = INTEGER(GET_SLOT(func,install(
"paramindex")));
221 cidx = INTEGER(GET_SLOT(func,install(
"covarindex")));
223 *((
void **) (&ff)) = R_ExternalPtrAddr(
fn);
225 for (
int k = 0; k < ntimes-1; k++, t1++, t2++) {
227 R_CheckUserInterrupt();
232 for (
int j = 0; j <
nreps; j++, ft++) {
235 double *x1 = x1p+
nvars*(j%nrepsx);
236 double *x2 = x2p+
nvars*(j%nrepsx);
238 (*ff)(ft,x1,x2,*t1,*t2,p,sidx,pidx,cidx,
cov);
240 if (!give_log) *ft = exp(*ft);
254 double *ft = REAL(F);
257 for (k = 0; k < ntimes-1; k++) {
258 for (j = 0; j <
nreps; j++, ft++) {
263 warn(
"'dprocess' unspecified: likelihood undefined.");
276 PROTECT(times=AS_NUMERIC(times));
280 PROTECT(
fn = GET_SLOT(
object,install(
"dprocess")));
282 PROTECT(
args = GET_SLOT(
object,install(
"userdata")));
283 PROTECT(covar = GET_SLOT(
object,install(
"covar")));
lookup_table_t make_covariate_table(SEXP, int *)
SEXP pomp_fun_handler(SEXP, SEXP, pompfunmode *, SEXP, SEXP, SEXP, SEXP)
void table_lookup(lookup_table_t *, double, double *)
SEXP get_covariate_names(SEXP)
SEXP do_dprocess(SEXP object, SEXP x, SEXP times, SEXP params, SEXP log, SEXP gnsi)
static R_INLINE SEXP paste0(SEXP a, SEXP b)
static R_INLINE SEXP eval_call(SEXP fn, SEXP args, double *t1, double *t2, double *x1, double *x2, int nvar, double *p, int npar, double *c, int ncov)
static R_INLINE SEXP add_args(SEXP args, SEXP Snames, SEXP Pnames, SEXP Cnames)
static R_INLINE SEXP ret_array(int nreps, int ntimes)
static SEXP onestep_density(SEXP func, SEXP x, SEXP times, SEXP params, SEXP covar, SEXP log, SEXP args, SEXP gnsi)
void pomp_dprocess(double *loglik, const double *x1, const double *x2, double t1, double t2, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars)
static R_INLINE void fixdimnames(SEXP x, const char **names, int n)
static R_INLINE SEXP makearray(int rank, const int *dim)
static R_INLINE SEXP as_state_array(SEXP x)
static R_INLINE SEXP as_matrix(SEXP x)