Changeset 16120
- Timestamp:
- Jan 17, 2008, 1:22:28 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libohana/src/gaussj.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/src/gaussj.c
r16112 r16120 11 11 int *rowIndex; 12 12 int *pivot; 13 int maxcol, maxrow;14 double maxval, tmpval;15 13 16 14 int diag, col, row; … … 21 19 memset (pivot, 0, N*sizeof(int)); 22 20 23 // init these so gcc does not complain 24 maxval = 0.0; 25 maxrow = maxcol = 0; 26 27 // we loop along the matrix diagonal, but we do not operate on the diagonal elements in 28 // order instead, we are looking for the current max element and operating on that 29 // diagonal element. this is effectively column pivoting. row pivoting is perfomed 30 // explicitly 21 // determine underflow conditions 22 // double underFlow = DBL_MIN; 23 # if (0) 24 double roundTest = 4.0; 25 roundTest /= 3.0; 26 roundTest -= 1.0; 27 double epsilon = fabs(((roundTest+roundTest) - 1.0) + roundTest); 28 double growth = 1.0; 29 # endif 30 31 // Following the algorithm laid out by Press et al., we loop along the matrix diagonal, 32 // but we do not operate on the diagonal elements in order instead, we are looking for 33 // the current max element and operating on that diagonal element. this is effectively 34 // column pivoting. row pivoting is perfomed explicitly. 31 35 32 36 for (diag = 0; diag < N; diag++) { 33 37 34 maxval = 0.0; 38 double maxval = 0.0; 39 int maxrow = 0; 40 int maxcol = 0; 35 41 36 42 // search for the next pivot … … 63 69 colIndex[diag] = maxcol; 64 70 if (A[maxcol][maxcol] == 0.0) goto escape; 71 // XXX Kahan replaces the 0.0 pivot with epsilon*(largest element in column) + underFlow 65 72 66 73 /* rescale by pivot reciprocal */ 67 tmpval = 1.0 / A[maxcol][maxcol];74 double tmpval = 1.0 / A[maxcol][maxcol]; 68 75 A[maxcol][maxcol] = 1.0; 69 76 for (col = 0; col < N; col++) A[maxcol][col] *= tmpval; 70 77 for (col = 0; col < M; col++) B[maxcol][col] *= tmpval; 78 // XXX measure the pivot growth and trigger on over/under flow 79 // growth *= tmpval; 80 // fprintf (stderr, "column: %d, growth: %e, epsilon: %e\n", maxcol, growth, epsilon); 71 81 72 82 /* adjust the elements above the pivot */ … … 111 121 ALLOCATE (pivot, int, N); 112 122 memset (pivot, 0, N*sizeof(int)); 123 124 // determine underflow conditions 125 // float underFlow = FLT_MIN; 126 # if (0) 127 float roundTest = 4.0; 128 roundTest /= 3.0; 129 roundTest -= 1.0; 130 float epsilon = fabs(((roundTest+roundTest) - 1.0) + roundTest); 131 float growth = 1.0; 132 # endif 113 133 114 134 // we loop along the matrix diagonal, but we do not operate on the diagonal elements in … … 152 172 colIndex[diag] = maxcol; 153 173 if (A[maxcol][maxcol] == 0.0) goto escape; 174 // XXX Kahan replaces the 0.0 pivot with epsilon*(largest element in column) + underFlow 154 175 155 176 /* rescale by pivot reciprocal */ … … 158 179 for (col = 0; col < N; col++) A[maxcol][col] *= tmpval; 159 180 for (col = 0; col < M; col++) B[maxcol][col] *= tmpval; 181 // growth *= tmpval; 182 // fprintf (stderr, "column: %d, growth: %e, epsilon: %e\n", maxcol, growth, epsilon); 160 183 161 184 /* adjust the elements above the pivot */
Note:
See TracChangeset
for help on using the changeset viewer.
