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 int *pinv, const int *q, int values)
4 {
5  int t, j, k, nz = 0, m, n, *Ap, *Ai, *Cp, *Ci ;
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 (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 }
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
cs * cs_permute(const cs *A, const int *pinv, const int *q, int values)
Definition: cs_permute.c:3
int n
Definition: cs.h:20
#define CS_CSC(A)
Definition: cs.h:140
int * p
Definition: cs.h:21
Definition: cs.h:16
int * i
Definition: cs.h:22
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