IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 9, 2006, 2:49:38 PM (20 years ago)
Author:
Paul Price
Message:

Renaming psGaussJordan to psMatrixGJSolve, moving function into psMatrix.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMinimizeLMM.c

    r6942 r7102  
    1010 *  @author EAM, IfA
    1111 *
    12  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-04-21 21:18:44 $
     12 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-05-10 00:49:38 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    114114    }
    115115
    116     if (false == psGaussJordan(Alpha, Beta)) {
     116    if (false == psMatrixGJSolve(Alpha, Beta)) {
    117117        psTrace (__func__, 4, "singular matrix in Guess ABP\n");
    118118        return(false);
     
    514514}
    515515
    516 // This is a temporary gauss-jordan solver based on gene's
    517 // version based on the Numerical Recipes version
    518 bool psGaussJordan(
    519     psImage *a,
    520     psVector *b)
    521 {
    522     int *indxc,*indxr,*ipiv;
    523     int Nx, icol, irow;
    524     int i, j, k, l, ll;
    525     float big, dum, pivinv;
    526     psF64 *vector;
    527     psF64 **matrix;
    528 
    529     Nx = a->numCols;
    530     matrix = a->data.F64;
    531     vector = b->data.F64;
    532 
    533     indxc = psAlloc(Nx*sizeof(int));
    534     indxr = psAlloc(Nx*sizeof(int));
    535     ipiv  = psAlloc(Nx*sizeof(int));
    536     for (j = 0; j < Nx; j++) {
    537         ipiv[j] = 0;
    538     }
    539 
    540     irow = icol = 0;
    541     big = fabs(matrix[0][0]);
    542 
    543     for (i = 0; i < Nx; i++) {
    544         big = 0.0;
    545         for (j = 0; j < Nx; j++) {
    546             if (!isfinite(matrix[i][j])) {
    547                 psTrace (__func__, 3, "Input matrix contains NaNs: matrix[%d][%d] is %.2f\n", i, j, matrix[i][j]);
    548                 goto fescape;
    549             }
    550             if (ipiv[j] != 1) {
    551                 for (k = 0; k < Nx; k++) {
    552                     if (ipiv[k] == 0) {
    553                         if (fabs (matrix[j][k]) >= big) {
    554                             big  = fabs(matrix[j][k]);
    555                             irow = j;
    556                             icol = k;
    557                         }
    558                     } else {
    559                         if (ipiv[k] > 1) {
    560                             psTrace (__func__, 3, "Singular Matrix (1).\n");
    561                             goto fescape;
    562                         }
    563                     }
    564                 }
    565             }
    566         }
    567         ipiv[icol]++;
    568         if (irow != icol) {
    569             for (l = 0; l < Nx; l++) {
    570                 PS_SWAP(matrix[irow][l], matrix[icol][l]);
    571             }
    572             PS_SWAP(vector[irow], vector[icol]);
    573         }
    574         indxr[i] = irow;
    575         indxc[i] = icol;
    576         if (matrix[icol][icol] == 0.0) {
    577             psTrace (__func__, 3, "Singular Matrix (2).\n");
    578             goto fescape;
    579         }
    580         pivinv = 1.0 / matrix[icol][icol];
    581         matrix[icol][icol] = 1.0;
    582         for (l = 0; l < Nx; l++) {
    583             matrix[icol][l] *= pivinv;
    584         }
    585         vector[icol] *= pivinv;
    586 
    587         for (ll = 0; ll < Nx; ll++) {
    588             if (ll != icol) {
    589                 dum = matrix[ll][icol];
    590                 matrix[ll][icol] = 0.0;
    591                 for (l = 0; l < Nx; l++) {
    592                     matrix[ll][l] -= matrix[icol][l]*dum;
    593                 }
    594                 vector[ll] -= vector[icol]*dum;
    595             }
    596         }
    597     }
    598 
    599     for (l = Nx - 1; l >= 0; l--) {
    600         if (indxr[l] != indxc[l]) {
    601             for (k = 0; k < Nx; k++) {
    602                 PS_SWAP(matrix[k][indxr[l]], matrix[k][indxc[l]]);
    603             }
    604         }
    605     }
    606     psFree(ipiv);
    607     psFree(indxr);
    608     psFree(indxc);
    609     return(true);
    610 
    611 fescape:
    612     psFree(ipiv);
    613     psFree(indxr);
    614     psFree(indxc);
    615     return(false);
    616 }
    617 
    618516static void minimizationFree(psMinimization *min)
    619517{
Note: See TracChangeset for help on using the changeset viewer.