Changeset 13123 for trunk/psLib/test/math/tap_psSparse.c
- Timestamp:
- May 1, 2007, 6:14:33 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/math/tap_psSparse.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tap_psSparse.c
r12607 r13123 10 10 plan_tests(26); 11 11 12 // diag("psSparse() tests");13 14 12 // test psSparseSolve for a simple normal example matrix 15 13 { 16 14 psMemId id = psMemGetId(); 17 15 18 // diag ("solve a normalized matrix equation with psSparseSolve"); 16 //solve a normalized matrix equation with psSparseSolve 19 17 20 18 // the basic equation is Ax = b … … 28 26 skip_start(matrix == NULL, 5, "Skipping tests because psSparseAlloc() failed"); 29 27 30 for (int i = 0; i < 100; i++) 31 { 28 for (int i = 0; i < 100; i++) { 32 29 psSparseMatrixElement (matrix, i, i, 1.0); 33 30 if (i + 1 < 100) { … … 38 35 // incoming matrix elements do not need to be in order; sort before 39 36 // applying sparse matrix 40 psSparseResort (matrix);37 psSparseResort(matrix); 41 38 42 39 psVector *xRef = psVectorAlloc (100, PS_TYPE_F32); … … 46 43 } 47 44 48 psVector *bVec = psSparseMatrixTimesVector (NULL, matrix, xRef); 49 50 for (int i = 0; i < 100; i++) 51 { 52 psSparseVectorElement (matrix, i, bVec->data.F32[i]); 45 psVector *bVec = psSparseMatrixTimesVector(NULL, matrix, xRef); 46 47 for (int i = 0; i < 100; i++) { 48 psSparseVectorElement(matrix, i, bVec->data.F32[i]); 53 49 } 54 50 … … 59 55 60 56 // solve for normalization terms (need include local sky?) 61 psVector *xFit = psSparseSolve (NULL, constraint, matrix, 4);57 psVector *xFit = psSparseSolve(NULL, constraint, matrix, 4); 62 58 63 59 // measure stdev between xFit and xRes … … 89 85 psMemId id = psMemGetId(); 90 86 91 // diag ("solve a non-normalized matrix equation with psSparseSolve"); 92 87 //solve a non-normalized matrix equation with psSparseSolve 93 88 // the basic equation is Ax = b 94 95 89 // create a matrix A with diagonals of 1 and a small number of off diagonal elements. 96 90 // construct a vector x, construct the corresponding vector b by multiplication. solve … … 101 95 skip_start(matrix == NULL, 5, "Skipping tests because psSparseAlloc() failed"); 102 96 103 for (int i = 0; i < 100; i++) 104 { 97 for (int i = 0; i < 100; i++) { 105 98 psSparseMatrixElement (matrix, i, i, 5.0); 106 99 if (i + 1 < 100) { … … 111 104 // incoming matrix elements do not need to be in order; sort before 112 105 // applying sparse matrix 113 psSparseResort (matrix);106 psSparseResort(matrix); 114 107 115 108 psVector *xRef = psVectorAlloc (100, PS_TYPE_F32); … … 119 112 } 120 113 121 psVector *bVec = psSparseMatrixTimesVector (NULL, matrix, xRef); 122 123 for (int i = 0; i < 100; i++) 124 { 125 psSparseVectorElement (matrix, i, bVec->data.F32[i]); 114 psVector *bVec = psSparseMatrixTimesVector(NULL, matrix, xRef); 115 116 for (int i = 0; i < 100; i++) { 117 psSparseVectorElement(matrix, i, bVec->data.F32[i]); 126 118 } 127 119 … … 132 124 133 125 // solve for normalization terms (need include local sky?) 134 psVector *xFit = psSparseSolve (NULL, constraint, matrix, 4);126 psVector *xFit = psSparseSolve(NULL, constraint, matrix, 4); 135 127 136 128 // measure stdev between xFit and xRes … … 173 165 psMemId id = psMemGetId(); 174 166 175 // diag ("solve a simple, small matrix equation "); 167 //solve a simple, small matrix equation 176 168 177 169 // the basic equation (Ax = b) is: … … 192 184 skip_start(matrix == NULL, 5, "Skipping tests because psSparseAlloc() failed"); 193 185 194 psSparseMatrixElement (matrix, 0, 0, 1.0);195 psSparseMatrixElement (matrix, 1, 1, 1.0);196 psSparseMatrixElement (matrix, 1, 0, 0.1);197 psSparseResort (matrix);186 psSparseMatrixElement(matrix, 0, 0, 1.0); 187 psSparseMatrixElement(matrix, 1, 1, 1.0); 188 psSparseMatrixElement(matrix, 1, 0, 0.1); 189 psSparseResort(matrix); 198 190 199 191 // border region has a width of 1: … … 244 236 245 237 // supply the fVec and gVec data to the border 246 for (int i = 0; i < Nrows; i++) 247 { 248 psSparseVectorElement (border->sparse, i, fVec->data.F32[i]); 249 } 250 for (int i = 0; i < Nborder; i++) 251 { 252 psSparseBorderElementG (border, i, gVec->data.F32[i]); 238 for (int i = 0; i < Nrows; i++) { 239 psSparseVectorElement(border->sparse, i, fVec->data.F32[i]); 240 } 241 for (int i = 0; i < Nborder; i++) { 242 psSparseBorderElementG(border, i, gVec->data.F32[i]); 253 243 } 254 244 … … 262 252 psVector *xFit = NULL; 263 253 psVector *yFit = NULL; 264 psSparseBorderSolve (&xFit, &yFit, constraint, border, 4);254 psSparseBorderSolve(&xFit, &yFit, constraint, border, 4); 265 255 is_float_tol (xFit->data.F32[0], 1.0, 1e-4, "f(0): %f", xFit->data.F32[0]); 266 256 is_float_tol (xFit->data.F32[1], 1.0, 1e-4, "f(1): %f", xFit->data.F32[1]); … … 283 273 psMemId id = psMemGetId(); 284 274 285 // diag ("solve a simple, small matrix equation "); 275 // solve a simple, small matrix equation 286 276 287 277 // the basic equation (Ax = b) is: … … 302 292 skip_start(matrix == NULL, 5, "Skipping tests because psSparseAlloc() failed"); 303 293 304 for (int i = 0; i < Nrows; i++) 305 { 306 psSparseMatrixElement (matrix, i, i, 1.0); 294 for (int i = 0; i < Nrows; i++) { 295 psSparseMatrixElement(matrix, i, i, 1.0); 307 296 if (i + 1 < Nrows) { 308 psSparseMatrixElement (matrix, i + 1, i, 0.1);309 } 310 } 311 psSparseResort (matrix);297 psSparseMatrixElement(matrix, i + 1, i, 0.1); 298 } 299 } 300 psSparseResort(matrix); 312 301 313 302 // border region has a width of 1: … … 349 338 350 339 // supply the fVec and gVec data to the border 351 for (int i = 0; i < Nrows; i++) 352 { 353 psSparseVectorElement (border->sparse, i, fVec->data.F32[i]); 354 } 355 for (int i = 0; i < Nborder; i++) 356 { 357 psSparseBorderElementG (border, i, gVec->data.F32[i]); 340 for (int i = 0; i < Nrows; i++) { 341 psSparseVectorElement(border->sparse, i, fVec->data.F32[i]); 342 } 343 for (int i = 0; i < Nborder; i++) { 344 psSparseBorderElementG(border, i, gVec->data.F32[i]); 358 345 } 359 346 … … 367 354 psVector *xFit = NULL; 368 355 psVector *yFit = NULL; 369 psSparseBorderSolve (&xFit, &yFit, constraint, border, 4);356 psSparseBorderSolve(&xFit, &yFit, constraint, border, 4); 370 357 371 358 // measure stdev between xFit and xRef
Note:
See TracChangeset
for help on using the changeset viewer.
