Changeset 2683 for trunk/psLib/test/dataManip/tst_psMatrix03.c
- Timestamp:
- Dec 10, 2004, 9:11:23 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psMatrix03.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psMatrix03.c
r2392 r2683 14 14 * @author Ross Harman, MHPCC 15 15 * 16 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $17 * @date $Date: 2004-1 1-22 21:00:21$16 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2004-12-10 19:11:23 $ 18 18 * 19 19 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psTest.h" 25 25 26 #define PRINT_MATRIX(IMAGE) \ 27 for(psS32 i=IMAGE->numRows-1; i>-1; i--) { \ 28 for(psS32 j=0; j<IMAGE->numCols; j++) { \ 29 printf("%f ", IMAGE->data.F64[i][j]); \ 30 } \ 31 printf("\n"); \ 26 #define TOLERANCE 0.000001 27 28 #define CHECK_MATRIX(IMAGE) \ 29 for(psU32 i=0; i<IMAGE->numRows; i++) { \ 30 for(psU32 j=0; j<IMAGE->numCols; j++) { \ 31 if(IMAGE->type.type == PS_TYPE_F64) { \ 32 if(fabs(IMAGE->data.F64[i][j]-truthMatrix[i][j]) > TOLERANCE) { \ 33 printf("Matrix values at element %d, %d don't agree %lf vs %lf\n", i, j, \ 34 IMAGE->data.F64[i][j], truthMatrix[i][j]); \ 35 } \ 36 } else if(IMAGE->type.type == PS_TYPE_F32){ \ 37 if(fabs(IMAGE->data.F32[i][j]-truthMatrix[i][j]) > TOLERANCE) { \ 38 printf("%lf\n", fabs(IMAGE->data.F32[i][j]-truthMatrix[i][j])), \ 39 printf("Matrix values at element %d, %d don't agree %f vs %lf\n", i, j, \ 40 IMAGE->data.F32[i][j], truthMatrix[i][j]); \ 41 } \ 42 } \ 43 } \ 32 44 } 33 \ 34 #define PRINT_VECTOR(VECTOR) \ 35 for(psS32 i=0; i<VECTOR->n; i++) { \ 36 printf("%f\n", VECTOR->data.F64[i]); \ 45 46 #define CHECK_VECTOR(VECTOR) \ 47 for(psU32 i=0; i<VECTOR->n; i++) { \ 48 if(VECTOR->type.type == PS_TYPE_F64) { \ 49 if(fabs(VECTOR->data.F64[i]-truthVector[i]) > TOLERANCE) { \ 50 printf("Vector values at element %d don't agree %lf vs %lf\n", i, \ 51 VECTOR->data.F64[i], truthVector[i]); \ 52 } \ 53 } else if(VECTOR->type.type == PS_TYPE_F32){ \ 54 if(fabs(VECTOR->data.F32[i]-truthVector[i]) > TOLERANCE) { \ 55 printf("Vector values at element %d don't agree %f vs %lf\n", i, \ 56 VECTOR->data.F32[i], truthVector[i]); \ 57 } \ 58 } \ 37 59 } 38 60 39 61 40 psS32 main(psS32 argc, 41 char* argv[]) 62 psS32 main(psS32 argc, char* argv[]) 42 63 { 43 64 psImage *luImage = NULL; … … 48 69 psVector *outVector = NULL; 49 70 psVector *inVector = NULL; 71 psImage *luImage32 = NULL; 72 psImage *inImage32 = NULL; 73 psImage *tempImage32 = NULL; 74 psVector *tempVector32 = NULL; 75 psVector *perm32 = NULL; 76 psVector *outVector32 = NULL; 77 psVector *inVector32 = NULL; 78 79 double truthVector[3] = { 80 4.000000, 81 -2.000000, 82 3.000000 83 }; 84 85 double truthMatrix[3][3] = {{4.000000, 5.000000, 6.000000}, 86 {0.750000, -2.750000, -6.500000}, 87 {0.500000, -0.545455, -0.545455}}; 50 88 51 89 … … 70 108 inVector->data.F64[2] = 4.0; 71 109 inVector->n = 3; 72 PRINT_MATRIX(inImage); 73 printf("\n"); 74 PRINT_VECTOR(inVector); 110 luImage32 = (psImage*)psImageAlloc(3, 3, PS_TYPE_F32); 111 perm32 = (psVector*)psVectorAlloc(3, PS_TYPE_F32); 112 outVector32 = (psVector*)psVectorAlloc(3, PS_TYPE_F32); 113 inVector32 = (psVector*)psVectorAlloc(3, PS_TYPE_F32); 114 inImage32 = (psImage*)psImageAlloc(3, 3, PS_TYPE_F32); 115 inImage32->data.F32[0][0] = 2; 116 inImage32->data.F32[0][1] = 4; 117 inImage32->data.F32[0][2] = 6; 118 inImage32->data.F32[1][0] = 4; 119 inImage32->data.F32[1][1] = 5; 120 inImage32->data.F32[1][2] = 6; 121 inImage32->data.F32[2][0] = 3; 122 inImage32->data.F32[2][1] = 1; 123 inImage32->data.F32[2][2] = -2; 124 inVector32->data.F32[0] = 18.0; 125 inVector32->data.F32[1] = 24.0; 126 inVector32->data.F32[2] = 4.0; 127 inVector32->n = 3; 75 128 printFooter(stdout, "psMatrix", "Create input and output images and vectors", true); 76 129 … … 80 133 tempImage = luImage; 81 134 luImage = psMatrixLUD(luImage, perm, inImage); 82 PRINT_MATRIX(luImage);135 CHECK_MATRIX(luImage); 83 136 if(luImage->type.dimen != PS_DIMEN_IMAGE) { 84 137 printf("Error: Resulting image is not PS_DIMEN_IMAGE\n"); 85 } else 86 if(luImage != tempImage) { 87 printf("Error: Return pointer not equal to output argument pointer\n"); 88 } 138 } else if(luImage != tempImage) { 139 printf("Error: Return pointer not equal to output argument pointer\n"); 140 } 141 142 tempImage32 = luImage32; 143 luImage32 = psMatrixLUD(luImage32, perm32, inImage32); 144 CHECK_MATRIX(luImage32); 145 if(luImage32->type.dimen != PS_DIMEN_IMAGE) { 146 printf("Error: Resulting image is not PS_DIMEN_IMAGE\n"); 147 } else if(luImage32 != tempImage32) { 148 printf("Error: Return pointer not equal to output argument pointer\n"); 149 } 89 150 printFooter(stdout, "psMatrix", "Calculate LU matrix", true); 90 151 … … 94 155 tempVector = outVector; 95 156 outVector = psMatrixLUSolve(outVector, luImage, inVector, perm); 96 PRINT_VECTOR(outVector);157 CHECK_VECTOR(outVector); 97 158 if(outVector->type.dimen != PS_DIMEN_VECTOR) { 98 159 printf("Error: Resulting image is not PS_DIMEN_VECTOR\n"); 99 } else 100 if(outVector != tempVector) { 101 printf("Error: Return pointer not equal to output argument pointer\n"); 102 } 160 } else if(outVector != tempVector) { 161 printf("Error: Return pointer not equal to output argument pointer\n"); 162 } 163 164 tempVector32 = outVector32; 165 outVector32 = psMatrixLUSolve(outVector32, luImage32, inVector32, perm32); 166 CHECK_VECTOR(outVector32); 167 if(outVector32->type.dimen != PS_DIMEN_VECTOR) { 168 printf("Error: Resulting image is not PS_DIMEN_VECTOR\n"); 169 } else if(outVector32 != tempVector32) { 170 printf("Error: Return pointer not equal to output argument pointer\n"); 171 } 103 172 printFooter(stdout, "psMatrix", "Determine solution to matrix equation", true); 104 173 … … 111 180 psFree(outVector); 112 181 psFree(inVector); 182 psFree(inImage32); 183 psFree(luImage32); 184 psFree(perm32); 185 psFree(outVector32); 186 psFree(inVector32); 113 187 if( psMemCheckLeaks(0, NULL, stdout, false) ) { 114 188 psError(PS_ERR_UNKNOWN,true,"Memory leaks detected");
Note:
See TracChangeset
for help on using the changeset viewer.
