コード例 #1
0
ファイル: util.c プロジェクト: fransklaver/SPOOLES
/*
   ---------------------------------------------------------
   sort the rows so the row ids are in ascending order
   sort the columns so the column ids are in ascending order

   created -- 98may02, cca
   ---------------------------------------------------------
*/
void
DenseMtx_sort (
   DenseMtx   *mtx
) {
A2    a2 ;
int   ii, ncol, nrow, sortColumns, sortRows ;
int   *colind, *rowind ;
/*
   ----------------
   check the output
   ----------------
*/
if ( mtx == NULL ) {
   fprintf(stderr, "\n fatal error in DenseMtx_sort(%p)"
           "\n bad input\n", mtx) ;
   spoolesFatal();
}
DenseMtx_rowIndices(mtx, &nrow, &rowind) ;
DenseMtx_columnIndices(mtx, &ncol, &colind) ;
if ( nrow <= 0 || ncol <= 0 ) {
   return ;
}
sortRows = sortColumns = 0 ;
for ( ii = 1 ; ii < nrow ; ii++ ) {
   if ( rowind[ii-1] > rowind[ii] ) {
      sortRows = 1 ;
      break ;
   }
}
for ( ii = 1 ; ii < ncol ; ii++ ) {
   if ( colind[ii-1] > colind[ii] ) {
      sortColumns = 1 ;
      break ;
   }
}
if ( sortRows == 0 && sortColumns == 0 ) {
   return ;
}
A2_setDefaultFields(&a2) ;
DenseMtx_setA2(mtx, &a2) ;
if ( sortRows == 1 ) {
   A2_sortRowsUp(&a2, nrow, rowind) ;
}
if ( sortColumns == 1 ) {
   A2_sortColumnsUp(&a2, ncol, colind) ;
}
return ; }
コード例 #2
0
ファイル: sort.c プロジェクト: bialk/SPOOLES
/*
   -----------------------------------------
   permute the columns of the matrix
   A(*,*) = A(*,index(*))
   this method calls A2_sortColumnsUp
   but does not overwrite the index[] vector

   created -- 98apr15, cca
   -----------------------------------------
*/
void
A2_permuteColumns (
   A2   *mtx,
   int   ncol,
   int   index[]
) {
int   *colids ;
/*
   ---------------
   check the input
   ---------------
*/
if ( mtx == NULL || ncol < 0 || ncol > mtx->n2 || index == NULL ) {
   fprintf(stderr, "\n fatal error in A2_permuteColumns(%p,%d,%p)"
           "\n bad input\n", mtx, ncol, index) ;
   exit(-1) ;
}
colids = IVinit(ncol, -1) ;
IVcopy(ncol, colids, index) ;
A2_sortColumnsUp(mtx, ncol, colids) ;
IVfree(colids) ;

return ; }