Changeset 908 for trunk/psLib/src/math/psMatrix.c
- Timestamp:
- Jun 7, 2004, 3:58:03 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMatrix.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMatrix.c
r878 r908 20 20 * @author Ross Harman, MHPCC 21 21 * 22 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $23 * @date $Date: 2004-06-0 4 23:49:59$22 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2004-06-08 01:57:52 $ 24 24 * 25 25 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 #include <gsl/gsl_eigen.h> 36 36 37 #include "psMemory.h" 37 38 #include "psError.h" 38 39 #include "psImage.h" … … 253 254 254 255 // Error checks 256 if(det == NULL) { 257 psError(__func__, "Invalid operation: determinant argument is NULL."); 258 return outImage; 259 } 255 260 PS_CHECK_POINTERS(inImage, outImage, outImage); 256 261 PS_CHECK_NULL_IMAGE(inImage, outImage); … … 292 297 } 293 298 294 float psMatrixDeterminant(const psImage *restrict inImage)299 float* psMatrixDeterminant(const psImage *restrict inImage) 295 300 { 296 301 int signum = 0; … … 298 303 int numRows = 0; 299 304 int numCols = 0; 300 float det = 0.0f;305 float *det = NULL; 301 306 gsl_matrix *lu = NULL; 302 307 gsl_permutation *perm = NULL; 303 308 304 309 // Error checks 305 PS_CHECK_NULL_IMAGE(inImage, 0);306 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, 0);307 PS_CHECK_SIZE_IMAGE(inImage, 0);310 PS_CHECK_NULL_IMAGE(inImage, NULL); 311 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL); 312 PS_CHECK_SIZE_IMAGE(inImage, NULL); 308 313 309 314 // Initialize data … … 323 328 324 329 // Calculate determinant 330 det = (float*)psAlloc(sizeof(float)); 325 331 gsl_linalg_LU_decomp(lu, perm, &signum); 326 det = (float)gsl_linalg_LU_det(lu, signum);332 *det = (float)gsl_linalg_LU_det(lu, signum); 327 333 328 334 // Free GSL structs … … 458 464 psVector *psMatrixToVector(psVector *outVector, psImage *inImage) 459 465 { 460 int colSize = 0;466 int size = 0; 461 467 462 468 // Error checks … … 464 470 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector); 465 471 PS_CHECK_SIZE_IMAGE(inImage, outVector); 466 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type); 467 PS_CHECK_NULL_VECTOR(outVector, outVector); 468 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector); 469 470 // Set n if allocated, but empty 471 if(outVector->n == 0) { 472 outVector->n = inImage->numRows; 473 } 474 475 // More checks 476 if(inImage->numCols > 1) { 477 psError(__func__, "Image has more than 1 column: numCols = %d.", inImage->numCols); 478 return outVector; 479 } else if(outVector->n != inImage->numRows) { 480 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n); 472 473 if(inImage->numRows == 1) { 474 // Create transposed row vector 475 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type); 476 outVector->type.dimen = PS_DIMEN_TRANSV; 477 } else if(inImage->numCols == 1) { 478 // Create non-transposed column vector 479 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type); 480 } else { 481 psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows, 482 inImage->numCols); 481 483 return outVector; 482 484 } 483 485 484 colSize = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows; 485 memcpy(outVector->data.V, inImage->data.V[0], colSize); 486 PS_CHECK_NULL_VECTOR(outVector, outVector); 487 488 489 // More checks 490 if(outVector->type.dimen == PS_DIMEN_VECTOR) { 491 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector); 492 493 if(outVector->n == 0) { 494 outVector->n = inImage->numRows; 495 } 496 497 if(outVector->n != inImage->numRows) { 498 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n); 499 return outVector; 500 } 501 502 size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows; 503 504 } else if(outVector->type.dimen == PS_DIMEN_TRANSV) { 505 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_TRANSV, outVector); 506 507 if(outVector->n == 0) { 508 outVector->n = inImage->numCols; 509 } 510 511 if(outVector->n != inImage->numCols) { 512 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n); 513 return outVector; 514 } 515 516 size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numCols; 517 } 518 519 memcpy(outVector->data.V, inImage->data.V[0], size); 486 520 487 521 return outVector; … … 490 524 psImage *psVectorToMatrix(psImage *outImage, psVector *inVector) 491 525 { 492 int colSize = 0;526 int size = 0; 493 527 494 528 // Error checks 495 529 PS_CHECK_NULL_VECTOR(inVector, outImage); 496 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage); 497 PS_CHECK_SIZE_VECTOR(inVector, outImage); 498 PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F32) 530 531 if(inVector->type.dimen == PS_DIMEN_VECTOR) { 532 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage); 533 PS_CHECK_SIZE_VECTOR(inVector, outImage); 534 PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64) 535 536 // More checks for PS_DIMEN_VECTOR 537 if(outImage->numCols > 1) { 538 psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols); 539 return outImage; 540 } else if(outImage->numRows != inVector->n) { 541 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n); 542 return outImage; 543 } 544 545 size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows; 546 547 } else if(inVector->type.dimen == PS_DIMEN_TRANSV) { 548 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage); 549 PS_CHECK_SIZE_VECTOR(inVector, outImage); 550 PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64) 551 552 // More checks for PS_DIMEN_TRANSV 553 if(outImage->numRows > 1) { 554 psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows); 555 return outImage; 556 } else if(outImage->numCols != inVector->n) { 557 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n); 558 return outImage; 559 } 560 561 size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numCols; 562 } 563 499 564 PS_CHECK_NULL_IMAGE(outImage, outImage); 500 565 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 501 566 502 // More checks 503 if(outImage->numCols > 1) { 504 psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols); 505 return outImage; 506 } else if(outImage->numRows != inVector->n) { 507 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n); 508 return outImage; 509 } 510 511 colSize = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows; 512 memcpy(outImage->data.V[0], inVector->data.V, colSize); 567 memcpy(outImage->data.V[0], inVector->data.V, size); 513 568 514 569 return outImage;
Note:
See TracChangeset
for help on using the changeset viewer.
