$search
00001 #include "cs.h" 00002 /* solve Gx=b(:,k), where G is either upper (lo=0) or lower (lo=1) triangular */ 00003 int cs_spsolve (cs *G, const cs *B, int k, int *xi, double *x, const int *pinv, 00004 int lo) 00005 { 00006 int j, J, p, q, px, top, n, *Gp, *Gi, *Bp, *Bi ; 00007 double *Gx, *Bx ; 00008 if (!CS_CSC (G) || !CS_CSC (B) || !xi || !x) return (-1) ; 00009 Gp = G->p ; Gi = G->i ; Gx = G->x ; n = G->n ; 00010 Bp = B->p ; Bi = B->i ; Bx = B->x ; 00011 top = cs_reach (G, B, k, xi, pinv) ; /* xi[top..n-1]=Reach(B(:,k)) */ 00012 for (p = top ; p < n ; p++) x [xi [p]] = 0 ; /* clear x */ 00013 for (p = Bp [k] ; p < Bp [k+1] ; p++) x [Bi [p]] = Bx [p] ; /* scatter B */ 00014 for (px = top ; px < n ; px++) 00015 { 00016 j = xi [px] ; /* x(j) is nonzero */ 00017 J = pinv ? (pinv [j]) : j ; /* j maps to col J of G */ 00018 if (J < 0) continue ; /* column J is empty */ 00019 x [j] /= Gx [lo ? (Gp [J]) : (Gp [J+1]-1)] ;/* x(j) /= G(j,j) */ 00020 p = lo ? (Gp [J]+1) : (Gp [J]) ; /* lo: L(j,j) 1st entry */ 00021 q = lo ? (Gp [J+1]) : (Gp [J+1]-1) ; /* up: U(j,j) last entry */ 00022 for ( ; p < q ; p++) 00023 { 00024 x [Gi [p]] -= Gx [p] * x [j] ; /* x(i) -= G(i,j) * x(j) */ 00025 } 00026 } 00027 return (top) ; /* return top of stack */ 00028 }