cs_spsolve.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* solve Gx=b(:,k), where G is either upper (lo=0) or lower (lo=1) triangular */
3 int cs_spsolve (cs *G, const cs *B, int k, int *xi, double *x, const int *pinv,
4  int lo)
5 {
6  int j, J, p, q, px, top, n, *Gp, *Gi, *Bp, *Bi ;
7  double *Gx, *Bx ;
8  if (!CS_CSC (G) || !CS_CSC (B) || !xi || !x) return (-1) ;
9  Gp = G->p ; Gi = G->i ; Gx = G->x ; n = G->n ;
10  Bp = B->p ; Bi = B->i ; Bx = B->x ;
11  top = cs_reach (G, B, k, xi, pinv) ; /* xi[top..n-1]=Reach(B(:,k)) */
12  for (p = top ; p < n ; p++) x [xi [p]] = 0 ; /* clear x */
13  for (p = Bp [k] ; p < Bp [k+1] ; p++) x [Bi [p]] = Bx [p] ; /* scatter B */
14  for (px = top ; px < n ; px++)
15  {
16  j = xi [px] ; /* x(j) is nonzero */
17  J = pinv ? (pinv [j]) : j ; /* j maps to col J of G */
18  if (J < 0) continue ; /* column J is empty */
19  x [j] /= Gx [lo ? (Gp [J]) : (Gp [J+1]-1)] ;/* x(j) /= G(j,j) */
20  p = lo ? (Gp [J]+1) : (Gp [J]) ; /* lo: L(j,j) 1st entry */
21  q = lo ? (Gp [J+1]) : (Gp [J+1]-1) ; /* up: U(j,j) last entry */
22  for ( ; p < q ; p++)
23  {
24  x [Gi [p]] -= Gx [p] * x [j] ; /* x(i) -= G(i,j) * x(j) */
25  }
26  }
27  return (top) ; /* return top of stack */
28 }
int cs_reach(cs *G, const cs *B, int k, int *xi, const int *pinv)
Definition: cs_reach.c:4
int n
Definition: cs.h:20
#define CS_CSC(A)
Definition: cs.h:140
int * p
Definition: cs.h:21
Definition: cs.h:16
int * i
Definition: cs.h:22
double * x
Definition: cs.h:23
int cs_spsolve(cs *G, const cs *B, int k, int *xi, double *x, const int *pinv, int lo)
Definition: cs_spsolve.c:3


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:31