pomp
Inference for partially observed Markov processes
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pomp_defines.h File Reference
#include <R.h>
#include <Rmath.h>
#include <Rdefines.h>
#include "pomp.h"
Include dependency graph for pomp_defines.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lookup_table_t
 

Macros

#define MATCHROWNAMES(X, N, W)   (matchnames(GET_ROWNAMES(GET_DIMNAMES(X)),(N),(W)))
 
#define MATCHCOLNAMES(X, N, W)   (matchnames(GET_COLNAMES(GET_DIMNAMES(X)),(N),(W)))
 

Typedefs

typedef SEXP pomp_fun_handler_t(SEXP pfun, SEXP gnsi, pompfunmode *mode, SEXP S, SEXP P, SEXP O, SEXP C)
 
typedef SEXP load_stack_incr_t(SEXP pack)
 
typedef SEXP load_stack_decr_t(SEXP pack)
 
typedef lookup_table_t make_covariate_table_t(SEXP object, int *ncovar)
 
typedef void table_lookup_t(lookup_table_t *tab, double x, double *y)
 
typedef SEXP apply_probe_data_t(SEXP object, SEXP probes)
 
typedef SEXP apply_probe_sim_t(SEXP object, SEXP nsim, SEXP params, SEXP probes, SEXP datval, SEXP gnsi)
 
typedef SEXP systematic_resampling_t(SEXP weights)
 
typedef void set_pomp_userdata_t(SEXP userdata)
 
typedef void unset_pomp_userdata_t(void)
 
typedef SEXP get_covariate_names_t(SEXP object)
 

Enumerations

enum  pompfunmode { undef =0 , Rfun =1 , native =2 , regNative =3 }
 
enum  rprocmode {
  dflt =0 , onestep =1 , discrete =2 , euler =3 ,
  gill =4
}
 

Functions

static R_INLINE SEXP makearray (int rank, const int *dim)
 
static R_INLINE int invalid_names (SEXP names)
 
static R_INLINE SEXP matchnames (SEXP provided, SEXP needed, const char *where)
 
static R_INLINE void fillrownames (SEXP x, SEXP names)
 
static R_INLINE void setrownames (SEXP x, SEXP names, int rank)
 
static R_INLINE void setcolnames (SEXP x, SEXP names)
 
static R_INLINE void fixdimnames (SEXP x, const char **names, int n)
 
static R_INLINE SEXP as_matrix (SEXP x)
 
static R_INLINE SEXP as_state_array (SEXP x)
 
static R_INLINE SEXP getListElement (SEXP list, const char *str)
 
static R_INLINE SEXP getPairListElement (SEXP list, const char *name)
 

Macro Definition Documentation

◆ MATCHCOLNAMES

#define MATCHCOLNAMES (   X,
  N,
 
)    (matchnames(GET_COLNAMES(GET_DIMNAMES(X)),(N),(W)))

Definition at line 14 of file pomp_defines.h.

◆ MATCHROWNAMES

#define MATCHROWNAMES (   X,
  N,
 
)    (matchnames(GET_ROWNAMES(GET_DIMNAMES(X)),(N),(W)))

Definition at line 13 of file pomp_defines.h.

Typedef Documentation

◆ apply_probe_data_t

typedef SEXP apply_probe_data_t(SEXP object, SEXP probes)

Definition at line 33 of file pomp_defines.h.

◆ apply_probe_sim_t

typedef SEXP apply_probe_sim_t(SEXP object, SEXP nsim, SEXP params, SEXP probes, SEXP datval, SEXP gnsi)

Definition at line 34 of file pomp_defines.h.

◆ get_covariate_names_t

typedef SEXP get_covariate_names_t(SEXP object)

Definition at line 38 of file pomp_defines.h.

◆ load_stack_decr_t

typedef SEXP load_stack_decr_t(SEXP pack)

Definition at line 30 of file pomp_defines.h.

◆ load_stack_incr_t

typedef SEXP load_stack_incr_t(SEXP pack)

Definition at line 29 of file pomp_defines.h.

◆ make_covariate_table_t

typedef lookup_table_t make_covariate_table_t(SEXP object, int *ncovar)

Definition at line 31 of file pomp_defines.h.

◆ pomp_fun_handler_t

typedef SEXP pomp_fun_handler_t(SEXP pfun, SEXP gnsi, pompfunmode *mode, SEXP S, SEXP P, SEXP O, SEXP C)

Definition at line 28 of file pomp_defines.h.

◆ set_pomp_userdata_t

typedef void set_pomp_userdata_t(SEXP userdata)

Definition at line 36 of file pomp_defines.h.

◆ systematic_resampling_t

typedef SEXP systematic_resampling_t(SEXP weights)

Definition at line 35 of file pomp_defines.h.

◆ table_lookup_t

