Changeset 10170 for trunk/psLib/test/math/tap_psSparse.c
- Timestamp:
- Nov 22, 2006, 7:27:06 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/math/tap_psSparse.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tap_psSparse.c
r10015 r10170 8 8 int main (void) 9 9 { 10 plan_tests(2 3);10 plan_tests(26); 11 11 12 12 diag("psSparse() tests"); 13 13 14 // test psSparseSolve for a simple example matrix14 // test psSparseSolve for a simple normal example matrix 15 15 { 16 16 psMemId id = psMemGetId(); 17 17 18 diag ("solve a simple, small matrix equation");18 diag ("solve a normalized matrix equation with psSparseSolve"); 19 19 20 20 // the basic equation is Ax = b … … 31 31 { 32 32 psSparseMatrixElement (matrix, i, i, 1.0); 33 if (i + 1 < 100) { 34 psSparseMatrixElement (matrix, i + 1, i, 0.1); 35 } 36 } 37 38 // incoming matrix elements do not need to be in order; sort before 39 // applying sparse matrix 40 psSparseResort (matrix); 41 42 psVector *xRef = psVectorAlloc (100, PS_TYPE_F32); 43 for (int i = 0; i < 100; i++) 44 { 45 xRef->data.F32[i] = 1.0; 46 } 47 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]); 53 } 54 55 psSparseConstraint constraint; 56 constraint.paramMin = 0.0; 57 constraint.paramMax = 1e8; 58 constraint.paramDelta = 1e8; 59 60 // solve for normalization terms (need include local sky?) 61 psVector *xFit = psSparseSolve (NULL, constraint, matrix, 4); 62 63 // measure stdev between xFit and xRes 64 float dS = 0; 65 float dS2 = 0; 66 for (int i = 0; i < 100; i++) 67 { 68 float dX = xRef->data.F32[i] - xFit->data.F32[i]; 69 // fprintf (stderr, "%5.3f %5.3f %5.3f %5.3f\n", bVec->data.F32[i], xRef->data.F32[i], xFit->data.F32[i], dX); 70 dS2 += PS_SQR(dX); 71 dS += dX; 72 } 73 dS /= 100.0; 74 dS2 = sqrt (dS2/100.0 - dS*dS); 75 76 ok_float_tol (dS2, 0.0, 1e-4, "scatter: %.20f", dS2); 77 78 psFree (matrix); 79 psFree (xRef); 80 psFree (bVec); 81 psFree (xFit); 82 83 skip_end(); 84 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 85 } 86 87 // test psSparseSolve for a simple non-normal example matrix 88 { 89 psMemId id = psMemGetId(); 90 91 diag ("solve a non-normalized matrix equation with psSparseSolve"); 92 93 // the basic equation is Ax = b 94 95 // create a matrix A with diagonals of 1 and a small number of off diagonal elements. 96 // construct a vector x, construct the corresponding vector b by multiplication. solve 97 // Ax = b for x using psSparseSolve. compare with the input values for x. 98 99 psSparse *matrix = psSparseAlloc (100, 100); 100 ok(matrix != NULL, "psSparse successfully allocated"); 101 skip_start(matrix == NULL, 5, "Skipping tests because psSparseAlloc() failed"); 102 103 for (int i = 0; i < 100; i++) 104 { 105 psSparseMatrixElement (matrix, i, i, 5.0); 33 106 if (i + 1 < 100) { 34 107 psSparseMatrixElement (matrix, i + 1, i, 0.1);
Note:
See TracChangeset
for help on using the changeset viewer.
