Compute filled pattern.

       colptr, rowidx = embed(A, colcount, snode, snptr, snpar, snpost)

    PURPOSE
    Computes rowindices and column pointer for representative vertices in supernodes.

    ARGUMENTS
    A         sparse matrix

    colcount  vector with column counts

    snode     vector with supernodes
 
    snptr     vector with offsets

    snpar     vector with supernodal parent indices

    snpost    vector with supernodal post ordering

    RETURNS
    colptr    vector with offsets 

    rowidx    vector with rowindices

def embed(A, colcount, snode, snptr, snpar, snpost):
    """
    Compute filled pattern.

       colptr, rowidx = embed(A, colcount, snode, snptr, snpar, snpost)

    PURPOSE
    Computes rowindices and column pointer for representative vertices in supernodes.

    ARGUMENTS
    A         sparse matrix

    colcount  vector with column counts

    snode     vector with supernodes
 
    snptr     vector with offsets

    snpar     vector with supernodal parent indices

    snpost    vector with supernodal post ordering

    RETURNS
    colptr    vector with offsets 

    rowidx    vector with rowindices 
    """

    Alo = tril(A)
    cp,ri,_ = Alo.CCS
    N = len(snpar)

    # colptr for compressed cholesky factor
    colptr = matrix(0,(N+1,1))
    for k in range(N):
        colptr[k+1] = colptr[k] + colcount[snode[snptr[k]]]
    rowidx = matrix(-1,(colptr[-1],1))
    cnnz = matrix(0,(N,1))

    # compute compressed sparse representation
    for k in range(N):
        p = snptr[k]
        Nk = snptr[k+1]-p
        nk = cp[snode[p]+1] - cp[snode[p]]
        rowidx[colptr[k]:colptr[k]+nk] = ri[cp[snode[p]]:cp[snode[p]+1]]
        cnnz[k] = nk
        for i in range(1,Nk):
            nk = cp[snode[p+i]+1]-cp[snode[p+i]]
            cnnz[k] = lmerge(rowidx, ri, colptr[k], cp[snode[p+i]], cnnz[k], nk)

    for k in snpost:
        p = snptr[k]
        Nk = snptr[k+1]-p
        if snpar[k] != k:
            cnnz[snpar[k]] = lmerge(rowidx,rowidx,colptr[snpar[k]], colptr[k]+Nk,cnnz[snpar[k]], cnnz[k]-Nk)

    return colptr, rowidx