Changeset 908
- Timestamp:
- Jun 7, 2004, 3:58:03 PM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 1 added
- 6 edited
-
src/dataManip/psMatrix.c (modified) (9 diffs)
-
src/dataManip/psMatrix.h (modified) (5 diffs)
-
src/math/psMatrix.c (modified) (9 diffs)
-
src/math/psMatrix.h (modified) (5 diffs)
-
test/dataManip/tst_psMatrix07.c (modified) (7 diffs)
-
test/dataManip/verified/tst_psMatrix07.stderr (added)
-
test/dataManip/verified/tst_psMatrix07.stdout (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/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; -
trunk/psLib/src/dataManip/psMatrix.h
r807 r908 9 9 * Matrix inversion 10 10 * Calculate determinant 11 * Matrix addition12 * Matrix subtraction13 11 * Matrix multiplication 14 12 * Calculate Eigenvectors … … 17 15 * 18 16 * These functions treat psImages as if they were matrices, therefore there is no psMatrix. These functions 19 * operate only with psF32 and psF64 data types.17 * operate only with the psF64 data type. 20 18 * 21 19 * @author Ross Harman, MHPCC 22 20 * 23 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $24 * @date $Date: 2004-0 5-28 20:52:41$21 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-06-08 01:58:03 $ 25 23 * 26 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 100 98 * @return float: Determinant from psImage. 101 99 */ 102 float psMatrixDeterminant(100 float* psMatrixDeterminant( 103 101 const psImage *restrict inMatrix ///< Image used to calculate determinant. 104 102 ); … … 149 147 * 150 148 * Converts a 1-d psImage matrix into a vector. If the user specifies NULL as the outVector argument, then it 151 * will automatically be created. The input matrix must be a 1-d column matrix. This function operates only 152 * with the psF64 data type. 149 * will automatically be created based on the input image (PS_DIMEN_VECTOR for an input image with 1 col or 150 * PS_DIMENT_TRANSV for an input image with 1 row). Either the number of rows or the number of colums of the 151 * input matrix must be 1. This function operates only with the psF64 data type. 153 152 * 154 153 * @return psVector*: Pointer to psVector. … … 161 160 /** Convert vector to matrix. 162 161 * 163 * Converts a vector into a 1-d column psImage matrix. If the user specifies NULL as the outImage argument, 164 * then it will automatically be created. This function operates only with the psF64 data type. 162 * Converts a vector into a psImage matrix. If the dimensionality of the vector is PS_DIMEN_VECTOR, then the 163 * resulting psImage is a 1d column. If the dimensionality of the vector is PS_DIMEN_TRANSV, then the 164 * resulting psImage is a 1d row. If the user specifies NULL as the outImage argument, then it will 165 * automatically be created. This function operates only with the psF64 data type. 165 166 * 166 167 * @return psVector*: Pointer to psIamge. -
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; -
trunk/psLib/src/math/psMatrix.h
r807 r908 9 9 * Matrix inversion 10 10 * Calculate determinant 11 * Matrix addition12 * Matrix subtraction13 11 * Matrix multiplication 14 12 * Calculate Eigenvectors … … 17 15 * 18 16 * These functions treat psImages as if they were matrices, therefore there is no psMatrix. These functions 19 * operate only with psF32 and psF64 data types.17 * operate only with the psF64 data type. 20 18 * 21 19 * @author Ross Harman, MHPCC 22 20 * 23 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $24 * @date $Date: 2004-0 5-28 20:52:41$21 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-06-08 01:58:03 $ 25 23 * 26 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 100 98 * @return float: Determinant from psImage. 101 99 */ 102 float psMatrixDeterminant(100 float* psMatrixDeterminant( 103 101 const psImage *restrict inMatrix ///< Image used to calculate determinant. 104 102 ); … … 149 147 * 150 148 * Converts a 1-d psImage matrix into a vector. If the user specifies NULL as the outVector argument, then it 151 * will automatically be created. The input matrix must be a 1-d column matrix. This function operates only 152 * with the psF64 data type. 149 * will automatically be created based on the input image (PS_DIMEN_VECTOR for an input image with 1 col or 150 * PS_DIMENT_TRANSV for an input image with 1 row). Either the number of rows or the number of colums of the 151 * input matrix must be 1. This function operates only with the psF64 data type. 153 152 * 154 153 * @return psVector*: Pointer to psVector. … … 161 160 /** Convert vector to matrix. 162 161 * 163 * Converts a vector into a 1-d column psImage matrix. If the user specifies NULL as the outImage argument, 164 * then it will automatically be created. This function operates only with the psF64 data type. 162 * Converts a vector into a psImage matrix. If the dimensionality of the vector is PS_DIMEN_VECTOR, then the 163 * resulting psImage is a 1d column. If the dimensionality of the vector is PS_DIMEN_TRANSV, then the 164 * resulting psImage is a 1d row. If the user specifies NULL as the outImage argument, then it will 165 * automatically be created. This function operates only with the psF64 data type. 165 166 * 166 167 * @return psVector*: Pointer to psIamge. -
trunk/psLib/test/dataManip/tst_psMatrix07.c
r831 r908 5 5 * This test driver contains the following tests for psMatrix test point 7: 6 6 * A) Create input and output images and vectors 7 * B) Convert matrix to vector 8 * C) Convert vector to matrix 9 * D) Free input and output images and vectors 7 * B) Convert matrix to PS_DIMEN_VECTOR vector 8 * C) Attempt to use null image input argument 9 * D) Convert matrix to PS_DIMEN_TRANSV vector 10 * E) Improper image size 11 * F) Convert PS_DIMEN_VECTOR vector to matrix 12 * G) Attempt to use null input vector argument 13 * H) Convert PS_DIMEN_TRANSV vector to matrix 14 * I) Free input and output images and vectors 10 15 * 11 16 * @author Ross Harman, MHPCC 12 17 * 13 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-06-0 2 23:29:39$18 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 19 * @date $Date: 2004-06-08 01:56:35 $ 15 20 * 16 21 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 27 23 28 #define PRINT_MATRIX(IMAGE) \ 24 for(int i=0; i<IMAGE->numRows; i++) { \25 for(int j=0; j<IMAGE->numCols; j++) { \26 printf("%f ", IMAGE->data.F64[i][j]); \27 } \28 printf("\n"); \29 for(int i=0; i<IMAGE->numRows; i++) { \ 30 for(int j=0; j<IMAGE->numCols; j++) { \ 31 printf("%f ", IMAGE->data.F64[i][j]); \ 32 } \ 33 printf("\n"); \ 29 34 } 30 35 31 36 #define PRINT_VECTOR(VECTOR) \ 32 for(int i=0; i<VECTOR->n; i++) { \33 printf("%f\n", VECTOR->data.F64[i]); \37 for(int i=0; i<VECTOR->n; i++) { \ 38 printf("%f\n", VECTOR->data.F64[i]); \ 34 39 } 35 40 … … 39 44 { 40 45 psVector *v1 = NULL; 46 psVector *tempVector = NULL; 47 psImage *tempImage = NULL; 41 48 psImage *m1 = NULL; 42 49 psVector *v2 = NULL; 43 50 psImage *m2 = NULL; 51 psImage *m3 = NULL; 52 psImage *m4 = NULL; 53 psImage *badImage = NULL; 44 54 45 55 … … 50 60 v2 = (psVector*)psVectorAlloc(3, PS_TYPE_F64); 51 61 m2 = (psImage*)psImageAlloc(1, 3, PS_TYPE_F64); 62 m3 = (psImage*)psImageAlloc(3, 1, PS_TYPE_F64); 63 m4 = (psImage*)psImageAlloc(3, 1, PS_TYPE_F64); 64 badImage = (psImage*)psImageAlloc(2, 2, PS_TYPE_F64); 52 65 m1->data.F64[0][0] = 0.0; 53 66 m1->data.F64[1][0] = 1.0; … … 57 70 v2->data.F64[2] = 2.0; 58 71 v2->n = 3; 72 m4->data.F64[0][0] = 0.0; 73 m4->data.F64[0][1] = 1.0; 74 m4->data.F64[0][2] = 2.0; 59 75 PRINT_MATRIX(m1); 76 printf("\n"); 77 PRINT_MATRIX(m4); 60 78 printf("\n"); 61 79 PRINT_VECTOR(v2); … … 63 81 64 82 65 // Test B - Convert matrix to vector 66 printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to vector"); 67 psMatrixToVector(v1, m1); 83 // Test B - Convert matrix to PS_DIMEN_VECTOR vector 84 printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to PS_DIMEN_VECTOR vector"); 85 tempVector = v1; 86 v1 = psMatrixToVector(v1, m1); 68 87 PRINT_VECTOR(v1); 69 printFooter(stdout, "psMatrix", "Calculate Eigenvectors", true); 88 if(v1->type.dimen != PS_DIMEN_VECTOR) { 89 printf("Error: Resulting image is not PS_DIMEN_VECTOR\n"); 90 } else if(v1 != tempVector) { 91 printf("Error: Return pointer not equal to output argument pointer\n"); 92 } 93 printFooter(stdout, "psMatrix", "Convert matrix to PS_DIMEN_VECTOR vector", true); 70 94 71 95 72 // Test C - Convert vector to matrix73 print PositiveTestHeader(stdout, "psMatrix", "Convert vector to matrix");74 psVectorToMatrix(m2, v2);75 PRINT_MATRIX(m2);76 printFooter(stdout, "psMatrix", " Convert vector to matrix", true);96 // Test C - Attempt to use null image input argument 97 printNegativeTestHeader(stdout,"psMatrix", "Attempt to use null image input argument", 98 "Invalid operation: inImage or its data is NULL.", 0); 99 v1 = psMatrixToVector(v1, NULL); 100 printFooter(stdout, "psMatrix", "Attempt to use null image input argument", true); 77 101 78 102 79 // Test D - Free input and output images 103 // Test D - Convert matrix to PS_DIMEN_TRANSV vector 104 printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to PS_DIMEN_TRANSV vector"); 105 v1->type.dimen = PS_DIMEN_TRANSV; 106 psMatrixToVector(v1, m4); 107 PRINT_VECTOR(v1); 108 if(v1->type.dimen != PS_DIMEN_TRANSV) { 109 printf("Error: Resulting image is not PS_DIMEN_TRANSV\n"); 110 } else if(v1 != tempVector) { 111 printf("Error: Return pointer not equal to output argument pointer\n"); 112 } 113 printFooter(stdout, "psMatrix", "Convert matrix to PS_DIMEN_TRANSV vector", true); 114 115 116 // Test E - Improper image size 117 printNegativeTestHeader(stdout,"psMatrix", "Improper image size", 118 "Image does not have dim with 1 col or 1 row: (2 x 2).", 0); 119 psMatrixToVector(v1, badImage); 120 printFooter(stdout, "psMatrix", "Improper image size", true); 121 122 123 // Test F - Convert PS_DIMEN_VECTOR vector to matrix 124 printPositiveTestHeader(stdout, "psMatrix", "Convert PS_DIMEN_VECTOR vector to matrix"); 125 tempImage = m2; 126 m2 = psVectorToMatrix(m2, v2); 127 PRINT_MATRIX(m2); 128 if(m2->type.dimen != PS_DIMEN_IMAGE) { 129 printf("Error: Resulting image is not PS_DIMEN_IMAGE\n"); 130 } else if(m2 != tempImage) { 131 printf("Error: Return pointer not equal to output argument pointer\n"); 132 } 133 printFooter(stdout, "psMatrix", "Convert PS_DIMEN_VECTOR vector to matrix", true); 134 135 136 // Test G - Attempt to use null input vector argument 137 printNegativeTestHeader(stdout,"psMatrix", "Attempt to use null input vector argument", 138 "Invalid operation: inVector or its data is NULL.", 0); 139 psVectorToMatrix(m2, NULL); 140 printFooter(stdout, "psMatrix", "Attempt to use null input vector argument", true); 141 142 143 // Test H - Convert PS_DIMEN_TRANSV vector to matrix 144 printPositiveTestHeader(stdout, "psMatrix", "Convert PS_DIMEN_TRANSV vector to matrix"); 145 v2->type.dimen = PS_DIMEN_TRANSV; 146 tempImage = m3; 147 psVectorToMatrix(m3, v2); 148 PRINT_MATRIX(m3); 149 if(m3->type.dimen != PS_DIMEN_IMAGE) { 150 printf("Error: Resulting image is not PS_DIMEN_IMAGE\n"); 151 } else if(m3 != tempImage) { 152 printf("Error: Return pointer not equal to output argument pointer\n"); 153 } 154 printFooter(stdout, "psMatrix", "Convert PS_DIMEN_TRANSV vector to matrix", true); 155 156 157 // Test I - Free input and output images 80 158 printPositiveTestHeader(stdout, "psMatrix", "Free input and output images and vectors"); 81 159 psImageFree(m1); … … 83 161 psImageFree(m2); 84 162 psVectorFree(v2); 163 psImageFree(m3); 164 psImageFree(m4); 165 psImageFree(badImage); 85 166 psMemCheckLeaks(0, NULL, stdout); 86 167 int nBad = psMemCheckCorruption(0); -
trunk/psLib/test/dataManip/verified/tst_psMatrix07.stdout
r804 r908 9 9 2.000000 10 10 11 0.000000 1.000000 2.000000 12 11 13 0.000000 12 14 1.000000 … … 17 19 /----------------------------- TESTPOINT ------------------------------------------\ 18 20 | TestFile: tst_psMatrix07.c | 19 | TestPoint: psMatrix{Convert matrix to vector}|21 | TestPoint: psMatrix{Convert matrix to PS_DIMEN_VECTOR vector} | 20 22 | TestType: Positive | 21 23 \----------------------------------------------------------------------------------/ … … 25 27 2.000000 26 28 27 ---> TESTPOINT PASSED (psMatrix{C alculate Eigenvectors} | tst_psMatrix07.c)29 ---> TESTPOINT PASSED (psMatrix{Convert matrix to PS_DIMEN_VECTOR vector} | tst_psMatrix07.c) 28 30 29 31 /----------------------------- TESTPOINT ------------------------------------------\ 30 32 | TestFile: tst_psMatrix07.c | 31 | TestPoint: psMatrix{Convert vector to matrix} | 33 | TestPoint: psMatrix{Attempt to use null image input argument} | 34 | TestType: Negative | 35 | ExpectedErrorText: Invalid operation: inImage or its data is NULL. | 36 | ExpectedStatusValue: 0 | 37 \----------------------------------------------------------------------------------/ 38 39 40 ---> TESTPOINT PASSED (psMatrix{Attempt to use null image input argument} | tst_psMatrix07.c) 41 42 /----------------------------- TESTPOINT ------------------------------------------\ 43 | TestFile: tst_psMatrix07.c | 44 | TestPoint: psMatrix{Convert matrix to PS_DIMEN_TRANSV vector} | 45 | TestType: Positive | 46 \----------------------------------------------------------------------------------/ 47 48 0.000000 49 1.000000 50 2.000000 51 52 ---> TESTPOINT PASSED (psMatrix{Convert matrix to PS_DIMEN_TRANSV vector} | tst_psMatrix07.c) 53 54 /----------------------------- TESTPOINT ------------------------------------------\ 55 | TestFile: tst_psMatrix07.c | 56 | TestPoint: psMatrix{Improper image size} | 57 | TestType: Negative | 58 | ExpectedErrorText: Image does not have dim with 1 col or 1 row: (2 x 2). | 59 | ExpectedStatusValue: 0 | 60 \----------------------------------------------------------------------------------/ 61 62 63 ---> TESTPOINT PASSED (psMatrix{Improper image size} | tst_psMatrix07.c) 64 65 /----------------------------- TESTPOINT ------------------------------------------\ 66 | TestFile: tst_psMatrix07.c | 67 | TestPoint: psMatrix{Convert PS_DIMEN_VECTOR vector to matrix} | 32 68 | TestType: Positive | 33 69 \----------------------------------------------------------------------------------/ … … 37 73 2.000000 38 74 39 ---> TESTPOINT PASSED (psMatrix{Convert vector to matrix} | tst_psMatrix07.c) 75 ---> TESTPOINT PASSED (psMatrix{Convert PS_DIMEN_VECTOR vector to matrix} | tst_psMatrix07.c) 76 77 /----------------------------- TESTPOINT ------------------------------------------\ 78 | TestFile: tst_psMatrix07.c | 79 | TestPoint: psMatrix{Attempt to use null input vector argument} | 80 | TestType: Negative | 81 | ExpectedErrorText: Invalid operation: inVector or its data is NULL. | 82 | ExpectedStatusValue: 0 | 83 \----------------------------------------------------------------------------------/ 84 85 86 ---> TESTPOINT PASSED (psMatrix{Attempt to use null input vector argument} | tst_psMatrix07.c) 87 88 /----------------------------- TESTPOINT ------------------------------------------\ 89 | TestFile: tst_psMatrix07.c | 90 | TestPoint: psMatrix{Convert PS_DIMEN_TRANSV vector to matrix} | 91 | TestType: Positive | 92 \----------------------------------------------------------------------------------/ 93 94 0.000000 1.000000 2.000000 95 96 ---> TESTPOINT PASSED (psMatrix{Convert PS_DIMEN_TRANSV vector to matrix} | tst_psMatrix07.c) 40 97 41 98 /----------------------------- TESTPOINT ------------------------------------------\
Note:
See TracChangeset
for help on using the changeset viewer.
