EVSL  1.1.0
EigenValues Slicing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
cs_transpose.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* C = A' */
3 cs *cs_transpose (const cs *A, CS_INT values)
4 {
5  CS_INT p, q, j, *Cp, *Ci, n, m, *Ap, *Ai, *w ;
6  CS_ENTRY *Cx, *Ax ;
7  cs *C ;
8  if (!CS_CSC (A)) return (NULL) ; /* check inputs */
9  m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
10  C = cs_spalloc (n, m, Ap [n], values && Ax, 0) ; /* allocate result */
11  w = cs_calloc (m, 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 (p = 0 ; p < Ap [n] ; p++) w [Ai [p]]++ ; /* row counts */
15  cs_cumsum (Cp, w, m) ; /* row pointers */
16  for (j = 0 ; j < n ; j++)
17  {
18  for (p = Ap [j] ; p < Ap [j+1] ; p++)
19  {
20  Ci [q = w [Ai [p]]++] = j ; /* place A(i,j) as entry C(j,i) */
21  if (Cx) Cx [q] = (values > 0) ? CS_CONJ (Ax [p]) : Ax [p] ;
22  }
23  }
24  return (cs_done (C, w, NULL, 1)) ; /* success; free w and return C */
25 }
#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_CSC(A)
Definition: cs.h:659
void * cs_calloc(CS_INT n, size_t size)
Definition: cs_malloc.c:16
cs * cs_transpose(const cs *A, CS_INT values)
Definition: cs_transpose.c:3
#define CS_INT
Definition: cs.h:627
cs * cs_done(cs *C, void *w, void *x, CS_INT ok)
Definition: cs_util.c:90