cs_transpose.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* C = A' */
3 cs *cs_transpose (const cs *A, int values)
4 {
5  int p, q, j, *Cp, *Ci, n, m, *Ap, *Ai, *w ;
6  double *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 = (int*)cs_calloc (m, 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 (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] = Ax [p] ;
22  }
23  }
24  return (cs_done (C, w, NULL, 1)) ; /* success; free w and return C */
25 }
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_CSC(A)
Definition: cs.h:140
cs * cs_transpose(const cs *A, int values)
Definition: cs_transpose.c:3
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
double * x
Definition: cs.h:23
int m
Definition: cs.h:19


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