IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16120


Ignore:
Timestamp:
Jan 17, 2008, 1:22:28 PM (18 years ago)
Author:
eugene
Message:

some cleanups; test overflow code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/src/gaussj.c

    r16112 r16120  
    1111  int *rowIndex;
    1212  int *pivot;
    13   int maxcol, maxrow;
    14   double maxval, tmpval;
    1513 
    1614  int diag, col, row;
     
    2119  memset (pivot, 0, N*sizeof(int));
    2220
    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. 
    3135
    3236  for (diag = 0; diag < N; diag++) {
    3337
    34     maxval = 0.0;
     38    double maxval = 0.0;
     39    int maxrow = 0;
     40    int maxcol = 0;
    3541
    3642    // search for the next pivot
     
    6369    colIndex[diag] = maxcol;
    6470    if (A[maxcol][maxcol] == 0.0) goto escape;
     71    // XXX Kahan replaces the 0.0 pivot with epsilon*(largest element in column) + underFlow
    6572
    6673    /* rescale by pivot reciprocal */
    67     tmpval = 1.0 / A[maxcol][maxcol];
     74    double tmpval = 1.0 / A[maxcol][maxcol];
    6875    A[maxcol][maxcol] = 1.0;
    6976    for (col = 0; col < N; col++) A[maxcol][col] *= tmpval;
    7077    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);
    7181
    7282    /* adjust the elements above the pivot */
     
    111121  ALLOCATE (pivot, int, N);
    112122  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
    113133
    114134  // we loop along the matrix diagonal, but we do not operate on the diagonal elements in
     
    152172    colIndex[diag] = maxcol;
    153173    if (A[maxcol][maxcol] == 0.0) goto escape;
     174    // XXX Kahan replaces the 0.0 pivot with epsilon*(largest element in column) + underFlow
    154175
    155176    /* rescale by pivot reciprocal */
     
    158179    for (col = 0; col < N; col++) A[maxcol][col] *= tmpval;
    159180    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);
    160183
    161184    /* adjust the elements above the pivot */
Note: See TracChangeset for help on using the changeset viewer.