phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
cblv.cc File Reference
#include "genealogy.h"
#include "generics.h"
#include "internal.h"
#include <utility>
#include <vector>
#include <R.h>
#include <Rdefines.h>
#include <Rinternals.h>
Include dependency graph for cblv.cc:

Go to the source code of this file.

Functions

static R_INLINE SEXP make_matrix (size_t nrow, size_t ncol, const char **names)
 
SEXP cblv (genealogy_t &A)
 
SEXP cblv (SEXP State)
 construct CBLV representation as a matrix
 
SEXP parse_cblv (SEXP XY, SEXP T0, SEXP Time)
 parse CBLV representation
 

Function Documentation

◆ cblv() [1/2]

SEXP cblv ( genealogy_t & A)

Definition at line 150 of file cblv.cc.

152{
153 const char *colnames[] = {"tip","node"};
154 double *x, *y;
155 size_t i, n;
156 SEXP S;
157 std::pair<std::vector<slate_t>, std::vector<slate_t>> rep;
158 rep = A.prune().obscure().insert_zlb().cblv();
159 n = rep.first.size();
160 PROTECT(S = make_matrix(n,2,colnames));
161 x = REAL(S);
162 y = REAL(S)+n;
163 for (i = 0; i < n; i++) {
164 x[i] = rep.first[i];
165 y[i] = rep.second[i];
166 }
167 UNPROTECT(1);
168 return S;
169}
static R_INLINE SEXP make_matrix(size_t nrow, size_t ncol, const char **names)
Definition cblv.cc:13
genealogy_t & prune(void)
prune the tree (drop all black balls)
Definition genealogy.h:311
friend SEXP cblv(genealogy_t &)
return the CBLV representation as an R matrix
Definition cblv.cc:151
genealogy_t & obscure(void)
erase all deme information
Definition genealogy.h:322
genealogy_t & insert_zlb(void)
insert zero-length branches for samples where needed
Definition genealogy.h:359
#define n
Definition lbdp_pomp.c:9
#define S
Definition seirs_pomp.c:38
Here is the caller graph for this function:

◆ cblv() [2/2]

SEXP cblv ( SEXP State)

construct CBLV representation as a matrix

Definition at line 174 of file cblv.cc.

174 {
175 genealogy_t A = State;
176 return cblv(A);
177 }
SEXP cblv(genealogy_t &A)
Definition cblv.cc:151
Encodes a genealogy.
Definition genealogy.h:20
Here is the call graph for this function:

◆ make_matrix()

static R_INLINE SEXP make_matrix ( size_t nrow,
size_t ncol,
const char ** names )
static

Definition at line 12 of file cblv.cc.

14{
15 SEXP dim, x;
16 SEXP dimnm, nm;
17 int *dimp;
18 size_t k;
19 PROTECT(dim = NEW_INTEGER(2));
20 PROTECT(dimnm = Rf_allocVector(VECSXP,2));
21 PROTECT(nm = NEW_CHARACTER(ncol));
22 for (k = 0; k < ncol; k++)
23 SET_STRING_ELT(nm,k,mkChar(names[k]));
24 dimp = INTEGER(dim);
25 dimp[0] = nrow; dimp[1] = ncol;
26 PROTECT(x = Rf_allocArray(REALSXP,dim));
27 SET_ELEMENT(dimnm,0,R_NilValue);
28 SET_ELEMENT(dimnm,1,nm);
29 SET_DIMNAMES(x,dimnm);
30 UNPROTECT(4);
31 return x;
32}
Here is the caller graph for this function:

◆ parse_cblv()

SEXP parse_cblv ( SEXP XY,
SEXP T0,
SEXP Time )

parse CBLV representation

Definition at line 180 of file cblv.cc.

180 {
181 int *n = INTEGER(GET_DIM(XY));
182 if (n[1] != 2)
183 err("in 'parse_cblv': 'xy' must be a two-column matrix.");
184 double *xp = REAL(XY);
185 double *yp = xp+n[0];
186 double *t0 = REAL(T0);
187 double *time = REAL(Time);
188 genealogy_t A(*t0);
189 A.parse_cblv(xp,yp,*n,*time);
190 return serial(A);
191 }
SEXP time(TYPE &X)
Definition generics.h:27
SEXP serial(const TYPE &X)
binary serialization
Definition generics.h:33
#define err(...)
Definition internal.h:18
Here is the call graph for this function: