1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/* test_sort.c */
#include "../SubMtx.h"
#include "../../Drand.h"
#include "../../timings.h"
/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
-----------------------
test the sort methods.
created -- 98apr15, cca
-----------------------
*/
{
SubMtx *mtxA ;
double t1, t2 ;
Drand *drand ;
FILE *msgFile ;
int mode, msglvl, ncolA, nentA, nrowA, seed, type ;
int *colind, *ivtemp, *rowind ;
if ( argc != 9 ) {
fprintf(stdout,
"\n\n usage : %s msglvl msgFile type mode "
"\n nrowA ncolA nentA seed"
"\n msglvl -- message level"
"\n msgFile -- message file"
"\n type -- type of entries"
"\n 1 -- real"
"\n 2 -- complex"
"\n mode -- type of matrix A"
"\n 0 -- dense stored by rows"
"\n 1 -- dense stored by columns"
"\n 2 -- sparse stored by rows"
"\n 3 -- sparse stored by columns"
"\n nrowA -- # of rows in matrix A"
"\n ncolA -- # of columns in matrix A"
"\n nentA -- # of entries in matrix A"
"\n seed -- random number seed"
"\n", argv[0]) ;
return(0) ;
}
if ( (msglvl = atoi(argv[1])) < 0 ) {
fprintf(stderr, "\n message level must be positive\n") ;
exit(-1) ;
}
if ( strcmp(argv[2], "stdout") == 0 ) {
msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
fprintf(stderr, "\n unable to open file %s\n", argv[2]) ;
return(-1) ;
}
type = atoi(argv[3]) ;
mode = atoi(argv[4]) ;
nrowA = atoi(argv[5]) ;
ncolA = atoi(argv[6]) ;
nentA = atoi(argv[7]) ;
seed = atoi(argv[8]) ;
fprintf(msgFile, "\n %% %s:"
"\n %% msglvl = %d"
"\n %% msgFile = %s"
"\n %% type = %d"
"\n %% mode = %d"
"\n %% nrowA = %d"
"\n %% ncolA = %d"
"\n %% nentA = %d"
"\n %% seed = %d",
argv[0], msglvl, argv[2], type, mode,
nrowA, ncolA, nentA, seed) ;
/*
-----------------------------
check for errors in the input
-----------------------------
*/
if ( nrowA <= 0
|| ncolA <= 0
|| nentA > nrowA*ncolA ) {
fprintf(stderr, "\n invalid input\n") ;
exit(-1) ;
}
/*
--------------------------------------
initialize the random number generator
--------------------------------------
*/
drand = Drand_new() ;
Drand_init(drand) ;
Drand_setSeed(drand, seed) ;
Drand_setNormal(drand, 0.0, 1.0) ;
/*
-----------------------------------
initialize the A matrix SubMtx object
-----------------------------------
*/
mtxA = SubMtx_new() ;
SubMtx_initRandom(mtxA, type, mode, 0, 0, nrowA, ncolA, nentA, seed) ;
SubMtx_rowIndices(mtxA, &nrowA, &rowind) ;
ivtemp = IVinit(nrowA + 5, -1) ;
IVramp(nrowA + 5, ivtemp, 0, 1) ;
IVshuffle(nrowA + 5, ivtemp, ++seed) ;
IVcopy(nrowA, rowind, ivtemp) ;
IVfree(ivtemp) ;
SubMtx_columnIndices(mtxA, &ncolA, &colind) ;
ivtemp = IVinit(ncolA + 5, -1) ;
IVramp(ncolA + 5, ivtemp, 0, 1) ;
IVshuffle(ncolA + 5, ivtemp, ++seed) ;
IVcopy(ncolA, colind, ivtemp) ;
IVfree(ivtemp) ;
SubMtx_writeToFile(mtxA, "temp.submtxb") ;
SubMtx_writeToFile(mtxA, "temp.submtxf") ;
/*
--------------------
print out the matrix
--------------------
*/
if ( msglvl > 1 ) {
fprintf(msgFile, "\n\n %% A SubMtx object") ;
fprintf(msgFile, "\n A = zeros(%d,%d) ;", nrowA+5, ncolA+5) ;
SubMtx_writeForMatlab(mtxA, "A", msgFile) ;
fflush(msgFile) ;
}
switch ( mode ) {
case SUBMTX_DENSE_ROWS :
case SUBMTX_SPARSE_ROWS :
/*
--------------------------------
sort the rows in ascending order
--------------------------------
*/
SubMtx_sortRowsUp(mtxA) ;
break ;
}
switch ( mode ) {
case SUBMTX_DENSE_COLUMNS :
case SUBMTX_SPARSE_COLUMNS :
/*
-----------------------------------
sort the columns in ascending order
-----------------------------------
*/
SubMtx_sortColumnsUp(mtxA) ;
break ;
}
/*
--------------------------
print out the matrix again
--------------------------
*/
if ( msglvl > 1 ) {
fprintf(msgFile, "\n\n %% B SubMtx object") ;
fprintf(msgFile, "\n B = zeros(%d,%d) ;", nrowA+5, ncolA+5) ;
SubMtx_writeForMatlab(mtxA, "B", msgFile) ;
fflush(msgFile) ;
}
/*
-----------------
check with matlab
-----------------
*/
if ( msglvl > 1 ) {
fprintf(msgFile, "\n\n maxabs = max(max(abs(A - B))) ") ;
fflush(msgFile) ;
}
/*
------------------------
free the working storage
------------------------
*/
SubMtx_free(mtxA) ;
Drand_free(drand) ;
fprintf(msgFile, "\n") ;
return(1) ; }
/*--------------------------------------------------------------------*/
|