3#ifndef _POMP_DEFINES_H_
4#define _POMP_DEFINES_H_
13# define MATCHROWNAMES(X,N,W) (matchnames(GET_ROWNAMES(GET_DIMNAMES(X)),(N),(W)))
14# define MATCHCOLNAMES(X,N,W) (matchnames(GET_COLNAMES(GET_DIMNAMES(X)),(N),(W)))
40static R_INLINE SEXP
makearray (
int rank,
const int *dim) {
44 PROTECT(dimx = NEW_INTEGER(rank));
46 for (k = 0; k < rank; k++) dimp[k] = dim[k];
47 PROTECT(x = allocArray(REALSXP,dimx));
49 for (k = 0; k < length(x); k++) xp[k] = NA_REAL;
40static R_INLINE SEXP
makearray (
int rank,
const int *dim) {
…}
61 SEXP provided, SEXP needed,
const char *where
63 int m = LENGTH(provided);
64 int n = length(needed);
67 PROTECT(provided = AS_CHARACTER(provided));
68 PROTECT(needed = AS_CHARACTER(needed));
70 err(
"invalid variable names among the %s.",where);
71 PROTECT(index = NEW_INTEGER(n));
73 for (i = 0; i < n; i++) {
74 for (j = 0; j < m; j++) {
75 if (!strcmp(CHAR(STRING_ELT(provided,j)),CHAR(STRING_ELT(needed,i)))) {
81 err(
"variable '%s' not found among the %s.",CHAR(STRING_ELT(needed,i)),where);
90 PROTECT(names = AS_CHARACTER(names));
91 PROTECT(dim = GET_DIM(x));
92 PROTECT(dimnms = allocVector(VECSXP,length(dim)));
94 if (nr > length(names)) {
97 PROTECT(nm = NEW_CHARACTER(nr));
98 for (k = 0; k < length(names); k++) {
99 SET_STRING_ELT(nm,k,STRING_ELT(names,k));
101 SET_ELEMENT(dimnms,0,nm);
104 SET_ELEMENT(dimnms,0,names);
106 SET_DIMNAMES(x,dimnms);
112 PROTECT(nm = AS_CHARACTER(names));
113 PROTECT(dimnms = allocVector(VECSXP,rank));
114 SET_ELEMENT(dimnms,0,nm);
115 SET_DIMNAMES(x,dimnms);
123 PROTECT(dn = GET_DIMNAMES(x));
124 SET_ELEMENT(dn,1,names);
129static R_INLINE
void fixdimnames (SEXP x,
const char **names,
int n) {
133 PROTECT(dimnames = GET_DIMNAMES(x));
134 if (isNull(dimnames)) {
135 PROTECT(dimnames = allocVector(VECSXP,n)); nprotect++;
137 PROTECT(nm = allocVector(VECSXP,n));
138 for (i = 0; i < n; i++)
139 SET_ELEMENT(nm,i,mkChar(names[i]));
140 SET_NAMES(dimnames,nm);
141 SET_DIMNAMES(x,dimnames);
129static R_INLINE
void fixdimnames (SEXP x,
const char **names,
int n) {
…}
148 int *xdim, nrow, ncol;
149 PROTECT(dim = GET_DIM(x));
151 PROTECT(x = duplicate(x));
152 PROTECT(names = GET_NAMES(x));
154 dim = NEW_INTEGER(2);
155 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1;
157 SET_NAMES(x,R_NilValue);
159 }
else if (LENGTH(dim) == 1) {
160 PROTECT(x = duplicate(x));
161 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
163 dim = NEW_INTEGER(2);
164 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1;
166 SET_NAMES(x,R_NilValue);
168 }
else if (LENGTH(dim) > 2) {
169 PROTECT(x = duplicate(x));
170 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
172 nrow = INTEGER(dim)[0]; ncol = LENGTH(x)/nrow;
173 dim = NEW_INTEGER(2);
174 xdim = INTEGER(dim); xdim[0] = nrow; xdim[1] = ncol;
176 SET_NAMES(x,R_NilValue);
186 int *xdim, nrow, ncol;
187 PROTECT(dim = GET_DIM(x));
189 PROTECT(x = duplicate(x));
190 PROTECT(names = GET_NAMES(x));
192 dim = NEW_INTEGER(3);
193 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1; xdim[2] = 1;
195 SET_NAMES(x,R_NilValue);
197 }
else if (LENGTH(dim) == 1) {
198 PROTECT(x = duplicate(x));
199 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
201 dim = NEW_INTEGER(3);
202 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1; xdim[2] = 1;
204 SET_NAMES(x,R_NilValue);
206 }
else if (LENGTH(dim) == 2) {
207 PROTECT(x = duplicate(x));
208 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
210 xdim = INTEGER(dim); nrow = xdim[0]; ncol = xdim[1];
211 dim = NEW_INTEGER(3);
212 xdim = INTEGER(dim); xdim[0] = nrow; xdim[1] = 1; xdim[2] = ncol;
214 SET_NAMES(x,R_NilValue);
216 }
else if (LENGTH(dim) > 3) {
217 PROTECT(x = duplicate(x));
218 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
220 xdim = INTEGER(dim); nrow = xdim[0]; ncol = xdim[1];
221 dim = NEW_INTEGER(3);
223 xdim[0] = nrow; xdim[1] = ncol; xdim[2] = LENGTH(x)/nrow/ncol;
225 SET_NAMES(x,R_NilValue);
234 SEXP elmt = R_NilValue;
235 SEXP names = getAttrib(list,R_NamesSymbol);
236 for (R_len_t i = 0; i < length(list); i++)
237 if (strcmp(CHAR(STRING_ELT(names,i)),str) == 0) {
238 elmt = VECTOR_ELT(list,i);
247 while (list != R_NilValue) {
248 tag = CHAR(PRINTNAME(TAG(list)));
249 if (strcmp(tag,name)==0)
break;
257template <
class Scalar>
268 view (Scalar *x,
int d1) {
273 view (Scalar *x,
int d1,
int d2) {
279 inline Scalar& operator () (
int d1) {
282 inline Scalar& operator () (
int d1,
int d2) {
283 return(data[d1 + dim[0] * d2]);
285 inline Scalar& operator () (
int d1,
int d2,
int d3) {
286 return(data[d1 + dim[0] * (d2 + dim[1] * d3)]);
lookup_table_t make_covariate_table_t(SEXP object, int *ncovar)
static R_INLINE void fixdimnames(SEXP x, const char **names, int n)
static R_INLINE void setrownames(SEXP x, SEXP names, int rank)
SEXP pomp_fun_handler_t(SEXP pfun, SEXP gnsi, pompfunmode *mode, SEXP S, SEXP P, SEXP O, SEXP C)
void set_pomp_userdata_t(SEXP userdata)
SEXP load_stack_decr_t(SEXP pack)
void unset_pomp_userdata_t(void)
static R_INLINE void fillrownames(SEXP x, SEXP names)
static R_INLINE SEXP matchnames(SEXP provided, SEXP needed, const char *where)
static R_INLINE void setcolnames(SEXP x, SEXP names)
void table_lookup_t(lookup_table_t *tab, double x, double *y)
SEXP load_stack_incr_t(SEXP pack)
SEXP apply_probe_sim_t(SEXP object, SEXP nsim, SEXP params, SEXP probes, SEXP datval, SEXP gnsi)
static R_INLINE SEXP makearray(int rank, const int *dim)
static R_INLINE SEXP as_state_array(SEXP x)
SEXP systematic_resampling_t(SEXP weights)
SEXP apply_probe_data_t(SEXP object, SEXP probes)
static R_INLINE SEXP getListElement(SEXP list, const char *str)
SEXP get_covariate_names_t(SEXP object)
static R_INLINE int invalid_names(SEXP names)
static R_INLINE SEXP as_matrix(SEXP x)
static R_INLINE SEXP getPairListElement(SEXP list, const char *name)