Changeset 1407 for trunk/psLib/src/math/psMatrix.c
- Timestamp:
- Aug 6, 2004, 2:06:06 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMatrix.c (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMatrix.c
r1406 r1407 1 1 2 /** @file psMatrix.c 2 3 * … … 20 21 * @author Ross Harman, MHPCC 21 22 * 22 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $23 * @date $Date: 2004-08-0 6 22:34:05$23 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2004-08-07 00:06:06 $ 24 25 * 25 26 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 28 28 29 /******************************************************************************/ 30 29 31 /* INCLUDE FILES */ 32 30 33 /******************************************************************************/ 31 34 #include <string.h> … … 42 45 43 46 /******************************************************************************/ 47 44 48 /* DEFINE STATEMENTS */ 49 45 50 /******************************************************************************/ 46 51 … … 48 53 49 54 /******************************************************************************/ 55 50 56 /* TYPE DEFINITIONS */ 57 51 58 /******************************************************************************/ 52 59 … … 54 61 55 62 /*****************************************************************************/ 63 56 64 /* GLOBAL VARIABLES */ 65 57 66 /*****************************************************************************/ 58 67 … … 60 69 61 70 /*****************************************************************************/ 71 62 72 /* FILE STATIC VARIABLES */ 73 63 74 /*****************************************************************************/ 64 75 … … 66 77 67 78 /*****************************************************************************/ 79 68 80 /* FUNCTION IMPLEMENTATION - LOCAL */ 81 69 82 /*****************************************************************************/ 70 83 … … 142 155 143 156 /*****************************************************************************/ 157 144 158 /* FUNCTION IMPLEMENTATION - PUBLIC */ 145 /*****************************************************************************/ 146 147 psImage *psMatrixLUD(psImage *outImage, psVector *outPerm, psImage *inImage) 159 160 /*****************************************************************************/ 161 162 psImage *psMatrixLUD(psImage * outImage, psVector * outPerm, psImage * inImage) 148 163 { 149 164 int signum = 0; … … 169 184 numRows = inImage->numRows; 170 185 numCols = inImage->numCols; 171 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) *numRows*numCols;186 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) * numRows * numCols; 172 187 173 188 // Initialize GSL data … … 190 205 } 191 206 192 psVector *psMatrixLUSolve(psVector * outVector, const psImage *inImage, const psVector *inVector, const193 psVector * inPerm)207 psVector *psMatrixLUSolve(psVector * outVector, const psImage * inImage, const psVector * inVector, const 208 psVector * inPerm) 194 209 { 195 210 int arraySize = 0; … … 219 234 numRows = inImage->numRows; 220 235 numCols = inImage->numCols; 221 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) *numRows*numCols;236 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) * numRows * numCols; 222 237 223 238 // Initialize GSL data … … 243 258 } 244 259 245 psImage *psMatrixInvert(psImage * outImage, const psImage *inImage, float *restrict det)260 psImage *psMatrixInvert(psImage * outImage, const psImage * inImage, float *restrict det) 246 261 { 247 262 int signum = 0; … … 254 269 255 270 // Error checks 256 if (det == NULL) {271 if (det == NULL) { 257 272 psError(__func__, "Invalid operation: determinant argument is NULL."); 258 273 return outImage; … … 269 284 numRows = inImage->numRows; 270 285 numCols = inImage->numCols; 271 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) *numRows*numCols;286 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) * numRows * numCols; 272 287 273 288 // Allocate GSL structs … … 297 312 } 298 313 299 float * psMatrixDeterminant(const psImage *restrict inImage)314 float *psMatrixDeterminant(const psImage * restrict inImage) 300 315 { 301 316 int signum = 0; … … 315 330 numRows = inImage->numRows; 316 331 numCols = inImage->numCols; 317 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) *numRows*numCols;332 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) * numRows * numCols; 318 333 319 334 // Allocate GSL structs … … 328 343 329 344 // Calculate determinant 330 det = (float *)psAlloc(sizeof(float));345 det = (float *)psAlloc(sizeof(float)); 331 346 gsl_linalg_LU_decomp(lu, perm, &signum); 332 347 *det = (float)gsl_linalg_LU_det(lu, signum); … … 339 354 } 340 355 341 psImage * psMatrixMultiply(psImage *outImage, psImage *inImage1, psImage *inImage2)356 psImage *psMatrixMultiply(psImage * outImage, psImage * inImage1, psImage * inImage2) 342 357 { 343 358 int arraySize = 0; … … 364 379 numRows = inImage1->numRows; 365 380 numCols = inImage1->numCols; 366 arraySize = PSELEMTYPE_SIZEOF(outImage->type.type) *numRows*numCols;381 arraySize = PSELEMTYPE_SIZEOF(outImage->type.type) * numRows * numCols; 367 382 368 383 // Initialize GSL data … … 381 396 } 382 397 383 psImage * psMatrixTranspose(psImage *outImage, const psImage *inImage)398 psImage *psMatrixTranspose(psImage * outImage, const psImage * inImage) 384 399 { 385 400 int arraySize = 0; … … 400 415 numRows = inImage->numRows; 401 416 numCols = inImage->numCols; 402 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) *numRows*numCols;417 arraySize = PSELEMTYPE_SIZEOF(inImage->type.type) * numRows * numCols; 403 418 404 419 // Initialize GSL data … … 418 433 } 419 434 420 psImage *psMatrixEigenvectors(psImage * outImage, psImage *inImage)435 psImage *psMatrixEigenvectors(psImage * outImage, psImage * inImage) 421 436 { 422 437 int numRows = 0; … … 462 477 } 463 478 464 psVector *psMatrixToVector(psVector * outVector, psImage *inImage)479 psVector *psMatrixToVector(psVector * outVector, psImage * inImage) 465 480 { 466 481 int size = 0; … … 471 486 PS_CHECK_SIZE_IMAGE(inImage, outVector); 472 487 473 if (inImage->numRows == 1) {488 if (inImage->numRows == 1) { 474 489 // Create transposed row vector 475 490 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type); 476 491 outVector->type.dimen = PS_DIMEN_TRANSV; 477 } else 478 if(inImage->numCols == 1) { 479 // Create non-transposed column vector 480 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type); 481 } else { 482 psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows, 483 inImage->numCols); 484 return outVector; 485 } 492 } else if (inImage->numCols == 1) { 493 // Create non-transposed column vector 494 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type); 495 } else { 496 psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows, 497 inImage->numCols); 498 return outVector; 499 } 486 500 487 501 PS_CHECK_NULL_VECTOR(outVector, outVector); 488 502 489 490 503 // More checks 491 if (outVector->type.dimen == PS_DIMEN_VECTOR) {504 if (outVector->type.dimen == PS_DIMEN_VECTOR) { 492 505 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector); 493 506 494 if (outVector->n == 0) {507 if (outVector->n == 0) { 495 508 outVector->n = inImage->numRows; 496 509 } 497 510 498 if (outVector->n != inImage->numRows) {511 if (outVector->n != inImage->numRows) { 499 512 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n); 500 513 return outVector; 501 514 } 502 515 503 size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows; 504 505 } else 506 if(outVector->type.dimen == PS_DIMEN_TRANSV) { 507 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_TRANSV, outVector); 508 509 if(outVector->n == 0) { 510 outVector->n = inImage->numCols; 511 } 512 513 if(outVector->n != inImage->numCols) { 514 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n); 515 return outVector; 516 } 517 518 size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numCols; 516 size = PSELEMTYPE_SIZEOF(inImage->type.type) * inImage->numRows; 517 518 } else if (outVector->type.dimen == PS_DIMEN_TRANSV) { 519 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_TRANSV, outVector); 520 521 if (outVector->n == 0) { 522 outVector->n = inImage->numCols; 519 523 } 520 524 525 if (outVector->n != inImage->numCols) { 526 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n); 527 return outVector; 528 } 529 530 size = PSELEMTYPE_SIZEOF(inImage->type.type) * inImage->numCols; 531 } 532 521 533 memcpy(outVector->data.V, inImage->data.V[0], size); 522 534 … … 524 536 } 525 537 526 psImage *psVectorToMatrix(psImage * outImage, psVector *inVector)538 psImage *psVectorToMatrix(psImage * outImage, psVector * inVector) 527 539 { 528 540 int size = 0; … … 531 543 PS_CHECK_NULL_VECTOR(inVector, outImage); 532 544 533 if (inVector->type.dimen == PS_DIMEN_VECTOR) {545 if (inVector->type.dimen == PS_DIMEN_VECTOR) { 534 546 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage); 535 547 PS_CHECK_SIZE_VECTOR(inVector, outImage); 536 548 PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64) 537 538 549 // More checks for PS_DIMEN_VECTOR 539 if (outImage->numCols > 1) {550 if (outImage->numCols > 1) { 540 551 psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols); 541 552 return outImage; 542 } else 543 if(outImage->numRows != inVector->n) { 544 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n); 545 return outImage; 546 } 547 548 size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows; 549 550 } else 551 if(inVector->type.dimen == PS_DIMEN_TRANSV) { 552 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage); 553 PS_CHECK_SIZE_VECTOR(inVector, outImage); 554 PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64) 555 556 // More checks for PS_DIMEN_TRANSV 557 if(outImage->numRows > 1) { 558 psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows); 559 return outImage; 560 } else 561 if(outImage->numCols != inVector->n) { 562 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n); 563 return outImage; 564 } 565 566 size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numCols; 553 } else if (outImage->numRows != inVector->n) { 554 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n); 555 return outImage; 567 556 } 557 558 size = PSELEMTYPE_SIZEOF(outImage->type.type) * outImage->numRows; 559 560 } else if (inVector->type.dimen == PS_DIMEN_TRANSV) { 561 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage); 562 PS_CHECK_SIZE_VECTOR(inVector, outImage); 563 PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64) 564 // More checks for PS_DIMEN_TRANSV 565 if (outImage->numRows > 1) { 566 psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows); 567 return outImage; 568 } else if (outImage->numCols != inVector->n) { 569 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n); 570 return outImage; 571 } 572 573 size = PSELEMTYPE_SIZEOF(outImage->type.type) * outImage->numCols; 574 } 568 575 569 576 PS_CHECK_NULL_IMAGE(outImage, outImage); … … 574 581 return outImage; 575 582 } 576
Note:
See TracChangeset
for help on using the changeset viewer.