typedef void table_lookup_t(lookup_table_t *tab, double x, double *y)

Definition at line 32 of file pomp_defines.h.

◆ unset_pomp_userdata_t

typedef void unset_pomp_userdata_t(void)

Definition at line 37 of file pomp_defines.h.

Enumeration Type Documentation

◆ pompfunmode

Enumerator
undef 
Rfun 
native 
regNative 

Definition at line 16 of file pomp_defines.h.

pompfunmode
@ Rfun
@ native
@ undef
@ regNative

◆ rprocmode

enum rprocmode
Enumerator
dflt 
onestep 
discrete 
euler 
gill 

Definition at line 17 of file pomp_defines.h.

rprocmode
@ gill
@ discrete
@ dflt
@ onestep
@ euler

Function Documentation

◆ as_matrix()

static R_INLINE SEXP as_matrix ( SEXP  x)
static

Definition at line 145 of file pomp_defines.h.

145 {
146 int nprotect = 1;
147 SEXP dim, names;
148 int *xdim, nrow, ncol;
149 PROTECT(dim = GET_DIM(x));
150 if (isNull(dim)) {
151 PROTECT(x = duplicate(x));
152 PROTECT(names = GET_NAMES(x));
153 nprotect += 2;
154 dim = NEW_INTEGER(2);
155 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1;
156 SET_DIM(x,dim);
157 SET_NAMES(x,R_NilValue);
158 setrownames(x,names,2);
159 } else if (LENGTH(dim) == 1) {
160 PROTECT(x = duplicate(x));
161 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
162 nprotect += 2;
163 dim = NEW_INTEGER(2);
164 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1;
165 SET_DIM(x,dim);
166 SET_NAMES(x,R_NilValue);
167 setrownames(x,names,2);
168 } else if (LENGTH(dim) > 2) {
169 PROTECT(x = duplicate(x));
170 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
171 nprotect += 2;
172 nrow = INTEGER(dim)[0]; ncol = LENGTH(x)/nrow;
173 dim = NEW_INTEGER(2);
174 xdim = INTEGER(dim); xdim[0] = nrow; xdim[1] = ncol;
175 SET_DIM(x,dim);
176 SET_NAMES(x,R_NilValue);
177 setrownames(x,names,2);
178 }
179 UNPROTECT(nprotect);
180 return x;
181}
static R_INLINE void setrownames(SEXP x, SEXP names, int rank)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ as_state_array()

static R_INLINE SEXP as_state_array ( SEXP  x)
static

Definition at line 183 of file pomp_defines.h.

183 {
184 int nprotect = 1;
185 SEXP dim, names;
186 int *xdim, nrow, ncol;
187 PROTECT(dim = GET_DIM(x));
188 if (isNull(dim)) {
189 PROTECT(x = duplicate(x));
190 PROTECT(names = GET_NAMES(x));
191 nprotect += 2;
192 dim = NEW_INTEGER(3);
193 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1; xdim[2] = 1;
194 SET_DIM(x,dim);
195 SET_NAMES(x,R_NilValue);
196 setrownames(x,names,3);
197 } else if (LENGTH(dim) == 1) {
198 PROTECT(x = duplicate(x));
199 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
200 nprotect += 2;
201 dim = NEW_INTEGER(3);
202 xdim = INTEGER(dim); xdim[0] = LENGTH(x); xdim[1] = 1; xdim[2] = 1;
203 SET_DIM(x,dim);
204 SET_NAMES(x,R_NilValue);
205 setrownames(x,names,3);
206 } else if (LENGTH(dim) == 2) {
207 PROTECT(x = duplicate(x));
208 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
209 nprotect += 2;
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;
213 SET_DIM(x,dim);
214 SET_NAMES(x,R_NilValue);
215 setrownames(x,names,3);
216 } else if (LENGTH(dim) > 3) {
217 PROTECT(x = duplicate(x));
218 PROTECT(names = GET_ROWNAMES(GET_DIMNAMES(x)));
219 nprotect += 2;
220 xdim = INTEGER(dim); nrow = xdim[0]; ncol = xdim[1];
221 dim = NEW_INTEGER(3);
222 xdim = INTEGER(dim);
223 xdim[0] = nrow; xdim[1] = ncol; xdim[2] = LENGTH(x)/nrow/ncol;
224 SET_DIM(x,dim);
225 SET_NAMES(x,R_NilValue);
226 setrownames(x,names,3);
227 }
228 UNPROTECT(nprotect);
229 return x;
230}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fillrownames()

static R_INLINE void fillrownames ( SEXP  x,
SEXP  names 
)
static

Definition at line 87 of file pomp_defines.h.

