Changeset 2273 for trunk/psLib/src/dataManip/psMatrix.c
- Timestamp:
- Nov 3, 2004, 3:05:00 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/dataManip/psMatrix.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMatrix.c
r2214 r2273 20 20 * @author Ross Harman, MHPCC 21 21 * 22 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $23 * @date $Date: 2004-1 0-27 20:20:11$22 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2004-11-04 01:04:59 $ 24 24 * 25 25 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 40 40 #include "psVector.h" 41 41 #include "psMatrix.h" 42 43 /** Preprocessor macro to generate error a NULL image */ 44 #define PS_VECTOR_CHECK_NULL(NAME, RETURN) \ 45 if (NAME == NULL || NAME->data.V == NULL) { \ 46 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \ 47 return RETURN; \ 48 } 49 50 /** Preprocessor macro to create vector based on another */ 51 #define PS_CHECK_ALLOC_VECTOR(NAME, SIZE, PS_TYPE) \ 52 if(NAME == NULL) { \ 53 NAME = psVectorAlloc(SIZE, PS_TYPE); \ 54 } 55 56 /** Preprocessor macro to generate error for zero length vector */ 57 #define PS_CHECK_SIZE_VECTOR(NAME, RETURN) \ 58 if (NAME->n < 1) { \ 59 psError(__func__,"Invalid operation: %s has zero n value.", #NAME); \ 60 return RETURN; \ 61 } 62 63 /** Preprocessor macro to generate error a NULL image */ 64 #define PS_IMAGE_CHECK_NULL(NAME, RETURN) \ 65 if (NAME == NULL || NAME->data.V == NULL) { \ 66 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \ 67 return RETURN; \ 68 } 69 70 /** Preprocessor macro to create image based on another */ 71 #define PS_CHECK_ALLOC_IMAGE(NAME, NCOLS, NROWS, PS_TYPE) \ 72 if(NAME == NULL) { \ 73 NAME = psImageAlloc(NCOLS, NROWS, PS_TYPE); \ 74 } 75 76 /** Preprocessor macro to generate error for zero length rows or columns */ 77 #define PS_CHECK_SIZE_IMAGE(NAME, RETURN) \ 78 if (NAME->numCols < 1 || NAME->numRows < 1) { \ 79 psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME, \ 80 NAME->numCols, NAME->numRows); \ 81 return RETURN; \ 82 } 42 #include "psConstants.h" 43 44 83 45 84 46 /** Preprocessor macro to generate error for image dimensionality not set to PS_DIMEN_IMAGE */ 85 47 #define PS_CHECK_DIMEN_AND_TYPE(NAME, PS_DIMEN, RETURN) \ 86 48 if (NAME->type.dimen != PS_DIMEN) { \ 87 psError(__func__,"Invalid operation: %s incorrect dimensionality %d.", #NAME, PS_DIMEN); \ 49 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 50 "Invalid operation. %s has incorrect dimensionality %d.", #NAME, PS_DIMEN); \ 88 51 return RETURN; \ 89 52 } else if(NAME->type.type != PS_TYPE_F64) { \ 90 psError(__func__, "Invalid operation: %s not PS_TYPE_F64.", #NAME); \ 53 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 54 "Invalid operation. %s not PS_TYPE_F64.", #NAME); \ 91 55 return RETURN; \ 92 56 } … … 95 59 #define PS_CHECK_POINTERS(NAME1, NAME2, RETURN) \ 96 60 if (NAME1 == NAME2) { \ 97 psError(__func__,"Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2); \ 61 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 62 "Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2); \ 98 63 return RETURN; \ 99 64 } … … 102 67 #define PS_CHECK_SQUARE(NAME, RETURN) \ 103 68 if (NAME->numCols != NAME->numRows) { \ 104 psError(__func__,"Invalid operation: %s not square array.", #NAME); \ 69 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 70 "Invalid operation: %s not square array.", #NAME); \ 105 71 return RETURN; \ 106 72 } … … 126 92 gsl_permutation perm; 127 93 94 #define psMatrixLUD_EXIT { \ 95 psFree(outImage); \ 96 return NULL; \ 97 } 98 128 99 // Error checks 129 100 PS_CHECK_POINTERS(inImage, outImage, outImage); 130 PS_IMAGE_CHECK_NULL(inImage, outImage);131 101 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 132 PS_CHECK_SIZE_IMAGE(inImage, outImage); 133 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 134 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 135 PS_CHECK_SIZE_IMAGE(outImage, outImage); 136 PS_CHECK_ALLOC_VECTOR(outPerm, inImage->numRows, inImage->type.type); 137 PS_VECTOR_CHECK_NULL(outPerm, outImage); 102 103 PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixLUD_EXIT); 104 PS_VECTOR_CHECK_NULL_GENERAL(outPerm, psMatrixLUD_EXIT); 105 138 106 PS_CHECK_DIMEN_AND_TYPE(outPerm, PS_DIMEN_VECTOR, outImage); 107 108 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 109 psVectorRecycle(outPerm, inImage->numRows, inImage->type.type); 139 110 140 111 // Initialize data … … 179 150 PS_IMAGE_CHECK_NULL(inImage, outVector); 180 151 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector); 181 PS_CHECK_SIZE_IMAGE(inImage, outVector); 182 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type); 152 PS_IMAGE_CHECK_EMPTY(inImage, outVector); 183 153 PS_VECTOR_CHECK_NULL(outVector, outVector); 184 154 PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector); … … 188 158 PS_CHECK_DIMEN_AND_TYPE(inPerm, PS_DIMEN_VECTOR, outVector); 189 159 160 psVectorRecycle(outVector, inImage->numRows, inImage->type.type); 161 162 190 163 // Initialize data 191 164 numRows = inImage->numRows; … … 226 199 227 200 // Error checks 228 if (det == NULL) { 229 psError(__func__, "Invalid operation: determinant argument is NULL."); 230 return outImage; 231 } 201 PS_PTR_CHECK_NULL(det, outImage); 232 202 PS_CHECK_POINTERS(inImage, outImage, outImage); 233 203 PS_IMAGE_CHECK_NULL(inImage, outImage); 234 204 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 235 PS_CHECK_SIZE_IMAGE(inImage, outImage); 236 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 237 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 238 PS_CHECK_SIZE_IMAGE(outImage, outImage); 205 PS_IMAGE_CHECK_EMPTY(inImage, outImage); 206 207 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 239 208 240 209 // Initialize data … … 282 251 PS_IMAGE_CHECK_NULL(inImage, NULL); 283 252 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL); 284 PS_ CHECK_SIZE_IMAGE(inImage, NULL);253 PS_IMAGE_CHECK_EMPTY(inImage, NULL); 285 254 286 255 // Initialize data … … 325 294 PS_IMAGE_CHECK_NULL(inImage1, outImage); 326 295 PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage); 327 PS_ CHECK_SIZE_IMAGE(inImage1, outImage);296 PS_IMAGE_CHECK_EMPTY(inImage1, outImage); 328 297 PS_IMAGE_CHECK_NULL(inImage2, outImage); 329 298 PS_CHECK_DIMEN_AND_TYPE(inImage2, PS_DIMEN_IMAGE, outImage); 330 PS_CHECK_SIZE_IMAGE(inImage2, outImage); 331 PS_CHECK_ALLOC_IMAGE(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type); 299 PS_IMAGE_CHECK_EMPTY(inImage2, outImage); 332 300 PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage); 333 PS_CHECK_SIZE_IMAGE(outImage, outImage); 301 302 psImageRecycle(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type); 334 303 335 304 // Initialize data … … 364 333 PS_IMAGE_CHECK_NULL(inImage, outImage); 365 334 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 366 PS_CHECK_SIZE_IMAGE(inImage, outImage); 367 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 368 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 369 PS_CHECK_SIZE_IMAGE(outImage, outImage); 335 PS_IMAGE_CHECK_EMPTY(inImage, outImage); 336 337 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 370 338 371 339 // Initialize data … … 403 371 PS_IMAGE_CHECK_NULL(inImage, outImage); 404 372 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage); 405 PS_CHECK_SIZE_IMAGE(inImage, outImage); 406 PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 407 PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage); 408 PS_CHECK_SIZE_IMAGE(outImage, outImage); 373 PS_IMAGE_CHECK_EMPTY(inImage, outImage); 374 375 psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type); 409 376 410 377 // Initialize data … … 438 405 psS32 size = 0; 439 406 440 // Error checks 441 PS_IMAGE_CHECK_NULL(inImage, outVector); 407 #define psMatrixToVector_EXIT { \ 408 psFree(outVector); \ 409 return NULL; \ 410 } 411 412 // Error checks 413 PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixToVector_EXIT); 442 414 PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector); 443 PS_ CHECK_SIZE_IMAGE(inImage, outVector);415 PS_IMAGE_CHECK_EMPTY_GENERAL(inImage, psMatrixToVector_EXIT); 444 416 445 417 if (inImage->numRows == 1) { 446 418 // Create transposed row vector 447 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type);419 psVectorRecycle(outVector, inImage->numCols, inImage->type.type); 448 420 outVector->type.dimen = PS_DIMEN_TRANSV; 449 421 } else if (inImage->numCols == 1) { 450 422 // Create non-transposed column vector 451 PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);423 psVectorRecycle(outVector, inImage->numRows, inImage->type.type); 452 424 } else { 453 psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows, 454 inImage->numCols); 425 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 426 "Image does not have dim with 1 col or 1 row: (%d x %d).", 427 inImage->numRows, inImage->numCols); 455 428 return outVector; 456 429 } … … 467 440 468 441 if (outVector->n != inImage->numRows) { 469 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n); 442 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 443 "Image and vector sizes differ: (%d vs %d).", 444 inImage->numRows, outVector->n); 470 445 return outVector; 471 446 } … … 481 456 482 457 if (outVector->n != inImage->numCols) { 483 psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n); 458 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 459 "Image and vector sizes differ: (%d vs %d).", 460 inImage->numCols, outVector->n); 484 461 return outVector; 485 462 } … … 502 479 if (inVector->type.dimen == PS_DIMEN_VECTOR) { 503 480 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage); 504 PS_ CHECK_SIZE_VECTOR(inVector, outImage);505 PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64)481 PS_VECTOR_CHECK_EMPTY(inVector, outImage); 482 psImageRecycle(outImage, 1, inVector->n, PS_TYPE_F64); 506 483 // More checks for PS_DIMEN_VECTOR 507 484 if (outImage->numCols > 1) { 508 psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols); 485 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 486 "Image has more than 1 column: numCols = %d.", 487 outImage->numCols); 509 488 return outImage; 510 489 } else if (outImage->numRows != inVector->n) { 511 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n); 490 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 491 "Image and vector sizes differ: (%d vs %d).", 492 outImage->numRows, inVector->n); 512 493 return outImage; 513 494 } … … 517 498 } else if (inVector->type.dimen == PS_DIMEN_TRANSV) { 518 499 PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage); 519 PS_ CHECK_SIZE_VECTOR(inVector, outImage);520 PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64)500 PS_VECTOR_CHECK_EMPTY(inVector, outImage); 501 psImageRecycle(outImage, inVector->n, 1, PS_TYPE_F64); 521 502 // More checks for PS_DIMEN_TRANSV 522 503 if (outImage->numRows > 1) { 523 psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows); 504 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 505 "Image has more than 1 row: numRows = %d.", 506 outImage->numRows); 524 507 return outImage; 525 508 } else if (outImage->numCols != inVector->n) { 526 psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n); 509 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 510 "Image and vector sizes differ: (%d vs %d).", 511 outImage->numCols, inVector->n); 527 512 return outImage; 528 513 }
Note:
See TracChangeset
for help on using the changeset viewer.
