7{
8
9 SEXP t0, times, x0, x, y;
10 SEXP ans = R_NilValue, ans_names = R_NilValue;
11 SEXP simnames;
12 int return_type = *(INTEGER(rettype));
13
14 if (LENGTH(nsim) != 1)
err(
"'nsim' must be a single integer");
15
17
18 PROTECT(t0 = GET_SLOT(object,install("t0")));
19 PROTECT(times = GET_SLOT(object,install("times")));
20
21
23 PROTECT(simnames = GET_COLNAMES(GET_DIMNAMES(x0)));
24
25
27
28
30
33
34 int nprotect = 7;
35
36 switch (return_type) {
37
38 case 0:
39
40 PROTECT(ans = NEW_LIST(2));
41 PROTECT(ans_names = NEW_CHARACTER(2));
42 nprotect += 2;
43 SET_STRING_ELT(ans_names,0,mkChar("states"));
44 SET_STRING_ELT(ans_names,1,mkChar("obs"));
45 SET_NAMES(ans,ans_names);
46 SET_ELEMENT(ans,0,x);
47 SET_ELEMENT(ans,1,y);
48
49 break;
50
51 case 1: default:
52
53
54 {
55 SEXP pp, xx, yy, po;
56 const int *xdim;
57 int nvar, npar, nobs, nsim, ntim, nparsets;
58 int dim[2], i, j, k;
59
60 PROTECT(po = duplicate(object));
61 SET_SLOT(po,install("t0"),t0);
62 SET_SLOT(po,install("times"),times);
63
64 xdim = INTEGER(GET_DIM(x));
65 nvar = xdim[0]; nsim = xdim[1]; ntim = xdim[2];
66
67 xdim = INTEGER(GET_DIM(y));
68 nobs = xdim[0];
69
70 xdim = INTEGER(GET_DIM(
params));
71 npar = xdim[0]; nparsets = xdim[1];
72
73 dim[0] = nvar; dim[1] = ntim;
76 SET_SLOT(po,install("states"),xx);
77
78 dim[0] = nobs; dim[1] = ntim;
81 SET_SLOT(po,install("data"),yy);
82
83 PROTECT(pp = NEW_NUMERIC(npar));
84 SET_NAMES(pp,GET_ROWNAMES(GET_DIMNAMES(
params)));
85 SET_SLOT(po,install("params"),pp);
86
87 PROTECT(ans = NEW_LIST(nsim));
88 SET_NAMES(ans,simnames);
89
90 nprotect += 5;
91
92 for (k = 0; k < nsim; k++) {
93
94 SEXP po2;
95 double *xs = REAL(x), *ys = REAL(y), *ps = REAL(
params);
96 double *xt, *yt, *pt;
97
98 PROTECT(po2 = duplicate(po));
99 xt = REAL(GET_SLOT(po2,install("states")));
100 yt = REAL(GET_SLOT(po2,install("data")));
101 pt = REAL(GET_SLOT(po2,install("params")));
102
103 memcpy(pt,ps+npar*(k%nparsets),npar*sizeof(double));
104
105
106 for (j = 0; j < ntim; j++) {
107 for (i = 0; i < nvar; i++, xt++) *xt = xs[i+nvar*(k+nsim*j)];
108 for (i = 0; i < nobs; i++, yt++) *yt = ys[i+nobs*(k+nsim*j)];
109 }
110
111 SET_ELEMENT(ans,k,po2);
112 UNPROTECT(1);
113
114 }
115
116 break;
117
118 }
119
120 }
121
122 UNPROTECT(nprotect);
123 return ans;
124
125}
SEXP do_rmeasure(SEXP, SEXP, SEXP, SEXP, SEXP)
SEXP do_rinit(SEXP, SEXP, SEXP, SEXP, SEXP)
SEXP do_rprocess(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)
static R_INLINE void setrownames(SEXP x, SEXP names, int rank)
static R_INLINE void setcolnames(SEXP x, SEXP names)
static R_INLINE SEXP makearray(int rank, const int *dim)
static R_INLINE SEXP as_matrix(SEXP x)