Changeset 4580 for trunk/psLib/test/math/tst_psFunc07.c
- Timestamp:
- Jul 18, 2005, 4:55:54 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/math/tst_psFunc07.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tst_psFunc07.c
r4547 r4580 9 9 XXX: The spline eval functions are F32 only, while the spline fit functions 10 10 are F32 and F64. 11 12 XXX: Must call the spline fit functions with unallowable input parameters. 11 13 *****************************************************************************/ 12 14 #include <stdio.h> … … 17 19 #include "psFunctions.h" 18 20 21 #define VERBOSE 0 19 22 #define NUM_SPLINES 50 20 23 #define A 4.0 … … 51 54 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 52 55 y = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 53 tmpSpline = psSpline1DAlloc(NUM_SPLINES, 3, MIN, MAX); 56 57 58 psF32 width = (MAX - MIN) / ((psF32) NUM_SPLINES); 59 x->data.F32[0] = MIN; 60 for (psS32 i=1;i<NUM_SPLINES;i++) { 61 x->data.F32[i] = MIN + (width * (psF32) i); 62 } 63 x->data.F32[NUM_SPLINES] = MAX; 54 64 55 65 for (i=0;i<NUM_SPLINES+1;i++) { 56 x->data.F32[i] = tmpSpline->knots->data.F32[i];57 66 y->data.F32[i] = myFunc(x->data.F32[i]); 58 67 } … … 69 78 "psSpline1DAlloc(), psVectorFitSpline1D, psSpline1DEvalVector: F32 versions"); 70 79 71 psVectorFitSpline1D(tmpSpline, x, y, NULL); 72 newY = psSpline1DEvalVector( 73 tmpSpline, 74 newX 75 ); 76 77 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 78 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) { 79 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 80 newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i])); 81 testStatus = false; 80 tmpSpline = psVectorFitSpline1DNEW(x, y, NUM_SPLINES); 81 if (tmpSpline == NULL) { 82 printf("TEST ERROR: psVectorFitSpline1DNEW() returned NULL.\n"); 83 testStatus = false; 84 } else { 85 newY = psSpline1DEvalVector(tmpSpline, newX); 86 87 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 88 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) { 89 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 90 newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i])); 91 testStatus = false; 92 } else { 93 if (VERBOSE) { 94 printf("COOL[%d]: f(%f) is %f. Should be %f\n", i, 95 newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i])); 96 } 97 } 82 98 } 83 } 84 99 psFree(tmpSpline); 100 psFree(newY); 101 } 85 102 psFree(x); 103 psFree(y); 86 104 psFree(newX); 87 psFree(y);88 psFree(tmpSpline);89 psFree(newY);90 105 91 106 psMemCheckCorruption(1); … … 123 138 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F64); 124 139 y = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F64); 125 tmpSpline = psSpline1DAlloc(NUM_SPLINES, 3, MIN, MAX); 140 141 psF64 width = (MAX - MIN) / ((psF32) NUM_SPLINES); 142 x->data.F64[0] = MIN; 143 for (psS32 i=1;i<NUM_SPLINES;i++) { 144 x->data.F64[i] = MIN + (width * (psF64) i); 145 } 146 x->data.F64[NUM_SPLINES] = MAX; 126 147 127 148 for (i=0;i<NUM_SPLINES+1;i++) { 128 x->data.F64[i] = tmpSpline->knots->data.F32[i];129 149 y->data.F64[i] = myFunc(x->data.F64[i]); 130 150 } … … 141 161 "psSpline1DAlloc(), psVectorFitSpline1D, psSpline1DEvalVector: F64 versions"); 142 162 143 psVectorFitSpline1D(tmpSpline, x, y, NULL); 144 newY = psSpline1DEvalVector( 145 tmpSpline, 146 newX 147 ); 148 149 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 150 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F64[i]) ) > fabs( ERROR_TOLERANCE * myFunc((float)newX->data.F64[i]) ) ) { 151 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 152 newX->data.F64[i], newY->data.F32[i], myFunc((float)newX->data.F64[i])); 153 testStatus = false; 163 tmpSpline = psVectorFitSpline1DNEW(x, y, NUM_SPLINES); 164 if (tmpSpline == NULL) { 165 printf("TEST ERROR: psVectorFitSpline1DNEW() returned NULL.\n"); 166 testStatus = false; 167 } else { 168 newY = psSpline1DEvalVector(tmpSpline, newX); 169 170 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 171 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F64[i]) ) > fabs( ERROR_TOLERANCE * myFunc((float)newX->data.F64[i]) ) ) { 172 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 173 newX->data.F64[i], newY->data.F32[i], myFunc((float)newX->data.F64[i])); 174 testStatus = false; 175 } else { 176 if (VERBOSE) { 177 printf("COOL[%d]: f(%f) is %f. Should be %f\n", i, 178 newX->data.F64[i], newY->data.F32[i], myFunc((float)newX->data.F64[i])); 179 } 180 } 154 181 } 155 } 156 182 psFree(tmpSpline); 183 psFree(newY); 184 } 157 185 psFree(x); 158 186 psFree(newX); 159 187 psFree(y); 160 psFree(tmpSpline);161 psFree(newY);162 188 163 189 psMemCheckCorruption(1); … … 177 203 psS32 main() 178 204 { 179 // t00(); 205 psLogSetFormat("HLNM"); 206 t00(); 180 207 t01(); 181 208 }
Note:
See TracChangeset
for help on using the changeset viewer.
