13(
size_t nrow,
size_t ncol,
const char **names)
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]));
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);
36(
const std::unordered_map<name_t, bool>& memo)
const
45 std::vector<slate_t>& x,
46 std::vector<slate_t>& y,
47 std::unordered_map<name_t, bool>& memo,
48 const std::unordered_map<
name_t, std::vector<node_t*>>& children,
53 const std::vector<node_t*>& ch = children.at(
uniq);
60 ch[0]->cblv(x, y, memo, children, t0);
62 for (
size_t i = 1; i < ch.size(); i++) {
64 y.push_back(
slate - t0);
66 ch[i]->cblv(x, y, memo, children, t0);
71std::pair<std::vector<slate_t>, std::vector<slate_t>>
77 std::vector<slate_t> x, y;
80 std::unordered_map<name_t, bool> memo;
85 p->
cblv(x, y, memo, children, t0);
101 if (nin <= 0)
err(
"invalid CBLV");
102 size_t n = size_t(nin);
106 err(
"invalid CBLV: x[0] = %lg > %lg = time-t0", x[0], t-t0);
109 for (
size_t k = 0; k <
n; k++) {
116 err(
"invalid CBLV: negative tip-edge length in position %zu", k+1);
123 err(
"invalid CBLV: negative internal branch-time in position %zu", k+1);
127 if (j->
slate < t)
err(
"invalid CBLV: node %zu cannot attach.", k+1);
128 while (j != i && i->
slate > t) {
144 if (p != 0)
err(
"invalid CBLV: last value of y is nonzero.");
153 const char *colnames[] = {
"tip",
"node"};
157 std::pair<std::vector<slate_t>, std::vector<slate_t>> rep;
159 n = rep.first.size();
163 for (i = 0; i <
n; i++) {
165 y[i] = rep.second[i];
181 int *
n = INTEGER(GET_DIM(XY));
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);
SEXP parse_cblv(SEXP XY, SEXP T0, SEXP Time)
parse CBLV representation
static R_INLINE SEXP make_matrix(size_t nrow, size_t ncol, const char **names)
SEXP cblv(genealogy_t &A)
size_t nsample(void) const
number of samples
genealogy_t & prune(void)
prune the tree (drop all black balls)
genealogy_t(double t0=R_NaReal, size_t ndeme=0)
genealogy_t & parse_cblv(const double *, const double *, int, double)
parse a CBLV representation in the vectors x and y.
void clip_zlb(void)
clip out all zero-length branches
slate_t & timezero(void)
view/set zero time.
std::pair< std::vector< slate_t >, std::vector< slate_t > > cblv(void) const
slate_t & time(void)
view/set current time.
node_t * make_node(name_t d=undeme)
friend SEXP cblv(genealogy_t &)
return the CBLV representation as an R matrix
genealogy_t & obscure(void)
erase all deme information
genealogy_t & insert_zlb(void)
insert zero-length branches for samples where needed
Encodes a genealogical node.
node_t * parent(void) const
void cblv(std::vector< slate_t > &, std::vector< slate_t > &, std::unordered_map< name_t, bool > &, const std::unordered_map< name_t, std::vector< node_t * > > &, slate_t) const
slate_t joining_branch_length(const std::unordered_map< name_t, bool > &) const
node_t(name_t u=0, slate_t t=R_NaReal)
basic constructor for node class
ball_t * green_ball(void) const
pointer to my green ball
void weed(void)
drop all dead roots
std::unordered_map< name_t, std::vector< node_t * > > children_map(void) const
map nodes onto vector of children
void sort(void)
order nodes in order of increasing time
void attach(node_t *p, node_t *q)
std::vector< node_t * > ladderize(std::unordered_map< name_t, std::vector< node_t * > > &children) const
void move(ball_t *b, node_t *p, node_t *q)
move ball b from p to q
SEXP serial(const TYPE &X)
binary serialization