00001 #include "cs.h"
00002 
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) ;    
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) ;  
00011     if (!C) return (cs_done (C, NULL, NULL, 0)) ;   
00012     Cp = C->p ; Ci = C->i ; Cx = C->x ;
00013     for (k = 0 ; k < n ; k++)
00014     {
00015         Cp [k] = nz ;                   
00016         j = q ? (q [k]) : k ;
00017         for (t = Ap [j] ; t < Ap [j+1] ; t++)
00018         {
00019             if (Cx) Cx [nz] = Ax [t] ;  
00020             Ci [nz++] = pinv ? (pinv [Ai [t]]) : Ai [t] ;
00021         }
00022     }
00023     Cp [n] = nz ;                       
00024     return (cs_done (C, NULL, NULL, 1)) ;
00025 }