EVSL  1.1.0 EigenValues Slicing Library
cs_permute.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* C = A(p,q) where p and q are permutations of 0..m-1 and 0..n-1. */
3 cs *cs_permute (const cs *A, const CS_INT *pinv, const CS_INT *q, CS_INT values)
4 {
5  CS_INT t, j, k, nz = 0, m, n, *Ap, *Ai, *Cp, *Ci ;
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 (m, n, Ap [n], values && Ax != NULL, 0) ; /* alloc result */
11  if (!C) return (cs_done (C, NULL, NULL, 0)) ; /* out of memory */
12  Cp = C->p ; Ci = C->i ; Cx = C->x ;
13  for (k = 0 ; k < n ; k++)
14  {
15  Cp [k] = nz ; /* column k of C is column q[k] of A */
16  j = q ? (q [k]) : k ;
17  for (t = Ap [j] ; t < Ap [j+1] ; t++)
18  {
19  if (Cx) Cx [nz] = Ax [t] ; /* row i of A is row pinv[i] of C */
20  Ci [nz++] = pinv ? (pinv [Ai [t]]) : Ai [t] ;
21  }
22  }
23  Cp [n] = nz ; /* finalize the last column of C */
24  return (cs_done (C, NULL, NULL, 1)) ;
25 }
#define cs
Definition: cs.h:637
#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
#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_permute(const cs *A, const CS_INT *pinv, const CS_INT *q, CS_INT values)
Definition: cs_permute.c:3