Changeset 10251
- Timestamp:
- Nov 28, 2006, 4:14:49 PM (19 years ago)
- Location:
- trunk/psLib/src/math
- Files:
-
- 2 edited
-
psMatrix.c (modified) (2 diffs)
-
psMatrix.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMatrix.c
r9538 r10251 21 21 * @author Robert DeSonia, MHPCC 22 22 * 23 * @version $Revision: 1.4 4$ $Name: not supported by cvs2svn $24 * @date $Date: 2006-1 0-13 21:13:48$23 * @version $Revision: 1.45 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2006-11-29 02:14:49 $ 25 25 * 26 26 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 409 409 } 410 410 411 // This is a temporary gauss-jordan solver based on gene's 412 // version based on the Numerical Recipes version 413 bool psMatrixGJSolveF32(psImage *a, 414 psVector *b 415 ) 416 { 417 PS_ASSERT_IMAGE_NON_NULL(a, false); 418 PS_ASSERT_VECTOR_NON_NULL(b, false); 419 PS_ASSERT_IMAGE_TYPE(a, PS_TYPE_F32, false); 420 PS_ASSERT_VECTOR_TYPE(b, PS_TYPE_F32, false); 421 PS_ASSERT_INT_EQUAL(a->numCols, a->numRows, false); 422 int Nx = a->numCols; 423 PS_ASSERT_VECTOR_SIZE(b, (long int)Nx, false); 424 425 psF32 *vector = b->data.F32; 426 psF32 **matrix = a->data.F32; 427 int *indxc = psAlloc(Nx*sizeof(int)); 428 int *indxr = psAlloc(Nx*sizeof(int)); 429 int *ipiv = psAlloc(Nx*sizeof(int)); 430 memset(ipiv, 0, Nx*sizeof(int)); 431 432 int irow = 0; 433 int icol = 0; 434 435 for (int i = 0; i < Nx; i++) { 436 double big = 0.0; 437 for (int j = 0; j < Nx; j++) { 438 if (!isfinite(matrix[i][j])) { 439 psError(PS_ERR_BAD_PARAMETER_VALUE, 3, 440 "Input matrix contains non-finite elements: matrix[%d][%d] is %.2f\n", 441 i, j, matrix[i][j]); 442 goto fescape; 443 } 444 if (ipiv[j] != 1) { 445 for (int k = 0; k < Nx; k++) { 446 if (ipiv[k] == 0) { 447 if (fabs(matrix[j][k]) >= big) { 448 big = fabs(matrix[j][k]); 449 irow = j; 450 icol = k; 451 } 452 } else { 453 if (ipiv[k] > 1) { 454 // psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Singular Matrix (1).\n"); 455 psTrace("psLib.math", 4, "Singular Matrix (1).\n"); 456 goto fescape; 457 } 458 } 459 } 460 } 461 } 462 ipiv[icol]++; 463 if (irow != icol) { 464 for (int l = 0; l < Nx; l++) { 465 PS_SWAP(matrix[irow][l], matrix[icol][l]); 466 } 467 PS_SWAP(vector[irow], vector[icol]); 468 } 469 indxr[i] = irow; 470 indxc[i] = icol; 471 if (matrix[icol][icol] == 0.0) { 472 // psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Singular Matrix (2).\n"); 473 psTrace (__func__, 4, "Singular Matrix (2).\n"); 474 goto fescape; 475 } 476 double pivinv = 1.0 / matrix[icol][icol]; 477 matrix[icol][icol] = 1.0; 478 for (int l = 0; l < Nx; l++) { 479 matrix[icol][l] *= pivinv; 480 } 481 vector[icol] *= pivinv; 482 483 for (int ll = 0; ll < Nx; ll++) { 484 if (ll != icol) { 485 double dum = matrix[ll][icol]; 486 matrix[ll][icol] = 0.0; 487 for (int l = 0; l < Nx; l++) { 488 matrix[ll][l] -= matrix[icol][l]*dum; 489 } 490 vector[ll] -= vector[icol]*dum; 491 } 492 } 493 } 494 495 for (int l = Nx - 1; l >= 0; l--) { 496 if (indxr[l] != indxc[l]) { 497 for (int k = 0; k < Nx; k++) { 498 PS_SWAP(matrix[k][indxr[l]], matrix[k][indxc[l]]); 499 } 500 } 501 } 502 psFree(ipiv); 503 psFree(indxr); 504 psFree(indxc); 505 return true; 506 507 fescape: 508 psFree(ipiv); 509 psFree(indxr); 510 psFree(indxc); 511 return false; 512 } 513 411 514 psImage* psMatrixInvert(psImage* out, 412 515 const psImage* in, -
trunk/psLib/src/math/psMatrix.h
r9545 r10251 21 21 * @author Ross Harman, MHPCC 22 22 * 23 * @version $Revision: 1.2 3$ $Name: not supported by cvs2svn $24 * @date $Date: 2006-1 0-13 22:27:21$23 * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2006-11-29 02:14:49 $ 25 25 * 26 26 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 69 69 */ 70 70 bool psMatrixGJSolve( 71 psImage *A, ///< Matrix to be solved 72 psVector *b ///< Vector of values 73 ); 74 75 /** Gauss-Jordan numerical solver for F32 input data 76 * 77 * @return bool: True if successful. 78 */ 79 bool psMatrixGJSolveF32( 71 80 psImage *A, ///< Matrix to be solved 72 81 psVector *b ///< Vector of values
Note:
See TracChangeset
for help on using the changeset viewer.
