50{
51
52 SEXP Pnames, tparams, pompfun,
fn,
args, ob;
56 int *dim;
57
58 qvec = isNull(GET_DIM(
params));
59
60 PROTECT(tparams = duplicate(
params));
61
62
64 dim = INTEGER(GET_DIM(tparams));
66
67 PROTECT(Pnames = GET_ROWNAMES(GET_DIMNAMES(tparams)));
68
69
71 PROTECT(ob = GET_SLOT(object,install("partrans")));
72 switch (direc) {
74 PROTECT(pompfun = GET_SLOT(ob,install("from")));
75 break;
77 PROTECT(pompfun = GET_SLOT(ob,install("to")));
78 break;
79 }
80
82
83
84 PROTECT(
args = GET_SLOT(
object,install(
"userdata")));
85
86 int nprotect = 7;
87
89
91
92 SEXP ans, nm;
93 double *pa, *ps = REAL(tparams);
94 int *posn;
95 int i, j;
96
99
100 PROTECT(nm = GET_NAMES(ans));
102 err(
"user transformation functions must return named numeric vectors.");
103 posn = INTEGER(PROTECT(
matchnames(Pnames,nm,
"parameters")));
104
105 nprotect += 4;
106
107 pa = REAL(AS_NUMERIC(ans));
108
109 for (i = 0; i < LENGTH(ans); i++) ps[posn[i]] = pa[i];
110
112
114 pa = REAL(AS_NUMERIC(ans));
115 for (i = 0; i < LENGTH(ans); i++) ps[posn[i]] = pa[i];
116 UNPROTECT(1);
117
118 }
119
120 }
121
122 break;
123
125
127 double *ps, *pt;
128 int *idx;
129 int j;
130
131 *((
void **) (&ff)) = R_ExternalPtrAddr(
fn);
132
133 R_CheckUserInterrupt();
134
135 idx = INTEGER(GET_SLOT(pompfun,install("paramindex")));
136
138 (*ff)(pt,ps,idx);
139
140 }
141
142 break;
143
144 default:
145
146 break;
147
148 }
149
150 if (qvec) {
151 PROTECT(Pnames = GET_ROWNAMES(GET_DIMNAMES(tparams))); nprotect++;
152 SET_DIM(tparams,R_NilValue);
153 SET_NAMES(tparams,Pnames);
154 }
155
156 UNPROTECT(nprotect);
157 return tparams;
158
159}
SEXP pomp_fun_handler(SEXP, SEXP, pompfunmode *, SEXP, SEXP, SEXP, SEXP)
static R_INLINE SEXP eval_call(SEXP fn, SEXP args, double *p, int n)
static R_INLINE SEXP add_args(SEXP args, SEXP names)
void pomp_transform(double *pt, const double *p, const int *parindex)
static R_INLINE SEXP matchnames(SEXP provided, SEXP needed, const char *where)
static R_INLINE int invalid_names(SEXP names)
static R_INLINE SEXP as_matrix(SEXP x)