87 {
88 SEXP dim, dimnms;
89 int nr;
90 PROTECT(names = AS_CHARACTER(names));
91 PROTECT(dim = GET_DIM(x));
92 PROTECT(dimnms = allocVector(VECSXP,length(dim)));
93 nr = INTEGER(dim)[0];
94 if (nr > length(names)) {
95 SEXP nm;
96 int k;
97 PROTECT(nm = NEW_CHARACTER(nr));
98 for (k = 0; k < length(names); k++) {
99 SET_STRING_ELT(nm,k,STRING_ELT(names,k));
100 }
101 SET_ELEMENT(dimnms,0,nm);
102 UNPROTECT(1);
103 } else {
104 SET_ELEMENT(dimnms,0,names);
105 }
106 SET_DIMNAMES(x,dimnms);
107 UNPROTECT(3);
108}
Here is the caller graph for this function:

◆ fixdimnames()

static R_INLINE void fixdimnames ( SEXP  x,
const char **  names,
int  n 
)
static

Definition at line 129 of file pomp_defines.h.

129 {
130 int nprotect = 2;
131 int i;
132 SEXP dimnames, nm;
133 PROTECT(dimnames = GET_DIMNAMES(x));
134 if (isNull(dimnames)) {
135 PROTECT(dimnames = allocVector(VECSXP,n)); nprotect++;
136 }
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);
142 UNPROTECT(nprotect);
143}
Here is the caller graph for this function:

◆ getListElement()

static R_INLINE SEXP getListElement ( SEXP  list,
const char *  str 
)
static

Definition at line 232 of file pomp_defines.h.

233{
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);
239 break;
240 }
241 return elmt;
242}
Here is the caller graph for this function:

◆ getPairListElement()

static R_INLINE SEXP getPairListElement ( SEXP  list,
const char *  name 
)
static

Definition at line 244 of file pomp_defines.h.

245{
246 const char *tag;
247 while (list != R_NilValue) {
248 tag = CHAR(PRINTNAME(TAG(list)));
249 if (strcmp(tag,name)==0) break;
250 list = CDR(list);
251 }
252 return CAR(list);
253}

◆ invalid_names()

static R_INLINE int invalid_names ( SEXP  names)
static

Definition at line 55 of file pomp_defines.h.

55 {
56 return isNull(names);
57}
Here is the caller graph for this function:

◆ makearray()

static R_INLINE SEXP makearray ( int  rank,
const int *  dim 
)
static

Definition at line 40 of file pomp_defines.h.

40 {
41 int *dimp, k;
42 double *xp;
43 SEXP dimx, x;
44 PROTECT(dimx = NEW_INTEGER(rank));
45 dimp = INTEGER(dimx);
46 for (k = 0; k < rank; k++) dimp[k] = dim[k];
47 PROTECT(x = allocArray(REALSXP,dimx));
48 xp = REAL(x);
49 for (k = 0; k < length(x); k++) xp[k] = NA_REAL;
50 UNPROTECT(2);
51 return x;
52}
Here is the caller graph for this function:

◆ matchnames()

static R_INLINE SEXP matchnames ( SEXP  provided,
SEXP  needed,
const char *  where 
)
static

Definition at line 59 of file pomp_defines.h.

62 {
63 int m = LENGTH(provided);
64 int n = length(needed);
65 SEXP index;
66 int *idx, i, j;
67 PROTECT(provided = AS_CHARACTER(provided));
68 PROTECT(needed = AS_CHARACTER(needed));
69 if (invalid_names(provided))
70 err("invalid variable names among the %s.",where); // #nocov
71 PROTECT(index = NEW_INTEGER(n));
72 idx = INTEGER(index);
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)))) {
76 idx[i] = j;
77 break;
78 }
79 }
80 if (j==m)
81 err("variable '%s' not found among the %s.",CHAR(STRING_ELT(needed,i)),where);
82 }
83 UNPROTECT(3);
84 return index;
85}
#define err(...)
Definition pomp.h:21
static R_INLINE int invalid_names(SEXP names)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setcolnames()

static R_INLINE void setcolnames ( SEXP  x,
SEXP  names 
)
static

Definition at line 121 of file pomp_defines.h.

121 {
122 SEXP dn;
123 PROTECT(dn = GET_DIMNAMES(x));
124 SET_ELEMENT(dn,1,names);
125 SET_DIMNAMES(x,dn);
126 UNPROTECT(1);
127}
Here is the caller graph for this function:

◆ setrownames()

static R_INLINE void setrownames ( SEXP  x,
SEXP  names,
int  rank 
)
static

Definition at line 110 of file pomp_defines.h.

110 {
111 SEXP dimnms, nm;
112 PROTECT(nm = AS_CHARACTER(names));
113 PROTECT(dimnms = allocVector(VECSXP,rank));
114 SET_ELEMENT(dimnms,0,nm); // set row names
115 SET_DIMNAMES(x,dimnms);
116 UNPROTECT(2);
117}
Here is the caller graph for this function: