pomp
Inference for partially observed Markov processes
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lookup_table.c File Reference
#include <R.h>
#include <Rmath.h>
#include <Rdefines.h>
#include "internal.h"
Include dependency graph for lookup_table.c:

Go to the source code of this file.

Functions

SEXP get_covariate_names (SEXP object)
 
lookup_table_t make_covariate_table (SEXP object, int *ncovar)
 
SEXP lookup_in_table (SEXP covar, SEXP t)
 
void table_lookup (lookup_table_t *tab, double x, double *y)
 

Function Documentation

◆ get_covariate_names()

SEXP get_covariate_names ( SEXP  object)

Definition at line 7 of file lookup_table.c.

7 {
8 return GET_ROWNAMES(GET_DIMNAMES(GET_SLOT(object,install("table"))));
9}
Here is the caller graph for this function:

◆ lookup_in_table()

SEXP lookup_in_table ( SEXP  covar,
SEXP  t 
)

Definition at line 24 of file lookup_table.c.

24 {
25 int xdim[2], nvar;
26 int j, nt;
27 double *tp, *xp;
28 SEXP Cnames, X;
29
30 PROTECT(t = AS_NUMERIC(t));
31 nt = LENGTH(t);
32 PROTECT(Cnames = get_covariate_names(covar));
33
34 lookup_table_t tab = make_covariate_table(covar,&nvar);
35
36 if (nt > 1) {
37 xdim[0] = nvar; xdim[1] = nt;
38 PROTECT(X = makearray(2,xdim));
39 setrownames(X,Cnames,2);
40 } else {
41 PROTECT(X = NEW_NUMERIC(nvar));
42 SET_NAMES(X,Cnames);
43 }
44
45 for (j = 0, tp = REAL(t), xp = REAL(X); j < nt; j++, tp++, xp += nvar)
46 table_lookup(&tab,*tp,xp);
47
48 UNPROTECT(3);
49 return X;
50}
#define X
Definition gompertz.c:14
void table_lookup(lookup_table_t *tab, double x, double *y)
lookup_table_t make_covariate_table(SEXP object, int *ncovar)
SEXP get_covariate_names(SEXP object)
Definition lookup_table.c:7
static R_INLINE void setrownames(SEXP x, SEXP names, int rank)
static R_INLINE SEXP makearray(int rank, const int *dim)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_covariate_table()

lookup_table_t make_covariate_table ( SEXP  object,
int *  ncovar 
)

Definition at line 11 of file lookup_table.c.

11 {
13 int *dim;
14 dim = INTEGER(GET_DIM(GET_SLOT(object,install("table"))));
15 *ncovar = tab.width = dim[0];
16 tab.length = dim[1];
17 tab.index = 0;
18 tab.x = REAL(GET_SLOT(object,install("times")));
19 tab.y = REAL(GET_SLOT(object,install("table")));
20 tab.order = *(INTEGER(GET_SLOT(object,install("order"))));
21 return tab;
22}
Here is the caller graph for this function:

◆ table_lookup()

void table_lookup ( lookup_table_t tab,
double  x,
double *  y 
)

Definition at line 53 of file lookup_table.c.

54{
55 int flag = 0;
56 int j, k, n;
57 double e;
58 if ((tab == 0) || (tab->length < 1) || (tab->width < 1)) return;
59 tab->index = findInterval(tab->x,tab->length,x,1,1,tab->index,&flag);
60 // warn only if we are *outside* the interval
61 if ((x < tab->x[0]) || (x > tab->x[tab->length-1]))
62 warn("in 'table_lookup': extrapolating at %le.", x);
63 switch (tab->order) {
64 case 1: default: // linear interpolation
65 e = (x - tab->x[tab->index-1]) / (tab->x[tab->index] - tab->x[tab->index-1]);
66 for (j = 0, k = tab->index*tab->width, n = k-tab->width; j < tab->width; j++, k++, n++) {
67 y[j] = e*(tab->y[k])+(1-e)*(tab->y[n]);
68 }
69 break;
70 case 0: // piecewise constant
71 if (flag < 0) n = 0;
72 else if (flag > 0) n = tab->index;
73 else n = tab->index-1;
74 for (j = 0, k = n*tab->width; j < tab->width; j++, k++) {
75 y[j] = tab->y[k];
76 }
77 break;
78 }
79}
#define warn(...)
Definition pomp.h:22
Here is the caller graph for this function: