Changeset 824 for trunk/psLib/src/math/psMatrix.c
- Timestamp:
- Jun 1, 2004, 12:42:57 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMatrix.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMatrix.c
r807 r824 20 20 * @author Ross Harman, MHPCC 21 21 * 22 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $23 * @date $Date: 2004-0 5-28 20:52:41$22 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2004-06-01 22:42:57 $ 24 24 * 25 25 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 69 69 70 70 /** Preprocessor macro to generate error a NULL image */ 71 #define PS_CHECK_NULL_VECTOR(NAME, RETURN) \72 if (NAME == NULL || NAME->vec.v == NULL) { \73 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \74 return RETURN; \71 #define PS_CHECK_NULL_VECTOR(NAME, RETURN) \ 72 if (NAME == NULL || NAME->vec.v == NULL) { \ 73 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \ 74 return RETURN; \ 75 75 } 76 76 77 77 /** Preprocessor macro to create vector based on another */ 78 #define PS_CHECK_ALLOC_VECTOR(NAME, SIZE, PS_TYPE) \79 if(NAME == NULL) { \80 NAME = psVectorAlloc(PS_TYPE, SIZE); \78 #define PS_CHECK_ALLOC_VECTOR(NAME, SIZE, PS_TYPE) \ 79 if(NAME == NULL) { \ 80 NAME = psVectorAlloc(PS_TYPE, SIZE); \ 81 81 } 82 82 83 83 /** Preprocessor macro to generate error for zero length vector */ 84 #define PS_CHECK_SIZE_VECTOR(NAME, RETURN) \85 if (NAME->n < 1) { \86 psError(__func__,"Invalid operation: %s has zero n value.", #NAME); \87 return RETURN; \84 #define PS_CHECK_SIZE_VECTOR(NAME, RETURN) \ 85 if (NAME->n < 1) { \ 86 psError(__func__,"Invalid operation: %s has zero n value.", #NAME); \ 87 return RETURN; \ 88 88 } 89 89 90 90 /** Preprocessor macro to generate error a NULL image */ 91 #define PS_CHECK_NULL_IMAGE(NAME, RETURN) \92 if (NAME == NULL || NAME->data. v == NULL) {\93 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \94 return RETURN; \91 #define PS_CHECK_NULL_IMAGE(NAME, RETURN) \ 92 if (NAME == NULL || NAME->data.V == NULL) { \ 93 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \ 94 return RETURN; \ 95 95 } 96 96 97 97 /** Preprocessor macro to create image based on another */ 98 #define PS_CHECK_ALLOC_IMAGE(NAME, NCOLS, NROWS, PS_TYPE) \99 if(NAME == NULL) { \100 NAME = psImageAlloc(NCOLS, NROWS, PS_TYPE); \98 #define PS_CHECK_ALLOC_IMAGE(NAME, NCOLS, NROWS, PS_TYPE) \ 99 if(NAME == NULL) { \ 100 NAME = psImageAlloc(NCOLS, NROWS, PS_TYPE); \ 101 101 } 102 102 103 103 /** Preprocessor macro to generate error for zero length rows or columns */ 104 #define PS_CHECK_SIZE_IMAGE(NAME, RETURN) \105 if (NAME->numCols < 1 || NAME->numRows < 1) { \106 psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME, \107 NAME->numCols, NAME->numRows); \108 return RETURN; \104 #define PS_CHECK_SIZE_IMAGE(NAME, RETURN) \ 105 if (NAME->numCols < 1 || NAME->numRows < 1) { \ 106 psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME, \ 107 NAME->numCols, NAME->numRows); \ 108 return RETURN; \ 109 109 } 110 110 111 111 /** Preprocessor macro to generate error for image dimensionality not set to PS_DIMEN_IMAGE */ 112 #define PS_CHECK_DIMEN_AND_TYPE(NAME, PS_DIMEN, RETURN) \113 if (NAME->type.dimen != PS_DIMEN) { \114 psError(__func__,"Invalid operation: %s incorrect dimensionality %d.", #NAME, PS_DIMEN);\115 return RETURN; \116 } else if(NAME->type.type != PS_TYPE_F64) { \117 psError(__func__, "Invalid operation: %s not PS_TYPE_F64.", #NAME); \118 return RETURN; \112 #define PS_CHECK_DIMEN_AND_TYPE(NAME, PS_DIMEN, RETURN) \ 113 if (NAME->type.dimen != PS_DIMEN) { \ 114 psError(__func__,"Invalid operation: %s incorrectdimensionality %d.", #NAME, PS_DIMEN); \ 115 return RETURN; \ 116 } else if(NAME->type.type != PS_TYPE_F64) { \ 117 psError(__func__, "Invalid operation: %s not PS_TYPE_F64.", #NAME); \ 118 return RETURN; \ 119 119 } 120 120 121 121 /** Preprocessor macro to check that input is not equal to output */ 122 #define PS_CHECK_POINTERS(NAME1, NAME2, RETURN) \123 if (NAME1 == NAME2) { \124 psError(__func__,"Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2); \125 return RETURN; \122 #define PS_CHECK_POINTERS(NAME1, NAME2, RETURN) \ 123 if (NAME1 == NAME2) { \ 124 psError(__func__,"Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2); \ 125 return RETURN; \ 126 126 } 127 127 128 128 /** Preprocessor macro to check that an image is square */ 129 #define PS_CHECK_SQUARE(NAME, RETURN) \130 if (NAME->numCols != NAME->numRows) { \131 psError(__func__,"Invalid operation: %s not square array.", #NAME); \132 return RETURN; \129 #define PS_CHECK_SQUARE(NAME, RETURN) \ 130 if (NAME->numCols != NAME->numRows) { \ 131 psError(__func__,"Invalid operation: %s not square array.", #NAME); \ 132 return RETURN; \ 133 133 } 134 134 135 135 /** Preprocessor macro to initalize a GSL matrix. */ 136 #define PS_GSL_MATRIX_INITIALIZE(LHS_NAME, RHS_NAME) \137 LHS_NAME.size1 = numRows; \138 LHS_NAME.size2 = numCols; \139 LHS_NAME.tda = numCols; \136 #define PS_GSL_MATRIX_INITIALIZE(LHS_NAME, RHS_NAME) \ 137 LHS_NAME.size1 = numRows; \ 138 LHS_NAME.size2 = numCols; \ 139 LHS_NAME.tda = numCols; \ 140 140 LHS_NAME.data = RHS_NAME; 141 141 … … 174 174 outPerm->n = numCols; 175 175 perm.data = outPerm->vec.v; 176 PS_GSL_MATRIX_INITIALIZE(lu, outImage->data. v[0]);176 PS_GSL_MATRIX_INITIALIZE(lu, outImage->data.V[0]); 177 177 178 178 // Non-square matrices not allowed … … 181 181 182 182 // Copy psImage input data into GSL matrix data to keep input data pristine 183 memcpy(lu.data, inImage->data. v[0], arraySize);183 memcpy(lu.data, inImage->data.V[0], arraySize); 184 184 185 185 // Calculate LU decomposition … … 189 189 } 190 190 191 psVector *psMatrixLUSolve(psVector *outVector, const psImage *inImage, const psVector *inVector, const psVector *inPerm) 191 psVector *psMatrixLUSolve(psVector *outVector, const psImage *inImage, const psVector *inVector, const 192 psVector *inPerm) 192 193 { 193 194 int arraySize = 0; … … 220 221 221 222 // Initialize GSL data 222 PS_GSL_MATRIX_INITIALIZE(lu, inImage->data. v[0]);223 PS_GSL_MATRIX_INITIALIZE(lu, inImage->data.V[0]); 223 224 224 225 outVector->n = numCols; … … 270 271 271 272 // Initialize GSL data 272 PS_GSL_MATRIX_INITIALIZE(inv, outImage->data. v[0]);273 PS_GSL_MATRIX_INITIALIZE(inv, outImage->data.V[0]); 273 274 274 275 // Non-square matrices not allowed … … 277 278 278 279 // Copy psImage input data into GSL matrix data to keep input data pristine 279 memcpy(lu->data, inImage->data. v[0], arraySize);280 memcpy(lu->data, inImage->data.V[0], arraySize); 280 281 281 282 // Invert data and calculate determinant … … 319 320 320 321 // Copy psImage input data into GSL matrix data to keep input data pristine 321 memcpy(lu->data, inImage->data. v[0], arraySize);322 memcpy(lu->data, inImage->data.V[0], arraySize); 322 323 323 324 // Calculate determinant … … 360 361 361 362 // Initialize GSL data 362 PS_GSL_MATRIX_INITIALIZE(m1, inImage1->data. v[0]);363 PS_GSL_MATRIX_INITIALIZE(m2, inImage2->data. v[0]);364 PS_GSL_MATRIX_INITIALIZE(m3, outImage->data. v[0]);363 PS_GSL_MATRIX_INITIALIZE(m1, inImage1->data.V[0]); 364 PS_GSL_MATRIX_INITIALIZE(m2, inImage2->data.V[0]); 365 PS_GSL_MATRIX_INITIALIZE(m3, outImage->data.V[0]); 365 366 366 367 // Non-square matrices not allowed … … 396 397 397 398 // Initialize GSL data 398 PS_GSL_MATRIX_INITIALIZE(trans, outImage->data. v[0]);399 PS_GSL_MATRIX_INITIALIZE(trans, outImage->data.V[0]); 399 400 400 401 // Non-square matrices not allowed … … 403 404 404 405 // Copy psImage input data into psImage output data to keep input data pristine 405 memcpy(outImage->data. v[0], inImage->data.v[0], arraySize);406 memcpy(outImage->data.V[0], inImage->data.V[0], arraySize); 406 407 407 408 // Transpose data … … 434 435 435 436 // Initialize GSL data 436 PS_GSL_MATRIX_INITIALIZE(in, inImage->data. v[0]);437 PS_GSL_MATRIX_INITIALIZE(out, outImage->data. v[0]);437 PS_GSL_MATRIX_INITIALIZE(in, inImage->data.V[0]); 438 PS_GSL_MATRIX_INITIALIZE(out, outImage->data.V[0]); 438 439 439 440 // Allocate GSL structs … … 482 483 483 484 colSize = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows; 484 memcpy(outVector->vec.v, inImage->data. v[0], colSize);485 memcpy(outVector->vec.v, inImage->data.V[0], colSize); 485 486 486 487 return outVector; … … 509 510 510 511 colSize = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows; 511 memcpy(outImage->data. v[0], inVector->vec.v, colSize);512 memcpy(outImage->data.V[0], inVector->vec.v, colSize); 512 513 513 514 return outImage;
Note:
See TracChangeset
for help on using the changeset viewer.
