Changeset 24087
- Timestamp:
- May 6, 2009, 2:19:50 PM (17 years ago)
- Location:
- trunk/psLib/test/math
- Files:
-
- 4 added
- 2 edited
-
Makefile.am (modified) (1 diff)
-
data (added)
-
data/Agj.fits (added)
-
data/Bgj.fits (added)
-
data/input (added)
-
tap_psMatrix08.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/Makefile.am
r24019 r24087 48 48 tap_psMatrixVectorArithmetic01 \ 49 49 tap_psMatrixVectorArithmetic04 \ 50 tap_psRandom \51 50 tap_psMinimizePowell \ 52 51 tap_psSpline1D \ 53 52 tap_psPolynomialMD 53 54 # tap_psRandom 54 55 55 56 if BUILD_TESTS -
trunk/psLib/test/math/tap_psMatrix08.c
r24020 r24087 1 1 /** @file tap_psMatrix_08.c 2 2 * 3 * @brief Test driver for psMatrix transpose function 4 * 5 * This test driver contains the following tests: 6 * Transpose input image into output image 7 * Transpose input image into auto allocated NULL output image 8 * 9 * @author Ross Harman, MHPCC 3 * @brief psMatrixLUSolve, psMatrixGJSolve tests (for ill-conditioned matrix) 4 * @author Eugene Magnier, IfA 10 5 * 11 6 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 12 7 * @date $Date: 2007-05-02 04:20:06 $ 13 8 * 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii9 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii 15 10 * 16 11 */ … … 21 16 #include "pstap.h" 22 17 23 # if (0) 24 bool check_matrix(psImage *img) 25 { 26 bool errorFlag = false; 27 28 for(psU32 i=0; i<img->numRows; i++) { 29 for(psU32 j=0; j<img->numCols; j++) { 30 if(img->type.type == PS_TYPE_F64) { 31 if(fabs(img->data.F64[i][j]-truthMatrix[i][j]) > TOLERANCE) { 32 diag("Matrix values at element %d, %d don't agree %lf vs %lf\n", i, j, 33 img->data.F64[i][j], truthMatrix[i][j]); 34 errorFlag = true; 35 } 36 } else if(img->type.type == PS_TYPE_F32) { 37 if(fabs(img->data.F32[i][j]-truthMatrix[i][j]) > TOLERANCE) { 38 diag("Matrix values at element %d, %d don't agree %f vs %lf\n", i, j, 39 img->data.F32[i][j], truthMatrix[i][j]); 40 errorFlag = true; 41 } 42 } 43 } 44 } 45 return(errorFlag); 46 } 47 # endif 18 # define DEBUG 1 48 19 49 20 psS32 main( psS32 argc, char* argv[] ) 50 21 { 51 plan_tests(14); 22 plan_tests(23); 23 // psTraceSetLevel("psLib.math.psMatrixGJSolve", 4); 52 24 53 25 // Transpose input image into output image … … 55 27 psMemId id = psMemGetId(); 56 28 57 // we have a specific image which gave us trouble elsewhere: 58 psImage *inImage = psImageAlloc(2, 2, PS_TYPE_F64); 59 inImage->data.F64[0][0] = 0.0; 60 inImage->data.F64[0][1] = -0.000100588316855; 61 inImage->data.F64[1][0] = +0.000100588316855; 62 inImage->data.F64[1][1] = 4.4276353417e-11; 63 64 psVector *inVector = psVectorAlloc (2, PS_TYPE_F64); 65 inVector->data.F64[0] = 0.0; 66 inVector->data.F64[1] = 9.06388443347e-08; 29 psFits *fits = NULL; 30 31 // we have a specific image and vector pair which gave us trouble elsewhere: 32 // XXX this is an ill-conditioned matrix. LU Decomposition does not inform us that it is ill-conditioned. 33 // the result solves the equation, but what are the errors on the values? 34 fits = psFitsOpen ("data/Agj.fits", "r"); 35 ok(fits, "opened test image Agj.fits"); 36 37 psImage *Aimage = psFitsReadImage (fits, psRegionSet(0,0,0,0), 0); 38 ok(Aimage, "loaded test image Agj.fits"); 39 40 psImage *aimage = psImageCopy (NULL, Aimage, Aimage->type.type); 41 ok(aimage, "copied test image Agj.fits"); 42 43 psFitsClose (fits); 44 45 fits = psFitsOpen ("data/Bgj.fits", "r"); 46 ok(fits, "opened test image Bgj.fits"); 47 48 psImage *Bimage = psFitsReadImage (fits, psRegionSet(0,0,0,0), 0); 49 ok(Aimage, "loaded test image Bgj.fits"); 50 51 psFitsClose (fits); 52 53 psVector *Bvector = psVectorAlloc (Bimage->numRows, Bimage->type.type); 54 ok(Bvector, "allocated B vector"); 55 56 for (int i = 0; i < Bimage->numRows; i++) { 57 double value = psImageGet (Bimage, 0, i); 58 psVectorSet (Bvector, i, value); 59 } 67 60 68 61 bool status; 69 status = psMatrixGJSolveF32(inImage, inVector); 70 ok(status, "psMatrixGJSolve returns true exit status"); 71 psFree(inImage); 72 psFree(inVector); 62 status = psMatrixLUSolve(Aimage, Bvector); 63 ok(!status, "psMatrixLUSolve correctly returns false for ill-conditioned matrix"); 64 65 # if (DEBUG) 66 fprintf (stderr, "LU Solution:\n"); 67 for (int i = 0; i < Bimage->numRows; i++) { 68 double value = psVectorGet (Bvector, i); 69 double valerr = psImageGet (Aimage, i, i); 70 fprintf (stderr, "%f +/- %f\n", value, valerr); 71 } 72 73 // calculate Ax and compare with B: 74 fprintf (stderr, "result:\n"); 75 for (int i = 0; i < Bimage->numRows; i++) { 76 double value = 0; 77 for (int j = 0; j < Bvector->n; j++) { 78 double tmpV = psVectorGet (Bvector, j); 79 double tmpI = psImageGet (aimage, j, i); 80 value += tmpV*tmpI; 81 } 82 double actual = psImageGet (Bimage, 0, i); 83 fprintf (stderr, "%f vs %f (delta: %f)\n", value, actual, actual - value); 84 } 85 # endif 86 87 psFree(Aimage); 88 psFree(Bimage); 89 psFree(Bvector); 90 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 91 } 92 93 // Transpose input image into output image 94 { 95 psMemId id = psMemGetId(); 96 97 psFits *fits = NULL; 98 99 // we have a specific ill-conditioned matrix in Agj.fits. psMatrixGJSolve detects this and reports a failure. 100 fits = psFitsOpen ("data/Agj.fits", "r"); 101 ok(fits, "opened test image Agj.fits"); 102 103 psImage *Aimage = psFitsReadImage (fits, psRegionSet(0,0,0,0), 0); 104 ok(Aimage, "loaded test image Agj.fits"); 105 106 psFitsClose (fits); 107 108 fits = psFitsOpen ("data/Bgj.fits", "r"); 109 ok(fits, "opened test image Bgj.fits"); 110 111 psImage *Bimage = psFitsReadImage (fits, psRegionSet(0,0,0,0), 0); 112 ok(Bimage, "loaded test image Bgj.fits"); 113 114 psFitsClose (fits); 115 116 psVector *Bvector = psVectorAlloc (Bimage->numRows, Bimage->type.type); 117 ok(Bvector, "allocated B vector"); 118 119 for (int i = 0; i < Bimage->numRows; i++) { 120 double value = psImageGet (Bimage, 0, i); 121 psVectorSet (Bvector, i, value); 122 } 123 124 bool status; 125 status = psMatrixGJSolve(Aimage, Bvector); 126 ok(!status, "psMatrixGJSolve correctly returns false for ill-conditioned matrix"); 127 128 # if (DEBUG) 129 fprintf (stderr, "GJ Solution:\n"); 130 for (int i = 0; i < Bimage->numRows; i++) { 131 double value = psVectorGet (Bvector, i); 132 fprintf (stderr, "%f\n", value); 133 } 134 # endif 135 136 psFree(Aimage); 137 psFree(Bimage); 138 psFree(Bvector); 139 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 140 } 141 142 // Transpose input image into output image 143 { 144 psMemId id = psMemGetId(); 145 146 psFits *fits = NULL; 147 148 // we have a specific ill-conditioned matrix in Agj.fits. psMatrixGJSolve detects this and reports a failure. 149 fits = psFitsOpen ("data/Agj.fits", "r"); 150 ok(fits, "opened test image Agj.fits"); 151 152 psImage *aimage = psFitsReadImage (fits, psRegionSet(0,0,0,0), 0); 153 ok(aimage, "loaded test image Agj.fits"); 154 155 psImage *Aimage = psImageCopy (NULL, aimage, PS_TYPE_F64); 156 ok(Aimage, "converted test image to F64"); 157 158 psFitsClose (fits); 159 160 fits = psFitsOpen ("data/Bgj.fits", "r"); 161 ok(fits, "opened test image Bgj.fits"); 162 163 psImage *bimage = psFitsReadImage (fits, psRegionSet(0,0,0,0), 0); 164 ok(bimage, "loaded test image Bgj.fits"); 165 166 psImage *Bimage = psImageCopy (NULL, bimage, PS_TYPE_F64); 167 ok(Bimage, "converted test image to F64"); 168 169 psFitsClose (fits); 170 171 psVector *Bvector = psVectorAlloc (Bimage->numRows, Bimage->type.type); 172 ok(Bvector, "allocated B vector"); 173 174 for (int i = 0; i < Bimage->numRows; i++) { 175 double value = psImageGet (Bimage, 0, i); 176 psVectorSet (Bvector, i, value); 177 } 178 179 bool status; 180 status = psMatrixGJSolve(Aimage, Bvector); 181 ok(!status, "psMatrixGJSolve correctly returns false for ill-conditioned matrix"); 182 183 # if (DEBUG) 184 fprintf (stderr, "GJ Solution:\n"); 185 for (int i = 0; i < Bimage->numRows; i++) { 186 double value = psVectorGet (Bvector, i); 187 double valerr = psImageGet (Aimage, i, i); 188 fprintf (stderr, "%f +/- %f\n", value, valerr); 189 } 190 191 // calculate Ax and compare with B: 192 fprintf (stderr, "result:\n"); 193 for (int i = 0; i < Bimage->numRows; i++) { 194 double value = 0; 195 for (int j = 0; j < Bvector->n; j++) { 196 double tmpV = psVectorGet (Bvector, j); 197 double tmpI = psImageGet (aimage, j, i); 198 value += tmpV*tmpI; 199 } 200 double actual = psImageGet (Bimage, 0, i); 201 fprintf (stderr, "%f vs %f (delta: %f)\n", value, actual, actual - value); 202 } 203 # endif 204 205 psFree(Aimage); 206 psFree(Bimage); 207 psFree(aimage); 208 psFree(bimage); 209 psFree(Bvector); 73 210 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 74 211 }
Note:
See TracChangeset
for help on using the changeset viewer.
