cs_symperm.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* C = A(p,p) where A and C are symmetric the upper part stored; pinv not p */
3 cs *cs_symperm (const cs *A, const int *pinv, int values)
4 {
5  int i, j, p, q, i2, j2, n, *Ap, *Ai, *Cp, *Ci, *w ;
6  double *Cx, *Ax ;
7  cs *C ;
8  if (!CS_CSC (A)) return (NULL) ; /* check inputs */
9  n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
10  C = cs_spalloc (n, n, Ap [n], values && (Ax != NULL), 0) ; /* alloc result*/
11  w = (int*)cs_calloc (n, sizeof (int)) ; /* get workspace */
12  if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */
13  Cp = C->p ; Ci = C->i ; Cx = C->x ;
14  for (j = 0 ; j < n ; j++) /* count entries in each column of C */
15  {
16  j2 = pinv ? pinv [j] : j ; /* column j of A is column j2 of C */
17  for (p = Ap [j] ; p < Ap [j+1] ; p++)
18  {
19  i = Ai [p] ;
20  if (i > j) continue ; /* skip lower triangular part of A */
21  i2 = pinv ? pinv [i] : i ; /* row i of A is row i2 of C */
22  w [CS_MAX (i2, j2)]++ ; /* column count of C */
23  }
24  }
25  cs_cumsum (Cp, w, n) ; /* compute column pointers of C */
26  for (j = 0 ; j < n ; j++)
27  {
28  j2 = pinv ? pinv [j] : j ; /* column j of A is column j2 of C */
29  for (p = Ap [j] ; p < Ap [j+1] ; p++)
30  {
31  i = Ai [p] ;
32  if (i > j) continue ; /* skip lower triangular part of A*/
33  i2 = pinv ? pinv [i] : i ; /* row i of A is row i2 of C */
34  Ci [q = w [CS_MAX (i2, j2)]++] = CS_MIN (i2, j2) ;
35  if (Cx) Cx [q] = Ax [p] ;
36  }
37  }
38  return (cs_done (C, w, NULL, 1)) ; /* success; free workspace, return C */
39 }
cs * cs_spalloc(int m, int n, int nzmax, int values, int triplet)
Definition: cs_util.c:3
cs * cs_done(cs *C, void *w, void *x, int ok)
Definition: cs_util.c:89
int n
Definition: cs.h:20
#define CS_MAX(a, b)
Definition: cs.h:134
#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_calloc(int n, size_t size)
Definition: cs_malloc.c:16
double cs_cumsum(int *p, int *c, int n)
Definition: cs_cumsum.c:3
cs * cs_symperm(const cs *A, const int *pinv, int values)
Definition: cs_symperm.c:3
#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