Changeset 4995
- Timestamp:
- Sep 12, 2005, 10:31:24 AM (21 years ago)
- Location:
- trunk/psLib/test/math
- Files:
-
- 2 added
- 5 edited
-
Makefile.am (modified) (2 diffs)
-
tst_psMinimize04.c (modified) (6 diffs)
-
tst_psMinimize04_F32.c (modified) (4 diffs)
-
tst_psMinimize04b.c (modified) (5 diffs)
-
tst_psMinimize04b_F32.c (modified) (5 diffs)
-
tst_psMinimizeVector2D_F32.c (added)
-
tst_psMinimizeVector2D_F64.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/Makefile.am
r4981 r4995 37 37 tst_psMinimize05 \ 38 38 tst_psMinimize06 \ 39 tst_psMinimizeVector2D_F64 \ 40 tst_psMinimizeVector2D_F32 \ 41 tst_psMinimizeVector2D_F64Clipped \ 39 42 tst_psStats00 \ 40 43 tst_psStats01 \ … … 75 78 tst_psMatrixVectorArithmetic04_SOURCES = tst_psMatrixVectorArithmetic04.c 76 79 tst_psMinimize04_SOURCES = tst_psMinimize04.c 77 tst_psMinimize04_F32_SOURCES = tst_psMinimize04 .c80 tst_psMinimize04_F32_SOURCES = tst_psMinimize04_F32.c 78 81 tst_psMinimize04b_SOURCES = tst_psMinimize04b.c 79 tst_psMinimize04b_F32_SOURCES = tst_psMinimize04b.c 82 tst_psMinimize04b_F32_SOURCES = tst_psMinimize04b_F32.c 83 tst_psMinimizeVector2D_F64_SOURCES = tst_psMinimizeVector2D_F64.c 84 tst_psMinimizeVector2D_F32_SOURCES = tst_psMinimizeVector2D_F32.c 85 tst_psMinimizeVector2D_F64Clipped_SOURCES = tst_psMinimizeVector2D_F64Clipped.c 80 86 tst_psMinimize05_SOURCES = tst_psMinimize05.c 81 87 tst_psMinimize06_SOURCES = tst_psMinimize06.c -
trunk/psLib/test/math/tst_psMinimize04.c
r4973 r4995 1 1 /***************************************************************************** 2 This routine must ensure that the psVectorFitPolynomial 1D works correctly.2 This routine must ensure that the psVectorFitPolynomial2D works correctly. 3 3 We create a vectors of data points (x and y), and populate them with the 4 4 values from an arbitrary function setData(). We then call 5 psVectorFitPolynomial 1D() with a regular polynomial data structure. We then5 psVectorFitPolynomial2D() with a regular polynomial data structure. We then 6 6 evaluate the polynomial with the coefficients generated above and determine 7 7 if they are within an error tolerance of the expected values. … … 25 25 #define B 2.0 26 26 #define C 3.0 27 #define D 3.0 28 #define E 3.0 29 #define F 3.0 27 30 #define ERROR_TOLERANCE 0.10 28 #define YERR 1.0 29 double setData(double x) 31 #define FERR 1.0 32 #define PRINT_RESULTS 0 33 34 double setData(double x, double y) 30 35 { 31 return(A + (B * x) + (C * x * x) );36 return(A + (B * x) + (C * x * x) + (D * y) + (E * y * y) + (E * x * y)); 32 37 } 33 38 34 39 psS32 t00() 35 40 { 36 psPolynomial1D *myPoly = NULL;37 psVector *x = NULL;38 psVector *y = NULL;39 psVector *yErr = NULL;40 psS32 i = 0;41 41 psS32 currentId = psMemGetId(); 42 42 psS32 testStatus = true; … … 45 45 double actualData; 46 46 47 myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_ORD); 48 x = psVectorAlloc(NUM_DATA, PS_TYPE_F64); 49 y = psVectorAlloc(NUM_DATA, PS_TYPE_F64); 50 yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F64); 47 psPolynomial2D *myPoly = psPolynomial2DAlloc(POLY_ORDER+1, POLY_ORDER+1, PS_POLYNOMIAL_ORD); 48 psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32); 49 psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32); 50 psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32); 51 psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32); 51 52 52 for ( i=0;i<NUM_DATA;i++) {53 x->data.F 64[i] = (double) i;54 y->data.F 64[i] = setData(x->data.F64[i]);55 yErr->data.F64[i] = YERR;56 // printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);53 for (psS32 i=0;i<NUM_DATA;i++) { 54 x->data.F32[i] = (double) i; 55 y->data.F32[i] = (double) i; 56 f->data.F32[i] = setData(x->data.F32[i], y->data.F32[i]); 57 fErr->data.F32[i] = FERR; 57 58 } 58 59 59 60 printPositiveTestHeader(stdout, 60 61 "psMinimize functions", 61 "psVectorFitPolynomial 1D(): equal difference in variable yErr");62 "psVectorFitPolynomial2D(): equal difference in variable fErr"); 62 63 63 psVectorFitPolynomial1D(myPoly, x, y, yErr); 64 printf("TEST: calling psVectorFitPolynomial2D() with f, fErr, y, x as F32 vectors.\n"); 65 psVectorFitPolynomial2D(myPoly, NULL, 0, f, fErr, x, y); 64 66 65 67 // for (i=0;i<POLY_ORDER+1;i++) { … … 67 69 // } 68 70 69 for (i=0;i<NUM_DATA;i++) { 70 expectData = setData(x->data.F64[i]); 71 actualData = psPolynomial1DEval( 72 myPoly, 73 x->data.F64[i] 74 ); 71 for (psS32 i=0;i<NUM_DATA;i++) { 72 expectData = setData(x->data.F32[i], y->data.F32[i]); 73 actualData = psPolynomial2DEval(myPoly, x->data.F32[i], y->data.F32[i]); 75 74 if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) { 76 printf("ERROR: Fitted data %d: (%.1f %.1f ), expected was (%.1f)\n",77 i, x->data.F 64[i], actualData, expectData);75 printf("ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n", 76 i, x->data.F32[i], y->data.F32[i], actualData, expectData); 78 77 testStatus = false; 79 78 } 80 // } else { 81 // printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n", 82 // i, x->data.F64[i], actualData, expectData); 83 // } 79 if (PRINT_RESULTS) { 80 printf("Data point [%d] is %f, should be %f.\n", i, actualData, expectData); 81 } 82 } 83 84 85 printf("Running test with fErr set to NULL.\n"); 86 psVectorFitPolynomial2D(myPoly, NULL, 0, f, NULL, x, y); 87 for (psS32 i=0;i<NUM_DATA;i++) { 88 expectData = setData(x->data.F32[i], y->data.F32[i]); 89 actualData = psPolynomial2DEval(myPoly, x->data.F32[i], y->data.F32[i]); 90 if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) { 91 printf("ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n", 92 i, x->data.F32[i], y->data.F32[i], actualData, expectData); 93 testStatus = false; 94 } 95 if (PRINT_RESULTS) { 96 printf("Data point [%d] is %f, should be %f.\n", i, actualData, expectData); 97 } 98 } 99 psFree(myPoly); 100 101 printf("Running test with x, y set to NULL. Should generate error.\n"); 102 myPoly = psVectorFitPolynomial2D(NULL, NULL, 0, f, fErr, NULL, NULL); 103 if (myPoly != NULL) { 104 printf("TEST ERROR: psVectorFitPolynomial2D() returned non-NULL.\n"); 105 testStatus = false; 84 106 } 85 107 86 108 psMemCheckCorruption(1); 87 psFree(myPoly);88 109 psFree(x); 89 110 psFree(y); 90 psFree(yErr); 111 psFree(f); 112 psFree(fErr); 91 113 psMemCheckCorruption(1); 92 114 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false); … … 97 119 printFooter(stdout, 98 120 "psMinimize functions", 99 "psVectorFitPolynomial 1D(): equal differences in variable yErr",121 "psVectorFitPolynomial2D(): equal differences in variable fErr", 100 122 testStatus); 101 123 … … 103 125 } 104 126 105 psS32 t01()106 {107 psPolynomial1D *myPoly = NULL;108 psVector *x = NULL;109 psVector *y = NULL;110 psS32 i = 0;111 psS32 currentId = psMemGetId();112 psS32 testStatus = true;113 psS32 memLeaks = 0;114 double expectData;115 double actualData;116 117 myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_ORD);118 x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);119 y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);120 121 for (i=0;i<NUM_DATA;i++) {122 x->data.F64[i] = (double) i;123 y->data.F64[i] = setData(x->data.F64[i]);124 // printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);125 }126 127 printPositiveTestHeader(stdout,128 "psMinimize functions",129 "psVectorFitPolynomial1D(): yErr is NULL");130 131 psVectorFitPolynomial1D(myPoly, x, y, NULL);132 133 // for (i=0;i<POLY_ORDER+1;i++) {134 // printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);135 // }136 137 for (i=0;i<NUM_DATA;i++) {138 expectData = setData(x->data.F64[i]);139 actualData = psPolynomial1DEval(140 myPoly,141 x->data.F64[i]142 );143 if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {144 printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",145 i, x->data.F64[i], actualData, expectData);146 testStatus = false;147 // } else {148 // printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",149 // i, x->data.F64[i], actualData, expectData);150 }151 }152 153 psMemCheckCorruption(1);154 psFree(myPoly);155 psFree(x);156 psFree(y);157 psMemCheckCorruption(1);158 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);159 if (0 != memLeaks) {160 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);161 }162 163 printFooter(stdout,164 "psMinimize functions",165 "psVectorFitPolynomial1D(): yErr is NULL",166 testStatus);167 168 return (!testStatus);169 }170 171 psS32 t02()172 {173 psPolynomial1D *myPoly = NULL;174 psVector *y = NULL;175 psS32 i = 0;176 psS32 currentId = psMemGetId();177 psS32 testStatus = true;178 psS32 memLeaks = 0;179 double expectData;180 double actualData;181 182 myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_ORD);183 y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);184 185 for (i=0;i<NUM_DATA;i++) {186 y->data.F64[i] = setData((double) i);187 // printf("Original data %d: (%.1f)\n", i, y->data.F64[i]);188 }189 190 printPositiveTestHeader(stdout,191 "psMinimize functions",192 "psVectorFitPolynomial1D(): x, yErr is NULL");193 194 psVectorFitPolynomial1D(myPoly, NULL, y, NULL);195 196 // for (i=0;i<POLY_ORDER+1;i++) {197 // printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);198 // }199 200 for (i=0;i<NUM_DATA;i++) {201 expectData = setData((double) i);202 actualData = psPolynomial1DEval(203 myPoly,204 (double) i205 );206 if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {207 printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",208 i, (double) i, actualData, expectData);209 testStatus = false;210 // } else {211 // printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",212 // i, (double) i, actualData, expectData);213 }214 }215 216 psMemCheckCorruption(1);217 psFree(myPoly);218 psFree(y);219 psMemCheckCorruption(1);220 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);221 if (0 != memLeaks) {222 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);223 }224 225 printFooter(stdout,226 "psMinimize functions",227 "psVectorFitPolynomial1D(): x, yErr is NULL",228 testStatus);229 230 return (!testStatus);231 }232 233 psS32 t03()234 {235 psS32 currentId = psMemGetId();236 psS32 testStatus = true;237 psS32 memLeaks = 0;238 psPolynomial1D *myPoly = NULL;239 240 printPositiveTestHeader(stdout,241 "psMinimize functions",242 "psVectorFitPolynomial1D(): all inputs are NULL");243 244 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for null input polynomial.");245 myPoly = psVectorFitPolynomial1D(NULL, NULL, NULL, NULL);246 if ( myPoly != NULL ) {247 psError(PS_ERR_UNKNOWN, true,"A null polynomial should have returned a null pointer.");248 testStatus = false;249 }250 251 252 psMemCheckCorruption(1);253 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);254 if (0 != memLeaks) {255 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);256 }257 258 printFooter(stdout,259 "psMinimize functions",260 "psVectorFitPolynomial1D(): all inputs are NULL",261 testStatus);262 263 return (!testStatus);264 }265 266 267 127 psS32 main() 268 128 { 269 129 psLogSetFormat("HLNM"); 270 130 t00(); 271 t01();272 t02();273 t03();274 131 } -
trunk/psLib/test/math/tst_psMinimize04_F32.c
r4973 r4995 61 61 "psVectorFitPolynomial1D(): equal errors in yErr"); 62 62 63 psVectorFitPolynomial1D(myPoly, x, y, yErr);63 psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x); 64 64 65 65 // for (i=0;i<POLY_ORDER+1;i++) { … … 128 128 "psVectorFitPolynomial1D(): yErr is NULL"); 129 129 130 psVectorFitPolynomial1D(myPoly, x, y, NULL);130 psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x); 131 131 132 132 // for (i=0;i<POLY_ORDER+1;i++) { … … 191 191 "psVectorFitPolynomial1D(): x, yErr is NULL"); 192 192 193 psVectorFitPolynomial1D(myPoly, NULL, y, NULL);193 psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL); 194 194 195 195 // for (i=0;i<POLY_ORDER+1;i++) { … … 241 241 242 242 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null arguments."); 243 psVectorFitPolynomial1D(NULL, NULL, NULL, NULL); 244 243 244 psVectorFitPolynomial1D(NULL, NULL, 0, NULL, NULL, NULL); 245 245 246 246 psMemCheckCorruption(1); -
trunk/psLib/test/math/tst_psMinimize04b.c
r4973 r4995 1 1 /***************************************************************************** 2 2 This routine must ensure that the psVectorFitPolynomial1D works correctly. 3 4 We use Chebyshev polynomials here. 3 5 *****************************************************************************/ 4 6 #include <stdio.h> … … 52 54 "psVectorFitPolynomial1D(): CHEB, equal errors in yErr"); 53 55 54 psVectorFitPolynomial1D(myPoly, x, y, yErr);56 psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x); 55 57 56 58 // Remove for testing since print out differs from platforms … … 121 123 "psVectorFitPolynomial1D(): CHEB, yErr is NULL"); 122 124 123 psVectorFitPolynomial1D(myPoly, x, y, NULL);125 psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x); 124 126 125 127 // We don't test the first or last few data items. … … 184 186 "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL"); 185 187 186 psVectorFitPolynomial1D(myPoly, NULL, y, NULL);188 psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL); 187 189 // psVectorFitPolynomial1D(myPoly, x, y, NULL); 188 190 … … 232 234 233 235 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for null arguments."); 234 myPoly = psVectorFitPolynomial1D(NULL, NULL, NULL, NULL);236 psVectorFitPolynomial1D(myPoly, NULL, 0, NULL, NULL, NULL); 235 237 if (myPoly != NULL) { 236 238 printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n"); -
trunk/psLib/test/math/tst_psMinimize04b_F32.c
r4973 r4995 1 1 /***************************************************************************** 2 2 This routine must ensure that the psVectorFitPolynomial1D works correctly. 3 4 We use Chebyshev polynomials here. 3 5 *****************************************************************************/ 4 6 #include <stdio.h> … … 52 54 "psVectorFitPolynomial1D(): CHEB, equal errors in yErr"); 53 55 54 psVectorFitPolynomial1D(myPoly, x, y, yErr);56 psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x); 55 57 56 58 // Remove for testing since printout differs between platforms … … 121 123 "psVectorFitPolynomial1D(): CHEB, yErr is NULL"); 122 124 123 psVectorFitPolynomial1D(myPoly, x, y, NULL);125 psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x); 124 126 125 127 // We don't test the first or last few data items. … … 184 186 "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL"); 185 187 186 psVectorFitPolynomial1D(myPoly, NULL, y, NULL);188 psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL); 187 189 188 190 // We don't test the first or last few data items. … … 234 236 235 237 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null arguments."); 236 myPoly = psVectorFitPolynomial1D(NULL, NULL, NULL, NULL);238 psVectorFitPolynomial1D(myPoly, NULL, 0, NULL, NULL, NULL); 237 239 if (myPoly != NULL) { 238 240 printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n");
Note:
See TracChangeset
for help on using the changeset viewer.
