- Timestamp:
- Dec 10, 2004, 11:38:48 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psMatrixVectorArithmetic03.c
r2273 r2693 15 15 * @author Ross Harman, MHPCC 16 16 * 17 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $18 * @date $Date: 2004-1 1-04 01:05:00$17 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2004-12-10 21:38:47 $ 19 19 * 20 20 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 25 25 #include "psTest.h" 26 26 27 28 #define PRINT_VECTOR(VECTOR,TYPE) \ 29 for(psS32 i=0; i<VECTOR->n; i++) { \ 30 if(PS_IS_PSELEMTYPE_COMPLEX(VECTOR->type.type)) { \ 31 printf("%f+%fi ", creal(VECTOR->data.TYPE[i]), cimag(VECTOR->data.TYPE[i])); \ 32 } else if(PS_IS_PSELEMTYPE_INT(VECTOR->type.type)) { \ 33 printf("%d ", (psS32)VECTOR->data.TYPE[i]); \ 34 } else { \ 35 printf("%f ", (double)VECTOR->data.TYPE[i]); \ 36 } \ 37 } \ 27 #define PRINT_VECTOR(VECTOR,TYPE) \ 28 for(psS32 i=0; i<VECTOR->n; i++) { \ 29 if(PS_IS_PSELEMTYPE_COMPLEX(VECTOR->type.type)) { \ 30 printf("%f+%fi ", creal(VECTOR->data.TYPE[i]), cimag(VECTOR->data.TYPE[i])); \ 31 } else if(PS_IS_PSELEMTYPE_INT(VECTOR->type.type)) { \ 32 printf("%d ", (psS32)VECTOR->data.TYPE[i]); \ 33 } else { \ 34 printf("%f ", (double)VECTOR->data.TYPE[i]); \ 35 } \ 36 } \ 38 37 printf("\n\n"); 39 38 40 41 #define PRINT_MATRIX(IMAGE,TYPE) \ 42 for(psS32 i=IMAGE->numRows-1; i>-1; i--) { \ 43 for(psS32 j=0; j<IMAGE->numCols; j++) { \ 44 if(PS_IS_PSELEMTYPE_COMPLEX(IMAGE->type.type)) { \ 45 printf("%f+%fi ", creal(IMAGE->data.TYPE[i][j]), cimag(IMAGE->data.TYPE[i][j])); \ 46 } else if(PS_IS_PSELEMTYPE_INT(IMAGE->type.type)) { \ 47 printf("%d ", (psS32)IMAGE->data.TYPE[i][j]); \ 48 } else { \ 49 printf("%f ", (double)IMAGE->data.TYPE[i][j]); \ 50 } \ 51 } \ 52 printf("\n"); \ 53 } \ 39 #define PRINT_MATRIX(IMAGE,TYPE) \ 40 for(psS32 i=IMAGE->numRows-1; i>-1; i--) { \ 41 for(psS32 j=0; j<IMAGE->numCols; j++) { \ 42 if(PS_IS_PSELEMTYPE_COMPLEX(IMAGE->type.type)) { \ 43 printf("%f+%fi ", creal(IMAGE->data.TYPE[i][j]), cimag(IMAGE->data.TYPE[i][j])); \ 44 } else if(PS_IS_PSELEMTYPE_INT(IMAGE->type.type)) { \ 45 printf("%d ", (psS32)IMAGE->data.TYPE[i][j]); \ 46 } else { \ 47 printf("%f ", (double)IMAGE->data.TYPE[i][j]); \ 48 } \ 49 } \ 50 printf("\n"); \ 51 } \ 54 52 printf("\n"); 55 53 56 54 57 #define CREATE_AND_SET_VECTOR(NAME,TYPE,VALUE,SIZE) \58 psVector *NAME = (psVector*)psVectorAlloc(SIZE, PS_TYPE_##TYPE); \59 for(psS32 i=0; i<SIZE; i++) { \60 NAME->data.TYPE[i] = VALUE; \61 } \55 #define CREATE_AND_SET_VECTOR(NAME,TYPE,VALUE,SIZE) \ 56 psVector *NAME = (psVector*)psVectorAlloc(SIZE, PS_TYPE_##TYPE); \ 57 for(psS32 i=0; i<SIZE; i++) { \ 58 NAME->data.TYPE[i] = VALUE; \ 59 } \ 62 60 NAME->n = SIZE; 63 61 64 62 65 #define CREATE_AND_SET_IMAGE(NAME,TYPE,VALUE,NROWS,NCOLS) \66 psImage *NAME = (psImage*)psImageAlloc(NCOLS,NROWS,PS_TYPE_##TYPE); \67 for(psS32 i=0; i<NAME->numRows; i++) { \68 for(psS32 j=0; j<NAME->numCols; j++) { \69 NAME->data.TYPE[i][j] = VALUE; \70 } \63 #define CREATE_AND_SET_IMAGE(NAME,TYPE,VALUE,NROWS,NCOLS) \ 64 psImage *NAME = (psImage*)psImageAlloc(NCOLS,NROWS,PS_TYPE_##TYPE); \ 65 for(psS32 i=0; i<NAME->numRows; i++) { \ 66 for(psS32 j=0; j<NAME->numCols; j++) { \ 67 NAME->data.TYPE[i][j] = VALUE; \ 68 } \ 71 69 } 72 70 … … 82 80 CREATE_AND_SET_VECTOR(vector2,F64,0,3); 83 81 84 85 // Check for NULL arguments 86 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Check for NULL arguments", 87 "Null XXX argument", 0); 82 // Check for NULL output argument 83 printPositiveTestHeader(stdout,"psBinaryOp", "Check for output generated"); 88 84 psImage* image6 = (psImage*)psBinaryOp(NULL, image1, "+", image2); 89 85 if (image6 == NULL) { … … 91 87 return 1; 92 88 } 93 89 printFooter(stdout,"psBinaryOp","Check for output generated",true); 90 91 // Check for NULL input argument #1 92 printPositiveTestHeader(stdout,"psBinaryOp","Check for null input arg 1"); 93 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 94 94 image6 = (psImage*)psBinaryOp(image6, NULL, "+", image2); 95 95 if (image6 != NULL) { … … 97 97 return 2; 98 98 } 99 99 printFooter(stdout,"psBinaryOp","Check for null input arg 1",true); 100 101 // Check for NULL input argument #2 102 printPositiveTestHeader(stdout,"psBinaryOp","Check for null input arg 2"); 103 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 100 104 image6 = (psImage*)psBinaryOp(image6, image1, "+", NULL); 101 105 if (image6 != NULL) { … … 103 107 return 3; 104 108 } 109 printFooter(stdout,"psBinaryOp","Check for null input arg 2",true); 110 111 // Check for NULL operand 112 printPositiveTestHeader(stdout,"psBinaryOp","Check for null operand"); 113 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 105 114 image6 = (psImage*)psBinaryOp(image6, image1, NULL, image2); 106 115 if (image6 != NULL) { … … 108 117 return 4; 109 118 } 110 119 printFooter(stdout,"psBinaryOp","Check for null operand",true); 120 121 // Check for null output 122 printPositiveTestHeader(stdout,"psUnaryOp","Check for null output"); 111 123 image6 = (psImage*)psUnaryOp(NULL, image1, "sin"); 112 124 if (image6 == NULL) { … … 114 126 return 5; 115 127 } 116 128 printFooter(stdout,"psUnaryOp","Check for null output",true); 129 130 // Check for NULL input arg 131 printPositiveTestHeader(stdout,"psUnaryOp","Check for null input"); 132 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 117 133 image6 = (psImage*)psUnaryOp(image6, NULL, "sin"); 118 134 if (image6 != NULL) { … … 120 136 return 6; 121 137 } 122 138 printFooter(stdout,"psUnaryOp","Check for null input",true); 139 140 // Check for NULL operand 141 printPositiveTestHeader(stdout,"psUnaryOp","Check for null operator"); 142 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 123 143 image6 = (psImage*)psUnaryOp(image6, image1, NULL); 124 144 if (image6 != NULL) { … … 126 146 return 7; 127 147 } 128 129 printFooter(stdout, "psMatrixVectorArithmetic", "Check for NULL arguments", true); 148 printFooter(stdout,"psUnaryOp","Check for null operator",true); 130 149 131 150 // Inconsistent element types 132 print NegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Inconsistent element types",133 "Element types for arguments inconsistent", 0);151 printPositiveTestHeader(stdout,"psBinaryOp", "Inconsistent element types"); 152 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 134 153 image6 = (psImage*)psBinaryOp(image6, image3, "+", image2); 135 154 if (image6 != NULL) { … … 137 156 return 8; 138 157 } 139 158 printFooter(stdout,"psBinaryOp","Inconsistent element types",true); 159 160 // Check unary op to convert to correct type 161 printPositiveTestHeader(stdout,"psUnaryOp","Check output type conversion"); 140 162 image6 = psImageCopy(image6,image2,PS_TYPE_F64); 141 163 image6 = (psImage*)psUnaryOp(image6, image3, "sin"); … … 144 166 return 9; 145 167 } 146 147 printFooter(stdout, "psMatrixVectorArithmetic", "Inconsistent element types", true); 148 168 printFooter(stdout,"psUnaryOp","Check output type conversion",true); 149 169 150 170 // Inconsistent element count 151 print NegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Inconsistent element count",152 "Inconsistent element count", 0);171 printPositiveTestHeader(stdout,"psBinaryOp","Check for inconsistent elements"); 172 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 153 173 image6 = (psImage*)psBinaryOp(image6, image4, "+", image2); 154 174 if (image6 != NULL) { … … 156 176 return 10; 157 177 } 158 178 printFooter(stdout,"psBinaryOp","Check for inconsistent elements",true); 179 180 // Inconsistent element in input and output 181 printPositiveTestHeader(stdout,"psUnaryOp","Check inconsistent elements in input and output"); 159 182 image6 = psImageCopy(image6,image2,PS_TYPE_F64); 160 183 image6 = (psImage*)psUnaryOp(image6, image4, "sin"); … … 165 188 return 11; 166 189 } 167 190 printFooter(stdout,"psUnaryOp","Check inconsistent elements in input and output",true); 191 192 // Inconsistent size of input 1 and input 2 193 printPositiveTestHeader(stdout,"psBinaryOp","Check inconsistent size"); 194 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 168 195 image6 = (psImage*)psBinaryOp(image6, vector1, "+", image2); 169 196 if (image6 != NULL) { … … 171 198 return 12; 172 199 } 173 200 printFooter(stdout,"psBinaryOp","Check inconsistent size",true); 201 202 // Inconsistent size of input 1 and input 2 203 printPositiveTestHeader(stdout,"psBinaryOp","Check inconsistent size"); 204 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 174 205 vector1->type.dimen = PS_DIMEN_TRANSV; 175 206 image6 = (psImage*)psBinaryOp(image6, vector1, "+", image2); … … 178 209 return 13; 179 210 } 180 printFooter(stdout, "ps MatrixVectorArithmetic", "Inconsistent element count", true);211 printFooter(stdout, "psBinaryOp", "Check inconsistent size", true); 181 212 182 213 183 214 // Inconsistent dimensionality 184 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Inconsistent dimensionality", 185 "Dimensionality for arguments inconsistent", 0); 215 printPositiveTestHeader(stdout,"psUnaryOp","Check inconsistent dimensionality"); 186 216 image6 = psImageCopy(image6,image2,PS_TYPE_F64); 217 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an two error messages"); 187 218 image6 = (psImage*)psUnaryOp(image6, vector2, "sin"); 188 219 if (image6 != NULL) { … … 190 221 return 14; 191 222 } 192 193 printFooter(stdout, "psMatrixVectorArithmetic", "Inconsistent dimensionality", true); 223 printFooter(stdout,"psUnaryOp","Check inconsistent dimensionality",true); 194 224 195 225 // Attempt to use min with complex numbers 196 print NegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Use min with complex numbers",197 "Minimum operation not supported for complex numbers", 0);226 printPositiveTestHeader(stdout,"psBinaryOp","Attempt to use min with complex numbers"); 227 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 198 228 image6 = (psImage*)psBinaryOp(image6, image5, "min", image5); 199 printFooter(stdout, "psMatrixVectorArithmetic", "Use min with complex numbers", true); 229 if(image6 != NULL) { 230 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp returned result with min of complex numbers"); 231 return 15; 232 } 233 printFooter(stdout, "psBinaryOp", "Attempt to use min with complex numbers", true); 200 234 201 235 202 236 // Attempt to use max with complex numbers 203 print NegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Use max with complex numbers",204 "Maximum operation not supported for complex numbers", 0);237 printPositiveTestHeader(stdout,"psBinaryOp","Attempt to use max with complex numbers"); 238 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 205 239 image6 = (psImage*)psBinaryOp(image6, image5, "max", image5); 206 printFooter(stdout, "psMatrixVectorArithmetic", "Use max with complex numbers", true); 240 if(image6 != NULL) { 241 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp returned result with max of complex numbers"); 242 return 16; 243 } 244 printFooter(stdout, "psBinaryOp", "Attempt to use max with complex numbers", true); 207 245 208 246 209 247 // Invalid operation 210 print NegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Invalid operation",211 "Invalid operation", 0);248 printPositiveTestHeader(stdout,"psBinary","Attempt to use invalid operator"); 249 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error messgae"); 212 250 image6 = (psImage*)psBinaryOp(image6, image1, "yarg", image2); 251 if(image6 != NULL) { 252 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned result with invalid operator"); 253 return 17; 254 } 255 printFooter(stdout,"psBinaryOp","Attempt to use invalid operator",true); 256 257 printPositiveTestHeader(stdout,"psUnaryOp","Attempt to use invalid operator"); 258 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 213 259 image6 = (psImage*)psUnaryOp(image6, image1, "yarg"); 214 printFooter(stdout, "psMatrixVectorArithmetic", "Invalid operation", true); 215 216 // Invalid parameter in2 217 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic","Invalid input", 218 "Invalid operation", 0); 260 if(image6 != NULL) { 261 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp returned result with invalid operator"); 262 return 18; 263 } 264 printFooter(stdout, "psUnaryOp", "Attempt to use invalid operator", true); 265 219 266 CREATE_AND_SET_VECTOR(vector4,F64,0,3); 220 267 CREATE_AND_SET_VECTOR(vector5,F64,0,3); 221 CREATE_AND_SET_VECTOR(vector6,F64,0,3); 222 if ( psBinaryOp(vector6,vector4,"+",NULL) != NULL ) { 223 psError(PS_ERR_UNKNOWN, true,"psBinaryOp should return null when out and in1 valid but in2 null."); 224 return 10; 225 } 226 printFooter(stdout, "psMatrixVectorArithmetic", "Invalid input", true); 227 268 269 // Input parameter with dimension of PS_DIMEN_OTHER 270 printPositiveTestHeader(stdout,"psBinaryOp","Attempt to use input with PS_DIMEN_OTHER"); 271 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 228 272 vector4->type.dimen = PS_DIMEN_OTHER; 229 273 if ( psBinaryOp(NULL,vector4,"+",vector5) != NULL) { 230 274 psError(PS_ERR_UNKNOWN, true,"psBinaryOp should return null when input dimen PS_DIMEN_OTHER."); 231 return 1 1;275 return 19; 232 276 } 233 277 vector4->type.dimen = PS_DIMEN_VECTOR; 234 235 psScalar* inScalar = psScalarAlloc(0,PS_TYPE_F64); 236 CREATE_AND_SET_IMAGE(image10,F64,0,3,3); 237 if ( psBinaryOp(image10,inScalar,"+",vector4) == NULL ) { 238 psError(PS_ERR_UNKNOWN, true,"psBinaryOp should not return null when input/out dimension don't match."); 239 return 12; 240 } 278 printFooter(stdout,"psBinaryOp","Attempt to use input with PS_DIMEN_OTHER",true); 279 280 // Input parameter with dimension of PS_DIMEN_OTHER 281 printPositiveTestHeader(stdout,"psUnaryOp","Attempt to use input with PS_DIMEN_OTHER"); 282 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 283 vector4->type.dimen = PS_DIMEN_OTHER; 284 if ( psUnaryOp(NULL,vector4,"sin") != NULL ) { 285 psError(PS_ERR_UNKNOWN,true,"psUnaryOp should return null when input dimen PS_DIMEN_OTHER"); 286 return 20; 287 } 288 vector4->type.dimen = PS_DIMEN_VECTOR; 289 printFooter(stdout,"psUnaryOp","Attempt to use input with PS_DIMEN_OTHER",true); 241 290 242 291 psFree(vector4); 243 292 psFree(vector5); 293 psFree(image1); 294 psFree(image2); 295 psFree(image3); 296 psFree(image4); 297 psFree(image5); 298 psFree(vector1); 299 psFree(vector2); 300 301 psS32 nLeaks = psMemCheckLeaks(0,NULL,stdout,false); 302 if(nLeaks != 0) { 303 psError(PS_ERR_UNKNOWN,true,"Memory leaks detected"); 304 return 50; 305 } 306 psS32 nBad = psMemCheckCorruption(0); 307 if(nBad) { 308 psError(PS_ERR_UNKNOWN,true,"Memory corruption detected"); 309 return 51; 310 } 244 311 245 312 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.
