cs_permute.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* C = A(p,q) where p and q are permutations of 0..m-1 and 0..n-1. */
00003 cs *cs_permute (const cs *A, const int *pinv, const int *q, int values)
00004 {
00005     int t, j, k, nz = 0, m, n, *Ap, *Ai, *Cp, *Ci ;
00006     double *Cx, *Ax ;
00007     cs *C ;
00008     if (!CS_CSC (A)) return (NULL) ;    /* check inputs */
00009     m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
00010     C = cs_spalloc (m, n, Ap [n], values && Ax != NULL, 0) ;  /* alloc result */
00011     if (!C) return (cs_done (C, NULL, NULL, 0)) ;   /* out of memory */
00012     Cp = C->p ; Ci = C->i ; Cx = C->x ;
00013     for (k = 0 ; k < n ; k++)
00014     {
00015         Cp [k] = nz ;                   /* column k of C is column q[k] of A */
00016         j = q ? (q [k]) : k ;
00017         for (t = Ap [j] ; t < Ap [j+1] ; t++)
00018         {
00019             if (Cx) Cx [nz] = Ax [t] ;  /* row i of A is row pinv[i] of C */
00020             Ci [nz++] = pinv ? (pinv [Ai [t]]) : Ai [t] ;
00021         }
00022     }
00023     Cp [n] = nz ;                       /* finalize the last column of C */
00024     return (cs_done (C, NULL, NULL, 1)) ;
00025 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:00