Coverage Report

Created: 2023-06-07 06:06

/src/igraph/vendor/cs/cs_counts.c
Line
Count
Source (jump to first uncovered line)
1
#include "cs.h"
2
/* column counts of LL'=A or LL'=A'A, given parent & post ordering */
3
0
#define HEAD(k,j) (ata ? head [k] : j)
4
0
#define NEXT(J)   (ata ? next [J] : -1)
5
static void init_ata (cs *AT, const CS_INT *post, CS_INT *w, CS_INT **head, CS_INT **next)
6
0
{
7
0
    CS_INT i, k, p, m = AT->n, n = AT->m, *ATp = AT->p, *ATi = AT->i ;
8
0
    *head = w+4*n, *next = w+5*n+1 ;
9
0
    for (k = 0 ; k < n ; k++) w [post [k]] = k ;    /* invert post */
10
0
    for (i = 0 ; i < m ; i++)
11
0
    {
12
0
        for (k = n, p = ATp[i] ; p < ATp[i+1] ; p++) k = CS_MIN (k, w [ATi[p]]);
13
0
        (*next) [i] = (*head) [k] ;     /* place row i in linked list k */
14
0
        (*head) [k] = i ;
15
0
    }
16
0
}
17
CS_INT *cs_counts (const cs *A, const CS_INT *parent, const CS_INT *post, CS_INT ata)
18
0
{
19
0
    CS_INT i, j, k, n, m, J, s, p, q, jleaf, *ATp, *ATi, *maxfirst, *prevleaf,
20
0
        *ancestor, *head = NULL, *next = NULL, *colcount, *w, *first, *delta ;
21
0
    cs *AT ;
22
0
    if (!CS_CSC (A) || !parent || !post) return (NULL) ;    /* check inputs */
23
0
    m = A->m ; n = A->n ;
24
0
    s = 4*n + (ata ? (n+m+1) : 0) ;
25
0
    delta = colcount = cs_malloc (n, sizeof (CS_INT)) ;    /* allocate result */
26
0
    w = cs_malloc (s, sizeof (CS_INT)) ;                   /* get workspace */
27
0
    AT = cs_transpose (A, 0) ;                          /* AT = A' */
28
0
    if (!AT || !colcount || !w) return (cs_idone (colcount, AT, w, 0)) ;
29
0
    ancestor = w ; maxfirst = w+n ; prevleaf = w+2*n ; first = w+3*n ;
30
0
    for (k = 0 ; k < s ; k++) w [k] = -1 ;      /* clear workspace w [0..s-1] */
31
0
    for (k = 0 ; k < n ; k++)                   /* find first [j] */
32
0
    {
33
0
        j = post [k] ;
34
0
        delta [j] = (first [j] == -1) ? 1 : 0 ;  /* delta[j]=1 if j is a leaf */
35
0
        for ( ; j != -1 && first [j] == -1 ; j = parent [j]) first [j] = k ;
36
0
    }
37
0
    ATp = AT->p ; ATi = AT->i ;
38
0
    if (ata) init_ata (AT, post, w, &head, &next) ;
39
0
    for (i = 0 ; i < n ; i++) ancestor [i] = i ; /* each node in its own set */
40
0
    for (k = 0 ; k < n ; k++)
41
0
    {
42
0
        j = post [k] ;          /* j is the kth node in postordered etree */
43
0
        if (parent [j] != -1) delta [parent [j]]-- ;    /* j is not a root */
44
0
        for (J = HEAD (k,j) ; J != -1 ; J = NEXT (J))   /* J=j for LL'=A case */
45
0
        {
46
0
            for (p = ATp [J] ; p < ATp [J+1] ; p++)
47
0
            {
48
0
                i = ATi [p] ;
49
0
                q = cs_leaf (i, j, first, maxfirst, prevleaf, ancestor, &jleaf);
50
0
                if (jleaf >= 1) delta [j]++ ;   /* A(i,j) is in skeleton */
51
0
                if (jleaf == 2) delta [q]-- ;   /* account for overlap in q */
52
0
            }
53
0
        }
54
0
        if (parent [j] != -1) ancestor [j] = parent [j] ;
55
0
    }
56
0
    for (j = 0 ; j < n ; j++)           /* sum up delta's of each child */
57
0
    {
58
0
        if (parent [j] != -1) colcount [parent [j]] += colcount [j] ;
59
0
    }
60
0
    return (cs_idone (colcount, AT, w, 1)) ;    /* success: free workspace */
61
0
}