Changeset 4321 for trunk/psLib/src/dataManip/psMatrix.c
- Timestamp:
- Jun 20, 2005, 12:42:30 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/dataManip/psMatrix.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMatrix.c
r4160 r4321 21 21 * @author Robert DeSonia, MHPCC 22 22 * 23 * @version $Revision: 1.3 1$ $Name: not supported by cvs2svn $24 * @date $Date: 2005-06- 08 22:28:07$23 * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2005-06-20 22:42:29 $ 25 25 * 26 26 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 191 191 psS32 numCols = 0; 192 192 gsl_matrix *lu = NULL; 193 gsl_permutation perm ;193 gsl_permutation permGSL; 194 194 195 195 … … 212 212 213 213 // Initialize GSL data 214 perm .size = numCols;214 permGSL.size = numCols; 215 215 if (sizeof(size_t) == 4) { 216 216 *outPerm = psVectorRecycle(*outPerm, numCols, PS_TYPE_S32); … … 225 225 226 226 (*outPerm)->n = numCols; 227 perm .data = (psPtr)((*outPerm)->data.U8);227 permGSL.data = (psPtr)((*outPerm)->data.U8); 228 228 lu = gsl_matrix_alloc(numRows, numCols); 229 229 … … 232 232 233 233 // Calculate LU decomposition 234 gsl_linalg_LU_decomp(lu, &perm , &signum); // N.B., uses Gaussian Elimination with partial pivoting.234 gsl_linalg_LU_decomp(lu, &permGSL, &signum); // N.B., uses Gaussian Elimination with partial pivoting. 235 235 236 236 // Copy GSL matrix data to psImage data … … 298 298 } 299 299 300 psImage* psMatrixInvert(psImage* outImage, const psImage* inImage, psF32*det)300 psImage* psMatrixInvert(psImage* outImage, const psImage* inImage, float *det) 301 301 { 302 302 psS32 signum = 0; … … 346 346 } 347 347 348 psF32 *psMatrixDeterminant(const psImage* inImage)348 float *psMatrixDeterminant(const psImage* in) 349 349 { 350 350 psS32 signum = 0; … … 357 357 #define DETERMINANT_EXIT { return NULL; } 358 358 // Error checks 359 PS_ASSERT_GENERAL_IMAGE_NON_NULL(in Image, DETERMINANT_EXIT);360 PS_CHECK_DIMEN_AND_TYPE(in Image, PS_DIMEN_IMAGE, DETERMINANT_EXIT);361 PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(in Image, DETERMINANT_EXIT);362 PS_CHECK_SQUARE(in Image, DETERMINANT_EXIT);359 PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, DETERMINANT_EXIT); 360 PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, DETERMINANT_EXIT); 361 PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(in, DETERMINANT_EXIT); 362 PS_CHECK_SQUARE(in, DETERMINANT_EXIT); 363 363 364 364 // Initialize data 365 numRows = in Image->numRows;366 numCols = in Image->numCols;365 numRows = in->numRows; 366 numCols = in->numCols; 367 367 368 368 // Allocate GSL structs 369 369 perm = gsl_permutation_alloc(numRows); 370 370 lu = gsl_matrix_alloc(numRows, numCols); 371 psImageToGslMatrix(lu, in Image);371 psImageToGslMatrix(lu, in); 372 372 373 373 // Calculate determinant … … 480 480 } 481 481 482 psImage* psMatrixEigenvectors(psImage* out Image, psImage* inImage)482 psImage* psMatrixEigenvectors(psImage* out, psImage* in) 483 483 { 484 484 psS32 numRows = 0; … … 486 486 gsl_vector *eVals = NULL; 487 487 gsl_eigen_symmv_workspace *w = NULL; 488 gsl_matrix *out = NULL;489 gsl_matrix *in = NULL;490 491 #define EIGENVECTORS_CLEANUP { psFree(out Image); return NULL; }492 // Error checks 493 PS_ASSERT_GENERAL_IMAGE_NON_NULL(in Image, EIGENVECTORS_CLEANUP);494 PS_CHECK_DIMEN_AND_TYPE(in Image, PS_DIMEN_IMAGE, EIGENVECTORS_CLEANUP);495 PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(in Image, EIGENVECTORS_CLEANUP);496 PS_CHECK_POINTERS(in Image, outImage, EIGENVECTORS_CLEANUP);497 498 out Image = psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);488 gsl_matrix *outGSL = NULL; 489 gsl_matrix *inGSL = NULL; 490 491 #define EIGENVECTORS_CLEANUP { psFree(out); return NULL; } 492 // Error checks 493 PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, EIGENVECTORS_CLEANUP); 494 PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, EIGENVECTORS_CLEANUP); 495 PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(in, EIGENVECTORS_CLEANUP); 496 PS_CHECK_POINTERS(in, out, EIGENVECTORS_CLEANUP); 497 498 out = psImageRecycle(out, in->numCols, in->numRows, in->type.type); 499 499 500 500 // Initialize data 501 numRows = in Image->numRows;502 numCols = in Image->numCols;503 504 in = gsl_matrix_alloc(numRows, numCols);505 psImageToGslMatrix(in , inImage);506 out = gsl_matrix_alloc(numRows, numCols);501 numRows = in->numRows; 502 numCols = in->numCols; 503 504 inGSL = gsl_matrix_alloc(numRows, numCols); 505 psImageToGslMatrix(inGSL, in); 506 outGSL = gsl_matrix_alloc(numRows, numCols); 507 507 508 508 // Allocate GSL structs … … 511 511 512 512 // Non-square matrices not allowed 513 PS_CHECK_SQUARE(in Image, EIGENVECTORS_CLEANUP);514 PS_CHECK_SQUARE(out Image, EIGENVECTORS_CLEANUP);513 PS_CHECK_SQUARE(in, EIGENVECTORS_CLEANUP); 514 PS_CHECK_SQUARE(out, EIGENVECTORS_CLEANUP); 515 515 516 516 // Calculate Eigenvalues and Eigenvectors...Eigenvalues not currently used 517 gsl_eigen_symmv(in , eVals, out, w);517 gsl_eigen_symmv(inGSL, eVals, outGSL, w); 518 518 519 519 // Copy GSL matrix data to psImage data 520 gslMatrixToPsImage(out Image, out);520 gslMatrixToPsImage(out, outGSL); 521 521 522 522 // Free GSL structs 523 gsl_matrix_free(in );524 gsl_matrix_free(out );523 gsl_matrix_free(inGSL); 524 gsl_matrix_free(outGSL); 525 525 gsl_eigen_symmv_free(w); 526 526 gsl_vector_free(eVals); 527 527 528 return out Image;528 return out; 529 529 } 530 530
Note:
See TracChangeset
for help on using the changeset viewer.
