cs_updown.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* sparse Cholesky update/downdate, L*L' + sigma*w*w' (sigma = +1 or -1) */
3 int cs_updown (cs *L, int sigma, const cs *C, const int *parent)
4 {
5  int n, p, f, j, *Lp, *Li, *Cp, *Ci ;
6  double *Lx, *Cx, alpha, beta = 1, delta, gammaa, w1, w2, *w, beta2 = 1 ;
7  if (!CS_CSC (L) || !CS_CSC (C) || !parent) return (0) ; /* check inputs */
8  Lp = L->p ; Li = L->i ; Lx = L->x ; n = L->n ;
9  Cp = C->p ; Ci = C->i ; Cx = C->x ;
10  if ((p = Cp [0]) >= Cp [1]) return (1) ; /* return if C empty */
11  w = (double*)cs_malloc (n, sizeof (double)) ; /* get workspace */
12  if (!w) return (0) ; /* out of memory */
13  f = Ci [p] ;
14  for ( ; p < Cp [1] ; p++) f = CS_MIN (f, Ci [p]) ; /* f = min (find (C)) */
15  for (j = f ; j != -1 ; j = parent [j]) w [j] = 0 ; /* clear workspace w */
16  for (p = Cp [0] ; p < Cp [1] ; p++) w [Ci [p]] = Cx [p] ; /* w = C */
17  for (j = f ; j != -1 ; j = parent [j]) /* walk path f up to root */
18  {
19  p = Lp [j] ;
20  alpha = w [j] / Lx [p] ; /* alpha = w(j) / L(j,j) */
21  beta2 = beta*beta + sigma*alpha*alpha ;
22  if (beta2 <= 0) break ; /* not positive definite */
23  beta2 = sqrt (beta2) ;
24  delta = (sigma > 0) ? (beta / beta2) : (beta2 / beta) ;
25  gammaa = sigma * alpha / (beta2 * beta) ;
26  Lx [p] = delta * Lx [p] + ((sigma > 0) ? (gammaa * w [j]) : 0) ;
27  beta = beta2 ;
28  for (p++ ; p < Lp [j+1] ; p++)
29  {
30  w1 = w [Li [p]] ;
31  w [Li [p]] = w2 = w1 - alpha * Lx [p] ;
32  Lx [p] = delta * Lx [p] + gammaa * ((sigma > 0) ? w1 : w2) ;
33  }
34  }
35  cs_free (w) ;
36  return (beta2 > 0) ;
37 }
IntermediateState sqrt(const Expression &arg)
int n
Definition: cs.h:20
void * cs_free(void *p)
Definition: cs_malloc.c:22
int cs_updown(cs *L, int sigma, const cs *C, const int *parent)
Definition: cs_updown.c:3
#define CS_CSC(A)
Definition: cs.h:140
int * p
Definition: cs.h:21
Definition: cs.h:16
int * i
Definition: cs.h:22
void * cs_malloc(int n, size_t size)
Definition: cs_malloc.c:10
#define L
#define CS_MIN(a, b)
Definition: cs.h:135
double * x
Definition: cs.h:23


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