externals/SuiteSparse/LDL/ldl_di.c
/* Given a sparse matrix A (the arguments n, Ap, Ai, and Ax) and its symbolic
 * analysis (Lp and Parent, and optionally P and Pinv), compute the numeric LDL'
 * factorization of A or PAP'.  The outputs of this routine are arguments Li,
 * Lx, and D.  It also requires three size-n workspaces (Y, Pattern, and Flag).
 */
Given a sparse matrix A (the arguments n, Ap, Ai, and Ax) and its symbolic
analysis (Lp and Parent, and optionally P and Pinv), compute the numeric LDL'
factorization of A or PAP'.  The outputs of this routine are arguments Li,
Lx, and D.  It also requires three size-n workspaces (Y, Pattern, and Flag).
Given a sparse matrix A ( the arguments n Ap Ai and Ax ) and its symbolic analysis ( Lp and Parent and optionally P and Pinv ) compute the numeric LDL ' factorization of A or PAP ' . The outputs of this routine are arguments Li Lx and D . It also requires three size - n workspaces ( Y Pattern and Flag ) .
LDL_int LDL_numeric	
(
    LDL_int n,		
    LDL_int Ap [ ],	
    LDL_int Ai [ ],	
    double Ax [ ],	
    LDL_int Lp [ ],	
    LDL_int Parent [ ],	
    LDL_int Lnz [ ],	
    LDL_int Li [ ],	
    double Lx [ ],	
    double D [ ],	
    double Y [ ],	
    LDL_int Pattern [ ],
    LDL_int Flag [ ],	
    LDL_int P [ ],	
    LDL_int Pinv [ ]	
)
{
    double yi, l_ki ;
    LDL_int i, k, p, kk, p2, len, top ;
    for (k = 0 ; k < n ; k++)
    {
	Y [k] = 0.0 ;		    
	top = n ;		    
	Flag [k] = k ;		    
	Lnz [k] = 0 ;		    
	kk = (P) ? (P [k]) : (k) ;  
	p2 = Ap [kk+1] ;
	for (p = Ap [kk] ; p < p2 ; p++)
	{
	    i = (Pinv) ? (Pinv [Ai [p]]) : (Ai [p]) ;	
	    if (i <= k)
	    {
		Y [i] += Ax [p] ;  
		for (len = 0 ; Flag [i] != k ; i = Parent [i])
		{
		    Pattern [len++] = i ;   
		    Flag [i] = k ;	    
		}
		while (len > 0) Pattern [--top] = Pattern [--len] ;
	    }
	}
	D [k] = Y [k] ;		    
	Y [k] = 0.0 ;
	for ( ; top < n ; top++)
	{
	    i = Pattern [top] ;	    
	    yi = Y [i] ;	    
	    Y [i] = 0.0 ;
	    p2 = Lp [i] + Lnz [i] ;
	    for (p = Lp [i] ; p < p2 ; p++)
	    {
		Y [Li [p]] -= Lx [p] * yi ;
	    }
	    l_ki = yi / D [i] ;	    
	    D [k] -= l_ki * yi ;
	    Li [p] = k ;	    
	    Lx [p] = l_ki ;
	    Lnz [i]++ ;		    
	}
	if (D [k] == 0.0) return (k) ;	    
    }
    return (n) ;	
}
LDL_int LDL_numeric ( LDL_int n , LDL_int Ap [ ] , LDL_int Ai [ ] , double Ax [ ] , LDL_int Lp [ ] , LDL_int Parent [ ] , LDL_int Lnz [ ] , LDL_int Li [ ] , double Lx [ ] , double D [ ] , double Y [ ] , LDL_int Pattern [ ] , LDL_int Flag [ ] , LDL_int P [ ] , LDL_int Pinv [ ] ) { double yi , l_ki ; LDL_int i , k , p , kk , p2 , len , top ; for ( k = 0 ; k < n ; k ++ ) { Y [ k ] = 0.0 ; top = n ; Flag [ k ] = k ; Lnz [ k ] = 0 ; kk = ( P ) ? ( P [ k ] ) : ( k ) ; p2 = Ap [ kk + 1 ] ; for ( p = Ap [ kk ] ; p < p2 ; p ++ ) { i = ( Pinv ) ? ( Pinv [ Ai [ p ] ] ) : ( Ai [ p ] ) ; if ( i <= k ) { Y [ i ] += Ax [ p ] ; for ( len = 0 ; Flag [ i ] != k ; i = Parent [ i ] ) { Pattern [ len ++ ] = i ; Flag [ i ] = k ; } while ( len > 0 ) Pattern [ -- top ] = Pattern [ -- len ] ; } } D [ k ] = Y [ k ] ; Y [ k ] = 0.0 ; for ( ; top < n ; top ++ ) { i = Pattern [ top ] ; yi = Y [ i ] ; Y [ i ] = 0.0 ; p2 = Lp [ i ] + Lnz [ i ] ; for ( p = Lp [ i ] ; p < p2 ; p ++ ) { Y [ Li [ p ] ] -= Lx [ p ] * yi ; } l_ki = yi / D [ i ] ; D [ k ] -= l_ki * yi ; Li [ p ] = k ; Lx [ p ] = l_ki ; Lnz [ i ] ++ ; } if ( D [ k ] == 0.0 ) return ( k ) ; } return ( n ) ; }
Given a sparse matrix A (the arguments n, Ap, Ai, and Ax) and its symbolic
 analysis (Lp and Parent, and optionally P and Pinv), compute the numeric LDL'
 factorization of A or PAP'.
Given a sparse matrix A ( the arguments n Ap Ai and Ax ) and its symbolic analysis ( Lp and Parent and optionally P and Pinv ) compute the numeric LDL ' factorization of A or PAP ' .
/* returns n if successful, k if D (k,k) is zero */ /* A and L are n-by-n, where n >= 0 */ /* input of size n+1, not modified */ /* input of size nz=Ap[n], not modified */ /* input of size nz=Ap[n], not modified */ /* input of size n+1, not modified */ /* input of size n, not modified */ /* output of size n, not defn. on input */ /* output of size lnz=Lp[n], not defined on input */ /* output of size lnz=Lp[n], not defined on input */ /* output of size n, not defined on input */ /* workspace of size n, not defn. on input or output */ /* workspace of size n, not defn. on input or output */ /* workspace of size n, not defn. on input or output */ /* optional input of size n */ /* optional input of size n */ /* compute nonzero Pattern of kth row of L, in topological order */ /* Y(0:k) is now all zero */ /* stack for pattern is empty */ /* mark node k as visited */ /* count of nonzeros in column k of L */ /* kth original, or permuted, column */ /* get A(i,k) */ /* scatter A(i,k) into Y (sum duplicates) */ /* L(k,i) is nonzero */ /* mark i as visited */ /* compute numerical values kth row of L (a sparse triangular solve) */ /* get D(k,k) and clear Y(k) */ /* Pattern [top:n-1] is pattern of L(:,k) */ /* get and clear Y(i) */ /* the nonzero entry L(k,i) */ /* store L(k,i) in column form of L */ /* increment count of nonzeros in col i */ /* failure, D(k,k) is zero */ /* success, diagonal of D is all nonzero */