File: phyloXX.c

package info (click to toggle)
r-cran-phylobase 0.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,308 kB
  • sloc: cpp: 306; ansic: 247; xml: 135; lisp: 38; sh: 9; makefile: 5
file content (97 lines) | stat: -rw-r--r-- 2,504 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
  descendants.c:
    Identify all descendants of a given node. Function inputs are
  derived from a phylo4 edge matrix, which *must* be in preorder order.
  The isDescendant input vector should contain 1 for the immediate
  children of the node, and 0 otherwise. The function returns this
  vector updated to include all further descendants.
*/

// test1 <- function() {
//     for (i in edge[, 2]) {
//         dex <- edge[, 1] == i
//         cur <- edge[, 2] == i
//         xx[dex] <- phy@edge.length[dex] + xx[cur]
//         segs$v0x[dex] <- xx[cur]
//     }
//     return(list(segs=segs, xx=xx))
// }
// test1out <- test1()
// segs <- test1out$segs
// xx   <- test1out$xx

// test2 <- function() {
//     for(i in rev((Ntips + 1):nEdges(phy))) {
//         dex <- edge[, 1] == i
//         cur <- edge[, 2] == i
//         yy[cur] <- segs$v0y[dex] <- mean(yy[dex])
//     }
//     return(list(segs=segs, yy=yy))
// }
// test2out <- test2()
// segs <- test2out$segs
// yy   <- test2out$yy
// segs$h0y <- segs$h1y <- segs$v1y <- yy

#include <R.h>

// 
// void phyloyy(int *edge1, int *edge2, int *ntips, 
//                  int *numEdges, double *yy, double *v0y) 
// {
//     int i;
//     int k;
//     int j;
//     int cur;
//     int des;
//     int count;
//     double tmp;
//     double theMean;
//     Rprintf("test\n");
//     for (i=*numEdges; i > *ntips ; i--) {
//         for (k=0; k<*numEdges; k++) {
//             if(i == edge2[k]) {
//                 cur = k;
//             }
//         }
//         tmp=0;
//         count=0;
//         for (j=0; j<*numEdges; j++) {
//             if(i == edge1[j]) {
//                 des = j;
//                 tmp += yy[j];
//                 count += 1;
//             }
//         }
//         theMean  = tmp / count;
//         yy[cur]  = theMean;
//         for (j=0; j<*numEdges; j++) {
//             if(i == edge1[j]) {
//                 v0y[j] = theMean;
//             }
//         }
// 
//     }
// }

void phyloxx(int *edge1, int *edge2, double *edgeLengths, 
                 int *numEdges, double *xx, double *v0x) 
{
    int j;
    int i;
    int k;
    int cur=0;
    for (i=0; i <*numEdges; i++) {
        for (k=0; k<*numEdges; k++) {
            if(edge2[i] == edge2[k]) {
                cur = k;
            }
        }
        for (j=0; j<*numEdges; j++) {
            if(edge2[i] == edge1[j]) {
                xx[j] = edgeLengths[j] + xx[cur];
                v0x[j] = xx[cur];
            }
        }
    }
}