EVSL  1.1.0
EigenValues Slicing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
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 CS_INT *pinv, CS_INT values)
4 {
5  CS_INT i, j, p, q, i2, j2, n, *Ap, *Ai, *Cp, *Ci, *w ;
6  CS_ENTRY *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 = cs_calloc (n, sizeof (CS_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] = (i2 <= j2) ? Ax [p] : CS_CONJ (Ax [p]) ;
36  }
37  }
38  return (cs_done (C, w, NULL, 1)) ; /* success; free workspace, return C */
39 }
#define cs
Definition: cs.h:637
double cs_cumsum(CS_INT *p, CS_INT *c, CS_INT n)
Definition: cs_cumsum.c:3
#define CS_CONJ(x)
Definition: cs.h:649
#define CS_ENTRY
Definition: cs.h:635
cs * cs_spalloc(CS_INT m, CS_INT n, CS_INT nzmax, CS_INT values, CS_INT triplet)
Definition: cs_util.c:3
#define CS_MAX(a, b)
Definition: cs.h:653
#define CS_CSC(A)
Definition: cs.h:659
void * cs_calloc(CS_INT n, size_t size)
Definition: cs_malloc.c:16
#define CS_INT
Definition: cs.h:627
cs * cs_done(cs *C, void *w, void *x, CS_INT ok)
Definition: cs_util.c:90
cs * cs_symperm(const cs *A, const CS_INT *pinv, CS_INT values)
Definition: cs_symperm.c:3
#define CS_MIN(a, b)
Definition: cs.h:654