Changeset 5092
- Timestamp:
- Sep 22, 2005, 10:45:43 AM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 11 edited
-
src/math/psPolynomial.c (modified) (10 diffs)
-
test/math/tst_psFunc02.c (modified) (5 diffs)
-
test/math/tst_psFunc03.c (modified) (2 diffs)
-
test/math/tst_psFunc08.c (modified) (2 diffs)
-
test/math/tst_psFunc09.c (modified) (12 diffs)
-
test/math/tst_psFunc10.c (modified) (13 diffs)
-
test/math/tst_psFunc11.c (modified) (12 diffs)
-
test/math/tst_psMinimize04.c (modified) (1 diff)
-
test/math/verified/tst_psMinimize04.stderr (modified) (1 diff)
-
test/math/verified/tst_psMinimize04.stdout (modified) (1 diff)
-
test/math/verified/tst_psMinimizeVector2D_F32.stderr (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psPolynomial.c
r5091 r5092 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.12 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-09-22 03:00:31$9 * @version $Revision: 1.125 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-09-22 20:45:43 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 298 298 /* This is old code that does not use Clenshaw's formula. Get rid of it. 299 299 300 psS32 n;301 300 psS32 i; 302 301 psF32 tmp; 303 302 psPolynomial1D **chebPolys = NULL; 304 303 305 n = 1 + poly->COOL_1D_n; 306 chebPolys = createChebyshevPolys(n); 304 chebPolys = createChebyshevPolys(1 + poly->COOL_1D_n); 307 305 308 306 tmp = 0.0; … … 360 358 // Determine how many Chebyshev polynomials 361 359 // are needed, then create them. 362 maxChebyPoly = 1 +poly->COOL_2D_nX;363 if ( (1 + poly->COOL_2D_nY)> maxChebyPoly) {364 maxChebyPoly = (1 + poly->COOL_2D_nY);365 } 366 chebPolys = createChebyshevPolys(maxChebyPoly );360 maxChebyPoly = poly->COOL_2D_nX; 361 if (poly->COOL_2D_nY > maxChebyPoly) { 362 maxChebyPoly = poly->COOL_2D_nY; 363 } 364 chebPolys = createChebyshevPolys(maxChebyPoly + 1); 367 365 368 366 for (loop_x = 0; loop_x < (1 + poly->COOL_2D_nX); loop_x++) { … … 375 373 } 376 374 } 377 for (i=0;i<maxChebyPoly ;i++) {375 for (i=0;i<maxChebyPoly+1;i++) { 378 376 psFree(chebPolys[i]); 379 377 } … … 453 451 } 454 452 455 for (i=0;i<maxChebyPoly ;i++) {453 for (i=0;i<maxChebyPoly+1;i++) { 456 454 psFree(chebPolys[i]); 457 455 } … … 529 527 maxChebyPoly = poly->COOL_4D_nT; 530 528 } 531 chebPolys = createChebyshevPolys(maxChebyPoly );529 chebPolys = createChebyshevPolys(maxChebyPoly + 1); 532 530 533 531 for (loop_x = 0; loop_x < (1 + poly->COOL_4D_nX); loop_x++) { … … 536 534 for (loop_t = 0; loop_t < (1 + poly->COOL_4D_nZ); loop_t++) { 537 535 if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) { 536 //printf("HMMM (%d, %d, %d, %d)\n", loop_x, loop_y, loop_z, loop_t); 537 //printf("HMMM (%d, %d, %d, %d)\n", chebPolys[loop_x]->COOL_1D_n, chebPolys[loop_y]->COOL_1D_n, chebPolys[loop_z]->COOL_1D_n, chebPolys[loop_t]->COOL_1D_n); 538 538 539 polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] * 539 540 psPolynomial1DEval(chebPolys[loop_x], x) * … … 547 548 } 548 549 549 for (i=0;i<maxChebyPoly ;i++) {550 for (i=0;i<maxChebyPoly+1;i++) { 550 551 psFree(chebPolys[i]); 551 552 } … … 618 619 psPolynomialType type) 619 620 { 620 PS_ASSERT_INT_ POSITIVE(n, NULL);621 PS_ASSERT_INT_NONNEGATIVE(n, NULL); 621 622 622 623 unsigned int i = 0; … … 628 629 newPoly->type = type; 629 630 newPoly->COOL_1D_n = n; 630 newPoly->coeff = psAlloc( n* sizeof(psF64));631 newPoly->coeffErr = psAlloc( n* sizeof(psF64));631 newPoly->coeff = psAlloc((n + 1) * sizeof(psF64)); 632 newPoly->coeffErr = psAlloc((n + 1) * sizeof(psF64)); 632 633 newPoly->mask = (psMaskType *)psAlloc((n + 1) * sizeof(psMaskType)); 633 634 for (i = 0; i < (n + 1); i++) { -
trunk/psLib/test/math/tst_psFunc02.c
r5091 r5092 51 51 testStatus = false; 52 52 } 53 if ((tmpSpline->spline[i])->COOL_1D_n != LINEAR +1) {53 if ((tmpSpline->spline[i])->COOL_1D_n != LINEAR) { 54 54 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->COOL_1D_n); 55 55 testStatus = false; … … 133 133 testStatus = false; 134 134 } 135 if ((tmpSpline->spline[i])->COOL_1D_n != LINEAR +1) {135 if ((tmpSpline->spline[i])->COOL_1D_n != LINEAR) { 136 136 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->COOL_1D_n); 137 137 testStatus = false; … … 188 188 testStatus = false; 189 189 } 190 if ((tmpSpline->spline[i])->COOL_1D_n != CUBIC +1) {190 if ((tmpSpline->spline[i])->COOL_1D_n != CUBIC) { 191 191 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->COOL_1D_n); 192 192 testStatus = false; … … 270 270 testStatus = false; 271 271 } 272 if ((tmpSpline->spline[i])->COOL_1D_n != CUBIC +1) {272 if ((tmpSpline->spline[i])->COOL_1D_n != CUBIC) { 273 273 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->COOL_1D_n); 274 274 testStatus = false; … … 330 330 testStatus = false; 331 331 } 332 if ((tmpSpline->spline[i])->COOL_1D_n != LINEAR +1) {332 if ((tmpSpline->spline[i])->COOL_1D_n != LINEAR) { 333 333 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->COOL_1D_n); 334 334 testStatus = false; -
trunk/psLib/test/math/tst_psFunc03.c
r4973 r5092 56 56 testStatus = false; 57 57 } 58 if ((tmpSpline->spline[i])-> n != LINEAR+1) {59 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])-> n);58 if ((tmpSpline->spline[i])->COOL_1D_n != LINEAR) { 59 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->COOL_1D_n); 60 60 testStatus = false; 61 61 } … … 117 117 testStatus = false; 118 118 } 119 if ((tmpSpline->spline[i])-> n != CUBIC+1) {120 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])-> n);119 if ((tmpSpline->spline[i])->COOL_1D_n != CUBIC) { 120 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->COOL_1D_n); 121 121 testStatus = false; 122 122 } -
trunk/psLib/test/math/tst_psFunc08.c
r5090 r5092 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-09-22 02:47:16$6 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-09-22 20:45:43 $ 8 8 * 9 9 * XXX: Probably should test single- and multi-dimensional polynomials in 10 10 * which one diminsion is constant (n == 1). 11 * 12 * XXX: define ORDERS, not TERMS 13 * 11 14 * 12 15 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 191 194 return 0; 192 195 } 193 -
trunk/psLib/test/math/tst_psFunc09.c
r5090 r5092 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-09-22 02:47:16$6 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-09-22 20:45:43 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 22 22 23 23 testDescription tests[] = { 24 {testPoly2DEval,583,"psPolynomial2DEval", 0,false},25 {testPoly2DEvalVector,000,"psPolynomial2DEvalVector", 0,false},24 {testPoly2DEval,583,"psPolynomial2DEval",true,false}, 25 {testPoly2DEvalVector,000,"psPolynomial2DEvalVector",true,false}, 26 26 {NULL} 27 27 }; … … 82 82 83 83 // This test will verify operation of 1D polynomial evaluation 84 /*psS32 testPoly2DEval(void)84 psS32 testPoly2DEval(void) 85 85 { 86 psF32 result; 87 psF32 resultCheb; 88 86 psF64 result; 87 psF64 resultCheb; 88 psBool testStatus = true; 89 89 90 // Allocate polynomial structure 90 91 psPolynomial2D* polyOrd = psPolynomial2DAlloc(TERMS-1, TERMS-1, PS_POLYNOMIAL_ORD); … … 101 102 // Evaluate test points and verify results 102 103 for(psS32 i = 0; i < TESTPOINTS; i++) { 103 result = psPolynomial2DEval(polyOrd,poly2DXYValue[i][0],poly2DXYValue[i][1]); 104 if(fabs(poly2DResult[i]-result) > ERROR_TOL ) { 105 psError(PS_ERR_UNKNOWN,true,"Evaluated value %g not as expected %g", 106 result, poly2DResult[i]); 107 return i; 108 } 109 resultCheb = psPolynomial2DEval(polyCheb,poly2DXYChebValue[i][0], poly2DXYChebValue[i][1]); 110 if(fabs(poly2DChebResult[i]-resultCheb) > ERROR_TOL ) { 111 psError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg", 112 resultCheb, poly2DChebResult[i]); 113 return 5*i; 104 result = psPolynomial2DEval(polyOrd,Dpoly2DXYValue[i][0],Dpoly2DXYValue[i][1]); 105 if(fabs(Dpoly2DResult[i]-result) > ERROR_TOL ) { 106 printf("TEST ERROR: Evaluated value %f, should be %f\n", result, Dpoly2DResult[i]); 107 testStatus = false; 108 } 109 resultCheb = psPolynomial2DEval(polyCheb,Dpoly2DXYChebValue[i][0],Dpoly2DXYChebValue[i][1]); 110 if(fabs(Dpoly2DChebResult[i]-resultCheb) > ERROR_TOL ) { 111 printf("TEST ERROR: Evaluated value %f, should be %f\n", resultCheb, Dpoly2DChebResult[i]); 112 testStatus = false; 114 113 } 115 114 } 116 115 psFree(polyOrd); 117 116 psFree(polyCheb); 118 117 119 118 // Allocate polynomial with invalid type 120 119 polyOrd = psPolynomial2DAlloc(TERMS-1, TERMS-1, 99); … … 124 123 if ( !isnan(result) ) { 125 124 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type"); 126 return 20;125 testStatus = false; 127 126 } 128 127 psFree(polyOrd); 129 130 return 0;128 129 return(testStatus); 131 130 } 132 */ 133 // This test will verify operation of 1D polynomial evaluation 134 psS32 testPoly2DEval(void) 135 { 136 psF64 result; 137 psF64 resultCheb; 138 139 // Allocate polynomial structure 140 psPolynomial2D* polyOrd = psPolynomial2DAlloc(TERMS-1, TERMS-1, PS_POLYNOMIAL_ORD); 141 psPolynomial2D* polyCheb = psPolynomial2DAlloc(TERMS-1, TERMS-1, PS_POLYNOMIAL_CHEB); 142 // Set polynomial members 143 for(psS32 i = 0; i < TERMS; i++) { 144 for(psS32 j = 0; j < TERMS; j++) { 145 polyOrd->coeff[i][j] = poly2DCoeff[i][j]; 146 polyOrd->mask[i][j] = poly2DMask[i][j]; 147 polyCheb->coeff[i][j] = 1.0; 148 polyCheb->mask[i][j] = poly2DMask[i][j]; 149 } 150 } 151 // Evaluate test points and verify results 152 for(psS32 i = 0; i < TESTPOINTS; i++) { 153 result = psPolynomial2DEval(polyOrd,Dpoly2DXYValue[i][0],Dpoly2DXYValue[i][1]); 154 if(fabs(Dpoly2DResult[i]-result) > ERROR_TOL ) { 155 psError(PS_ERR_UNKNOWN,true,"Evaluated value %lg not as expected %lg", 156 result, Dpoly2DResult[i]); 157 return i; 158 } 159 resultCheb = psPolynomial2DEval(polyCheb,Dpoly2DXYChebValue[i][0],Dpoly2DXYChebValue[i][1]); 160 if(fabs(Dpoly2DChebResult[i]-resultCheb) > ERROR_TOL ) { 161 psError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg", 162 resultCheb, Dpoly2DChebResult[i]); 163 return 5*i; 164 } 165 } 166 psFree(polyOrd); 167 psFree(polyCheb); 168 169 // Allocate polynomial with invalid type 170 polyOrd = psPolynomial2DAlloc(TERMS-1, TERMS-1, 99); 171 // Attempt to evaluation invalid polynomial type 172 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type"); 173 result = psPolynomial2DEval(polyOrd,0.0, 0.0); 174 if ( !isnan(result) ) { 175 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type"); 176 return 20; 177 } 178 psFree(polyOrd); 179 180 return 0; 181 } 182 183 /*psS32 testPoly2DEvalVector(void) 184 { 185 // Allocate polynomial 186 psPolynomial2D* polyOrd = psPolynomial2DAlloc(TERMS-1,TERMS-1,PS_POLYNOMIAL_ORD); 187 psPolynomial2D* polyCheb = psPolynomial2DAlloc(TERMS-1,TERMS-1,PS_POLYNOMIAL_CHEB); 188 189 // Set polynomial members 190 for(psS32 i = 0; i < TERMS; i++) { 191 for(psS32 j = 0; j < TERMS; j++) { 192 polyOrd->coeff[i][j] = poly2DCoeff[i][j]; 193 polyOrd->mask[i][j] = poly2DMask[i][j]; 194 polyCheb->coeff[i][j] = 1.0; 195 polyCheb->mask[i][j] = poly2DMask[i][j]; 196 } 197 } 198 199 // Create input vectors 200 psVector* inputOrdX = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 201 psVector* inputOrdY = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 202 psVector* inputChebX = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 203 psVector* inputChebY = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 204 for(psS32 i = 0; i < TESTPOINTS; i++) { 205 inputOrdX->data.F32[i] = poly2DXYValue[i][0]; 206 inputOrdY->data.F32[i] = poly2DXYValue[i][1]; 207 inputChebX->data.F32[i] = poly2DXYChebValue[i][0]; 208 inputChebY->data.F32[i] = poly2DXYChebValue[i][1]; 209 } 210 211 // Evaluate the vectors 212 psVector* outputOrd = psPolynomial2DEvalVector(polyOrd, inputOrdX, inputOrdY); 213 if(outputOrd == NULL) { 214 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL."); 215 return 1; 216 } 217 if(outputOrd->type.type != PS_TYPE_F32) { 218 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d", 219 outputOrd->type.type, PS_TYPE_F32); 220 return 2; 221 } 222 psVector* outputCheb = psPolynomial2DEvalVector(polyCheb, inputChebX, inputChebY); 223 if(outputCheb == NULL) { 224 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL."); 225 return 1; 226 } 227 if(outputCheb->type.type != PS_TYPE_F32) { 228 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d", 229 outputCheb->type.type, PS_TYPE_F32); 230 return 2; 231 } 232 233 // Verify the results 234 for(psS32 i = 0; i < TESTPOINTS; i++) { 235 if(fabs(poly2DResult[i]-outputOrd->data.F32[i]) > ERROR_TOL) { 236 psError(PS_ERR_UNKNOWN,true,"Result[%d] %g not equal to expected %g", 237 i, outputOrd->data.F32[i], poly2DResult[i]); 238 return i*5; 239 } 240 if(fabs(poly2DChebResult[i]-outputCheb->data.F32[i]) > ERROR_TOL) { 241 psError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %g not equal to expected %g", 242 i, outputCheb->data.F32[i], poly2DChebResult[i]); 243 return i*10; 244 } 245 } 246 247 // Attempt to invoke function with null polynomial 248 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial"); 249 if(psPolynomial2DEvalVector(NULL, inputOrdX, inputOrdY) != NULL) { 250 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial"); 251 return 60; 252 } 253 254 // Attempt to invoke function with null input vector 255 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 256 if(psPolynomial2DEvalVector(polyOrd,NULL, inputOrdY) != NULL) { 257 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector"); 258 return 61; 259 } 260 // Attempt to invoke function with null input vector 261 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 262 if(psPolynomial2DEvalVector(polyOrd, inputOrdX, NULL) != NULL) { 263 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector"); 264 return 62; 265 } 266 267 // Attempt to invoke function with a non F32 type input vector 268 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 269 inputOrdX->type.type = PS_TYPE_U8; 270 if(psPolynomial2DEvalVector(polyOrd,inputOrdX,inputOrdY) != NULL) { 271 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector"); 272 return 63; 273 } 274 inputOrdX->type.type = PS_TYPE_F32; 275 // Attempt to invoke function with a non F32 type input vector 276 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 277 inputOrdY->type.type = PS_TYPE_U8; 278 if(psPolynomial2DEvalVector(polyOrd,inputOrdX,inputOrdY) != NULL) { 279 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector"); 280 return 64; 281 } 282 inputOrdY->type.type = PS_TYPE_F32; 283 284 psFree(inputOrdX); 285 psFree(inputOrdY); 286 psFree(inputChebX); 287 psFree(inputChebY); 288 psFree(outputOrd); 289 psFree(outputCheb); 290 psFree(polyOrd); 291 psFree(polyCheb); 292 293 return 0; 294 } 295 */ 131 296 132 psS32 testPoly2DEvalVector(void) 297 133 { 134 psBool testStatus = true; 298 135 // Allocate polynomial 299 136 psPolynomial2D* polyOrd = psPolynomial2DAlloc(TERMS-1,TERMS-1,PS_POLYNOMIAL_ORD); … … 325 162 psVector* outputOrd = psPolynomial2DEvalVector(polyOrd, inputOrdX, inputOrdY); 326 163 if(outputOrd == NULL) { 327 p sError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");328 return 1;164 printf("TEST ERROR: Unexpected return of NULL.\n"); 165 testStatus = false; 329 166 } 330 167 if(outputOrd->type.type != PS_TYPE_F64) { 331 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d", 332 outputOrd->type.type, PS_TYPE_F64); 333 return 2; 168 printf("TEST ERROR: Output vector of type %d expected %d\n", outputOrd->type.type, PS_TYPE_F64); 169 testStatus = false; 334 170 } 335 171 psVector* outputCheb = psPolynomial2DEvalVector(polyCheb, inputChebX, inputChebY); 336 172 if(outputCheb == NULL) { 337 p sError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");338 return 1;173 printf("TEST ERROR: Unexpected return of NULL.\n"); 174 testStatus = false; 339 175 } 340 176 if(outputCheb->type.type != PS_TYPE_F64) { 341 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d", 342 outputCheb->type.type, PS_TYPE_F64); 343 return 2; 177 printf("TEST ERROR: Output vector of type %d expected %d.\n", outputCheb->type.type, PS_TYPE_F64); 178 testStatus = false; 344 179 } 345 180 … … 347 182 for(psS32 i = 0; i < TESTPOINTS; i++) { 348 183 if(fabs(poly2DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) { 349 p sError(PS_ERR_UNKNOWN,true,"Result[%d] %lg not equal to expected %lg",350 i, outputOrd->data.F64[i], poly2DResult[i]);351 return i*5;184 printf("TEST ERROR: Result[%d] %lg not equal to expected %lg.\n", 185 i, outputOrd->data.F64[i], poly2DResult[i]); 186 testStatus = false; 352 187 } 353 188 if(fabs(poly2DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) { 354 p sError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %lg not equal to expected %lg",355 i, outputCheb->data.F64[i], poly2DChebResult[i]);356 return i*10;189 printf("TEST ERROR: ResultCheb[%d] %lg not equal to expected %lg.\n", 190 i, outputCheb->data.F64[i], poly2DChebResult[i]); 191 testStatus = false; 357 192 } 358 193 } … … 361 196 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial"); 362 197 if(psPolynomial2DEvalVector(NULL, inputOrdX, inputOrdY) != NULL) { 363 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");364 return 60;198 printf("TEST ERROR: Return of NULL expected for NULL polynomial.\n"); 199 testStatus = false; 365 200 } 366 201 … … 368 203 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 369 204 if(psPolynomial2DEvalVector(polyOrd,NULL,inputOrdY) != NULL) { 370 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");371 return 61;205 printf("TEST ERROR: Return of NULL expected for NULL input vector.\n"); 206 testStatus = false; 372 207 } 373 208 // Attempt to invoke function with null input vector 374 209 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 375 210 if(psPolynomial2DEvalVector(polyOrd,inputOrdX,NULL) != NULL) { 376 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");377 return 62;211 printf("TEST ERROR: Return of NULL expected for NULL input vector.\n"); 212 testStatus = false; 378 213 } 379 214 … … 382 217 inputOrdX->type.type = PS_TYPE_U8; 383 218 if(psPolynomial2DEvalVector(polyOrd,inputOrdX, inputOrdY) != NULL) { 384 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");385 return 63;219 printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n"); 220 testStatus = false; 386 221 } 387 222 inputOrdX->type.type = PS_TYPE_F64; … … 390 225 inputOrdY->type.type = PS_TYPE_U8; 391 226 if(psPolynomial2DEvalVector(polyOrd,inputOrdX, inputOrdY) != NULL) { 392 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");393 return 64;227 printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n"); 228 testStatus = false; 394 229 } 395 230 inputOrdY->type.type = PS_TYPE_F64; … … 404 239 psFree(polyCheb); 405 240 406 return 0;241 return(testStatus); 407 242 } 408 243 -
trunk/psLib/test/math/tst_psFunc10.c
r5090 r5092 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-09-22 02:47:16$6 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-09-22 20:45:43 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 22 22 23 23 testDescription tests[] = { 24 {testPoly3DEval,583,"psPolynomial3DEval", 0,false},25 {testPoly3DEvalVector,000,"psPolynomial3DEvalVector", 0,false},24 {testPoly3DEval,583,"psPolynomial3DEval",true,false}, 25 {testPoly3DEvalVector,000,"psPolynomial3DEvalVector",true,false}, 26 26 {NULL} 27 27 }; … … 133 133 134 134 // This test will verify operation of 1D polynomial evaluation 135 /*psS32 testPoly3DEval(void)136 {137 psF32 result;138 psF32 resultCheb;139 140 // Allocate polynomial structure141 psPolynomial3D* polyOrd = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_ORD);142 psPolynomial3D* polyCheb = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_CHEB);143 // Set polynomial members144 for(psS32 i = 0; i < TERMS; i++) {145 for(psS32 j = 0; j < TERMS; j++) {146 for(psS32 k = 0; k < TERMS; k++) {147 polyOrd->coeff[i][j][k] = poly3DCoeff[i][j][k];148 polyOrd->mask[i][j][k] = poly3DMask[i][j][k];149 polyCheb->coeff[i][j][k] = 1.0;150 polyCheb->mask[i][j][k] = poly3DMask[i][j][k];151 }152 }153 }154 // Evaluate test points and verify results155 for(psS32 i = 0; i < TESTPOINTS; i++) {156 result = psPolynomial3DEval(polyOrd,poly3DXYZValue[i][0],poly3DXYZValue[i][1],157 poly3DXYZValue[i][2]);158 if(fabs(poly3DResult[i]-result) > ERROR_TOL ) {159 psError(PS_ERR_UNKNOWN,true,"Evaluated value %g not as expected %g",160 result, poly3DResult[i]);161 return i;162 }163 resultCheb = psPolynomial3DEval(polyCheb,poly3DXYZChebValue[i][0], poly3DXYZChebValue[i][1],164 poly3DXYZChebValue[i][2]);165 if(fabs(poly3DChebResult[i]-resultCheb) > ERROR_TOL ) {166 psError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg",167 resultCheb, poly3DChebResult[i]);168 return 5*i;169 }170 }171 psFree(polyOrd);172 psFree(polyCheb);173 174 // Allocate polynomial with invalid type175 polyOrd = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1, 99);176 // Attempt to evaluation invalid polynomial type177 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type");178 result = psPolynomial3DEval(polyOrd,0.0, 0.0, 0.0);179 if ( !isnan(result) ) {180 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");181 return 20;182 }183 psFree(polyOrd);184 185 return 0;186 }187 */188 // This test will verify operation of 1D polynomial evaluation189 135 psS32 testPoly3DEval(void) 190 136 { 191 137 psF64 result; 192 138 psF64 resultCheb; 139 psBool testStatus = true; 193 140 194 141 // Allocate polynomial structure … … 211 158 Dpoly3DXYZValue[i][2]); 212 159 if(fabs(Dpoly3DResult[i]-result) > ERROR_TOL ) { 213 p sError(PS_ERR_UNKNOWN,true,"Evaluated value %lg not as expected %lg",214 result, Dpoly3DResult[i]);215 return i;160 printf("TEST ERROR: Evaluated value %lg not as expected %lg.\n", 161 result, Dpoly3DResult[i]); 162 testStatus = false; 216 163 } 217 164 resultCheb = psPolynomial3DEval(polyCheb,Dpoly3DXYZChebValue[i][0],Dpoly3DXYZChebValue[i][1], 218 165 Dpoly3DXYZChebValue[i][2]); 219 166 if(fabs(Dpoly3DChebResult[i]-resultCheb) > ERROR_TOL ) { 220 p sError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg",221 resultCheb, Dpoly3DChebResult[i]);222 return 5*i;167 printf("TEST ERROR: Evaluated Chebyshev value %lg not as expected %lg.\n", 168 resultCheb, Dpoly3DChebResult[i]); 169 testStatus = false; 223 170 } 224 171 } … … 232 179 result = psPolynomial3DEval(polyOrd,0.0, 0.0, 0.0); 233 180 if ( !isnan(result) ) { 234 p sError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");235 return 20;181 printf("TEST ERROR: Did not return NAN for invalid polynomial type.\n"); 182 testStatus = false; 236 183 } 237 184 psFree(polyOrd); … … 240 187 } 241 188 242 /*psS32 testPoly3DEvalVector(void)243 {244 // Allocate polynomial245 psPolynomial3D* polyOrd = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1,PS_POLYNOMIAL_ORD);246 psPolynomial3D* polyCheb = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1,PS_POLYNOMIAL_CHEB);247 248 // Set polynomial members249 for(psS32 i = 0; i < TERMS; i++) {250 for(psS32 j = 0; j < TERMS; j++) {251 for(psS32 k = 0; k < TERMS; k++) {252 polyOrd->coeff[i][j][k] = poly3DCoeff[i][j][k];253 polyOrd->mask[i][j][k] = poly3DMask[i][j][k];254 polyCheb->coeff[i][j][k] = 1.0;255 polyCheb->mask[i][j][k] = poly3DMask[i][j][k];256 }257 }258 }259 260 // Create input vectors261 psVector* inputOrdX = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);262 psVector* inputOrdY = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);263 psVector* inputOrdZ = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);264 psVector* inputChebX = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);265 psVector* inputChebY = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);266 psVector* inputChebZ = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);267 for(psS32 i = 0; i < TESTPOINTS; i++) {268 inputOrdX->data.F32[i] = poly3DXYZValue[i][0];269 inputOrdY->data.F32[i] = poly3DXYZValue[i][1];270 inputOrdZ->data.F32[i] = poly3DXYZValue[i][2];271 inputChebX->data.F32[i] = poly3DXYZChebValue[i][0];272 inputChebY->data.F32[i] = poly3DXYZChebValue[i][1];273 inputChebZ->data.F32[i] = poly3DXYZChebValue[i][2];274 }275 276 // Evaluate the vectors277 psVector* outputOrd = psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ);278 if(outputOrd == NULL) {279 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");280 return 1;281 }282 if(outputOrd->type.type != PS_TYPE_F32) {283 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",284 outputOrd->type.type, PS_TYPE_F32);285 return 2;286 }287 psVector* outputCheb = psPolynomial3DEvalVector(polyCheb,inputChebX,inputChebY,inputChebZ);288 if(outputCheb == NULL) {289 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");290 return 1;291 }292 if(outputCheb->type.type != PS_TYPE_F32) {293 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",294 outputCheb->type.type, PS_TYPE_F32);295 return 2;296 }297 298 // Verify the results299 for(psS32 i = 0; i < TESTPOINTS; i++) {300 if(fabs(poly3DResult[i]-outputOrd->data.F32[i]) > ERROR_TOL) {301 psError(PS_ERR_UNKNOWN,true,"Result[%d] %g not equal to expected %g",302 i, outputOrd->data.F32[i], poly3DResult[i]);303 return i*5;304 }305 if(fabs(poly3DChebResult[i]-outputCheb->data.F32[i]) > ERROR_TOL) {306 psError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %g not equal to expected %g",307 i, outputCheb->data.F32[i], poly3DChebResult[i]);308 return i*10;309 }310 }311 312 // Attempt to invoke function with null polynomial313 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");314 if(psPolynomial3DEvalVector(NULL, inputOrdX, inputOrdY, inputOrdZ) != NULL) {315 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");316 return 60;317 }318 319 // Attempt to invoke function with null input vector320 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");321 if(psPolynomial3DEvalVector(polyOrd,NULL, inputOrdY,inputOrdZ) != NULL) {322 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");323 return 61;324 }325 // Attempt to invoke function with null input vector326 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");327 if(psPolynomial3DEvalVector(polyOrd, inputOrdX, NULL,inputOrdZ) != NULL) {328 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");329 return 62;330 }331 // Attempt to invoke function with null input vector332 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");333 if(psPolynomial3DEvalVector(polyOrd, inputOrdX,inputOrdY,NULL) != NULL) {334 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");335 return 63;336 }337 338 // Attempt to invoke function with a non F32 type input vector339 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");340 inputOrdX->type.type = PS_TYPE_U8;341 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {342 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector");343 return 65;344 }345 inputOrdX->type.type = PS_TYPE_F32;346 // Attempt to invoke function with a non F32 type input vector347 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");348 inputOrdY->type.type = PS_TYPE_U8;349 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {350 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector");351 return 66;352 }353 inputOrdY->type.type = PS_TYPE_F32;354 // Attempt to invoke function with a non F32 type input vector355 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");356 inputOrdZ->type.type = PS_TYPE_U8;357 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {358 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector");359 return 67;360 }361 inputOrdZ->type.type = PS_TYPE_F32;362 363 psFree(inputOrdX);364 psFree(inputOrdY);365 psFree(inputOrdZ);366 psFree(inputChebX);367 psFree(inputChebY);368 psFree(inputChebZ);369 psFree(outputOrd);370 psFree(outputCheb);371 psFree(polyOrd);372 psFree(polyCheb);373 374 return 0;375 }376 */377 189 psS32 testPoly3DEvalVector(void) 378 190 { 191 psBool testStatus = true; 379 192 // Allocate polynomial 380 193 psPolynomial3D* polyOrd = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1,PS_POLYNOMIAL_ORD); … … 412 225 psVector* outputOrd = psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ); 413 226 if(outputOrd == NULL) { 414 p sError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");415 return 1;227 printf("TEST ERROR: Unexpected return of NULL.\n"); 228 testStatus = false; 416 229 } 417 230 if(outputOrd->type.type != PS_TYPE_F64) { 418 p sError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",419 outputOrd->type.type, PS_TYPE_F64);420 return 2;231 printf("TEST ERROR: Output vector of type %d expected %d.\n", 232 outputOrd->type.type, PS_TYPE_F64); 233 testStatus = false; 421 234 } 422 235 psVector* outputCheb = psPolynomial3DEvalVector(polyCheb,inputChebX,inputChebY,inputChebZ); 423 236 if(outputCheb == NULL) { 424 p sError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");425 return 1;237 printf("TEST ERROR: Unexpected return of NULL.\n"); 238 testStatus = false; 426 239 } 427 240 if(outputCheb->type.type != PS_TYPE_F64) { 428 p sError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",429 outputCheb->type.type, PS_TYPE_F64);430 return 2;241 printf("TEST ERROR: Output vector of type %d expected %d.\n", 242 outputCheb->type.type, PS_TYPE_F64); 243 testStatus = false; 431 244 } 432 245 … … 434 247 for(psS32 i = 0; i < TESTPOINTS; i++) { 435 248 if(fabs(Dpoly3DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) { 436 p sError(PS_ERR_UNKNOWN,true,"Result[%d] %lg not equal to expected %lg",437 i, outputOrd->data.F64[i], Dpoly3DResult[i]);438 return i*5;249 printf("TEST ERROR: Result[%d] %lg not equal to expected %lg.\n", 250 i, outputOrd->data.F64[i], Dpoly3DResult[i]); 251 testStatus = false; 439 252 } 440 253 if(fabs(Dpoly3DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) { 441 p sError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %lg not equal to expected %lg",442 i, outputCheb->data.F64[i], Dpoly3DChebResult[i]);443 return i*10;254 printf("TEST ERROR: ResultCheb[%d] %lg not equal to expected %lg.\n", 255 i, outputCheb->data.F64[i], Dpoly3DChebResult[i]); 256 testStatus = false; 444 257 } 445 258 } … … 448 261 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial"); 449 262 if(psPolynomial3DEvalVector(NULL,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 450 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");451 return 60;263 printf("TEST ERROR: Return of NULL expected for NULL polynomial.\n"); 264 testStatus = false; 452 265 } 453 266 … … 455 268 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 456 269 if(psPolynomial3DEvalVector(polyOrd,NULL,inputOrdY,inputOrdZ) != NULL) { 457 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");458 return 61;270 printf("TEST ERROR: Return of NULL expected for NULL input vector.\n"); 271 testStatus = false; 459 272 } 460 273 // Attempt to invoke function with null input vector 461 274 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 462 275 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,NULL,inputOrdZ) != NULL) { 463 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");464 return 62;276 printf("TEST ERROR: Return of NULL expected for NULL input vector.\n"); 277 testStatus = false; 465 278 } 466 279 // Attempt to invoke function with null input vector 467 280 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 468 281 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,NULL) != NULL) { 469 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");470 return 63;282 printf("TEST ERROR: Return of NULL expected for NULL input vector.\n"); 283 testStatus = false; 471 284 } 472 285 … … 475 288 inputOrdX->type.type = PS_TYPE_U8; 476 289 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 477 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");478 return 64;290 printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n"); 291 testStatus = false; 479 292 } 480 293 inputOrdX->type.type = PS_TYPE_F64; … … 483 296 inputOrdY->type.type = PS_TYPE_U8; 484 297 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 485 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");486 return 65;298 printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n"); 299 testStatus = false; 487 300 } 488 301 inputOrdY->type.type = PS_TYPE_F64; … … 491 304 inputOrdZ->type.type = PS_TYPE_U8; 492 305 if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 493 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");494 return 66;306 printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n"); 307 testStatus = false; 495 308 } 496 309 inputOrdZ->type.type = PS_TYPE_F64; -
trunk/psLib/test/math/tst_psFunc11.c
r5090 r5092 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-09-22 02:47:16$6 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-09-22 20:45:43 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 19 19 20 20 static psS32 testPoly4DEval(void); 21 static psS32 testPoly4DEvalVector(void);21 //static psS32 testPoly4DEvalVector(void); 22 22 23 23 testDescription tests[] = { 24 {testPoly4DEval,583,"psPolynomial4DEval", 0,false},25 {testPoly4DEvalVector,000,"psPolynomial4DEvalVector",0,false},24 {testPoly4DEval,583,"psPolynomial4DEval",true,false}, 25 // {testPoly4DEvalVector,000,"psPolynomial4DEvalVector",true,false}, 26 26 {NULL} 27 27 }; … … 374 374 } 375 375 376 // This test will verify operation of 1D polynomial evaluation 377 /*psS32 testPoly4DEval(void) 378 { 379 psF32 result; 380 psF32 resultCheb; 381 382 // Allocate polynomial structure 383 psPolynomial4D* polyOrd = psPolynomial4DAlloc(TERMS-1, TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_ORD); 384 psPolynomial4D* polyCheb = psPolynomial4DAlloc(TERMS-1, TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_CHEB); 385 // Set polynomial members 386 for(psS32 i = 0; i < TERMS; i++) { 387 for(psS32 j = 0; j < TERMS; j++) { 388 for(psS32 k = 0; k < TERMS; k++) { 389 for(psS32 l = 0; l < TERMS; l++) { 390 polyOrd->coeff[i][j][k][l] = poly4DCoeff[i][j][k][l]; 391 polyOrd->mask[i][j][k][l] = poly4DMask[i][j][k][l]; 392 polyCheb->coeff[i][j][k][l] = 1.0; 393 polyCheb->mask[i][j][k][l] = poly4DMask[i][j][k][l]; 394 } 395 } 396 } 397 } 398 // Evaluate test points and verify results 399 for(psS32 i = 0; i < TESTPOINTS; i++) { 400 result = psPolynomial4DEval(polyOrd,poly4DWXYZValue[i][0],poly4DWXYZValue[i][1], 401 poly4DWXYZValue[i][2], poly4DWXYZValue[i][3]); 402 if(fabs(poly4DResult[i]-result) > ERROR_TOL ) { 403 psError(PS_ERR_UNKNOWN,true,"Evaluated value %g not as expected %g", 404 result, poly4DResult[i]); 405 return i; 406 } 407 resultCheb = psPolynomial4DEval(polyCheb,poly4DWXYZChebValue[i][0], poly4DWXYZChebValue[i][1], 408 poly4DWXYZChebValue[i][2], poly4DWXYZChebValue[i][3]); 409 if(fabs(poly4DChebResult[i]-resultCheb) > ERROR_TOL ) { 410 psError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg", 411 resultCheb, poly4DChebResult[i]); 412 return 5*i; 413 } 414 } 415 psFree(polyOrd); 416 psFree(polyCheb); 417 418 // Allocate polynomial with invalid type 419 polyOrd = psPolynomial4DAlloc(TERMS-1, TERMS-1, TERMS-1, TERMS-1, 99); 420 // Attempt to evaluation invalid polynomial type 421 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type"); 422 result = psPolynomial4DEval(polyOrd,0.0, 0.0, 0.0, 0.0); 423 if ( !isnan(result) ) { 424 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type"); 425 return 20; 426 } 427 psFree(polyOrd); 428 429 return 0; 430 } 431 */ 432 // This test will verify operation of 1D polynomial evaluation 376 // This test will verify operation of 4D polynomial evaluation 433 377 psS32 testPoly4DEval(void) 434 378 { 435 psF64 result; 436 psF64 resultCheb; 379 psBool testStatus = true; 437 380 438 381 // Allocate polynomial structure … … 452 395 } 453 396 } 397 454 398 // Evaluate test points and verify results 455 399 for(psS32 i = 0; i < TESTPOINTS; i++) { 456 result = psPolynomial4DEval(polyOrd,Dpoly4DWXYZValue[i][0],Dpoly4DWXYZValue[i][1],457 Dpoly4DWXYZValue[i][2],Dpoly4DWXYZValue[i][3]);400 psF64 result = psPolynomial4DEval(polyOrd,Dpoly4DWXYZValue[i][0],Dpoly4DWXYZValue[i][1], 401 Dpoly4DWXYZValue[i][2],Dpoly4DWXYZValue[i][3]); 458 402 if(fabs(Dpoly4DResult[i]-result) > ERROR_TOL ) { 459 p sError(PS_ERR_UNKNOWN,true,"Evaluated value %lg not as expected %lg",460 result, Dpoly4DResult[i]);461 return i;403 printf("TEST ERROR: Evaluated value %lg not as expected %lg.\n", 404 result, Dpoly4DResult[i]); 405 testStatus = false; 462 406 } 463 resultCheb = psPolynomial4DEval(polyCheb,Dpoly4DWXYZChebValue[i][0],Dpoly4DWXYZChebValue[i][1], 464 Dpoly4DWXYZChebValue[i][2],Dpoly4DWXYZChebValue[i][3]); 407 408 psF64 resultCheb = psPolynomial4DEval(polyCheb,Dpoly4DWXYZChebValue[i][0],Dpoly4DWXYZChebValue[i][1], 409 Dpoly4DWXYZChebValue[i][2],Dpoly4DWXYZChebValue[i][3]); 465 410 if(fabs(Dpoly4DChebResult[i]-resultCheb) > ERROR_TOL ) { 466 p sError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg",467 resultCheb, Dpoly4DChebResult[i]);468 return 5*i;411 printf("TEST ERROR: Evaluated Chebyshev value %lg not as expected %lg.\n", 412 resultCheb, Dpoly4DChebResult[i]); 413 testStatus = false; 469 414 } 470 415 } 416 471 417 psFree(polyOrd); 472 418 psFree(polyCheb); … … 476 422 // Attempt to evaluation invalid polynomial type 477 423 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type"); 478 result = psPolynomial4DEval(polyOrd,0.0, 0.0, 0.0, 0.0);424 psF64 result = psPolynomial4DEval(polyOrd,0.0, 0.0, 0.0, 0.0); 479 425 if ( !isnan(result) ) { 480 p sError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");481 return 20;426 printf("TEST ERROR: Did not return NAN for invalid polynomial type"); 427 testStatus = false; 482 428 } 483 429 psFree(polyOrd); 484 430 485 return 0;431 return(testStatus); 486 432 } 487 488 /*psS32 testPoly4DEvalVector(void) 489 { 490 // Allocate polynomial 491 psPolynomial4D* polyOrd = psPolynomial4DAlloc(TERMS-1, TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_ORD); 492 psPolynomial4D* polyCheb = psPolynomial4DAlloc(TERMS-1, TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_CHEB); 493 494 // Set polynomial members 495 for(psS32 i = 0; i < TERMS; i++) { 496 for(psS32 j = 0; j < TERMS; j++) { 497 for(psS32 k = 0; k < TERMS; k++) { 498 for(psS32 l = 0; l < TERMS; l++) { 499 polyOrd->coeff[i][j][k][l] = poly4DCoeff[i][j][k][l]; 500 polyOrd->mask[i][j][k][l] = poly4DMask[i][j][k][l]; 501 polyCheb->coeff[i][j][k][l] = 1.0; 502 polyCheb->mask[i][j][k][l] = poly4DMask[i][j][k][l]; 503 } 504 } 505 } 506 } 507 508 // Create input vectors 509 psVector* inputOrdW = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 510 psVector* inputOrdX = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 511 psVector* inputOrdY = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 512 psVector* inputOrdZ = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 513 psVector* inputChebW = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 514 psVector* inputChebX = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 515 psVector* inputChebY = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 516 psVector* inputChebZ = psVectorAlloc(TESTPOINTS, PS_TYPE_F32); 517 for(psS32 i = 0; i < TESTPOINTS; i++) { 518 inputOrdW->data.F32[i] = poly4DWXYZValue[i][0]; 519 inputOrdX->data.F32[i] = poly4DWXYZValue[i][1]; 520 inputOrdY->data.F32[i] = poly4DWXYZValue[i][2]; 521 inputOrdZ->data.F32[i] = poly4DWXYZValue[i][3]; 522 inputChebW->data.F32[i] = poly4DWXYZChebValue[i][0]; 523 inputChebX->data.F32[i] = poly4DWXYZChebValue[i][1]; 524 inputChebY->data.F32[i] = poly4DWXYZChebValue[i][2]; 525 inputChebZ->data.F32[i] = poly4DWXYZChebValue[i][3]; 526 } 527 528 // Evaluate the vectors 529 psVector* outputOrd = psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ); 530 if(outputOrd == NULL) { 531 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL."); 532 return 1; 533 } 534 if(outputOrd->type.type != PS_TYPE_F32) { 535 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d", 536 outputOrd->type.type, PS_TYPE_F32); 537 return 2; 538 } 539 psVector* outputCheb = psPolynomial4DEvalVector(polyCheb,inputChebW,inputChebX,inputChebY,inputChebZ); 540 if(outputCheb == NULL) { 541 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL."); 542 return 1; 543 } 544 if(outputCheb->type.type != PS_TYPE_F32) { 545 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d", 546 outputCheb->type.type, PS_TYPE_F32); 547 return 2; 548 } 549 550 // Verify the results 551 for(psS32 i = 0; i < TESTPOINTS; i++) { 552 if(fabs(poly4DResult[i]-outputOrd->data.F32[i]) > ERROR_TOL) { 553 psError(PS_ERR_UNKNOWN,true,"Result[%d] %g not equal to expected %g", 554 i, outputOrd->data.F32[i], poly4DResult[i]); 555 return i*5; 556 } 557 if(fabs(poly4DChebResult[i]-outputCheb->data.F32[i]) > ERROR_TOL) { 558 psError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %g not equal to expected %g", 559 i, outputCheb->data.F32[i], poly4DChebResult[i]); 560 return i*10; 561 } 562 } 563 564 // Attempt to invoke function with null polynomial 565 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial"); 566 if(psPolynomial4DEvalVector(NULL, inputOrdW, inputOrdX, inputOrdY, inputOrdZ) != NULL) { 567 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial"); 568 return 60; 569 } 570 571 // Attempt to invoke function with null input vector 572 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 573 if(psPolynomial4DEvalVector(polyOrd,NULL,inputOrdX, inputOrdY,inputOrdZ) != NULL) { 574 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector"); 575 return 61; 576 } 577 // Attempt to invoke function with null input vector 578 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 579 if(psPolynomial4DEvalVector(polyOrd, inputOrdW, NULL, inputOrdY, inputOrdZ) != NULL) { 580 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector"); 581 return 62; 582 } 583 // Attempt to invoke function with null input vector 584 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 585 if(psPolynomial4DEvalVector(polyOrd, inputOrdW, inputOrdX,NULL,inputOrdZ) != NULL) { 586 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector"); 587 return 63; 588 } 589 // Attempt to invoke function with null input vector 590 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 591 if(psPolynomial4DEvalVector(polyOrd, inputOrdW, inputOrdX,inputOrdY,NULL) != NULL) { 592 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector"); 593 return 64; 594 } 595 596 // Attempt to invoke function with a non F32 type input vector 597 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 598 inputOrdX->type.type = PS_TYPE_U8; 599 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 600 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector"); 601 return 65; 602 } 603 inputOrdX->type.type = PS_TYPE_F32; 604 // Attempt to invoke function with a non F32 type input vector 605 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 606 inputOrdY->type.type = PS_TYPE_U8; 607 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 608 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector"); 609 return 66; 610 } 611 inputOrdY->type.type = PS_TYPE_F32; 612 // Attempt to invoke function with a non F32 type input vector 613 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 614 inputOrdZ->type.type = PS_TYPE_U8; 615 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 616 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector"); 617 return 67; 618 } 619 inputOrdZ->type.type = PS_TYPE_F32; 620 // Attempt to invoke function with a non F32 type input vector 621 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 622 inputOrdW->type.type = PS_TYPE_U8; 623 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 624 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector"); 625 return 68; 626 } 627 inputOrdW->type.type = PS_TYPE_F32; 628 629 psFree(inputOrdW); 630 psFree(inputOrdX); 631 psFree(inputOrdY); 632 psFree(inputOrdZ); 633 psFree(inputChebW); 634 psFree(inputChebX); 635 psFree(inputChebY); 636 psFree(inputChebZ); 637 psFree(outputOrd); 638 psFree(outputCheb); 639 psFree(polyOrd); 640 psFree(polyCheb); 641 642 return 0; 643 } 644 */ 433 /* 645 434 psS32 testPoly4DEvalVector(void) 646 435 { … … 648 437 psPolynomial4D* polyOrd = psPolynomial4DAlloc(TERMS-1, TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_ORD); 649 438 psPolynomial4D* polyCheb = psPolynomial4DAlloc(TERMS-1, TERMS-1, TERMS-1, TERMS-1, PS_POLYNOMIAL_CHEB); 650 439 651 440 // Set polynomial members 652 441 for(psS32 i = 0; i < TERMS; i++) { … … 662 451 } 663 452 } 664 453 665 454 // Create input vectors 666 455 psVector* inputOrdW = psVectorAlloc(TESTPOINTS, PS_TYPE_F64); … … 682 471 inputChebZ->data.F64[i] = Dpoly4DWXYZChebValue[i][3]; 683 472 } 684 473 685 474 // Evaluate the vectors 686 475 psVector* outputOrd = psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ); 687 476 if(outputOrd == NULL) { 688 p sError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");689 return 1;477 printf("TEST ERROR: Unexpected return of NULL."); 478 testStatus = false; 690 479 } 691 480 if(outputOrd->type.type != PS_TYPE_F64) { 692 p sError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",481 printf("TEST ERROR: Output vector of type %d expected %d", 693 482 outputOrd->type.type, PS_TYPE_F64); 694 return 2;483 testStatus = false; 695 484 } 696 485 psVector* outputCheb = psPolynomial4DEvalVector(polyCheb,inputChebW,inputChebX,inputChebY,inputChebZ); 697 486 if(outputCheb == NULL) { 698 p sError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");699 return 1;487 printf("TEST ERROR: Unexpected return of NULL."); 488 testStatus = false; 700 489 } 701 490 if(outputCheb->type.type != PS_TYPE_F64) { 702 p sError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",491 printf("TEST ERROR: Output vector of type %d expected %d", 703 492 outputCheb->type.type, PS_TYPE_F64); 704 return 2;705 } 706 493 testStatus = false; 494 } 495 707 496 // Verify the results 708 497 for(psS32 i = 0; i < TESTPOINTS; i++) { 709 498 if(fabs(Dpoly4DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) { 710 p sError(PS_ERR_UNKNOWN,true,"Result[%d] %lg not equal to expected %lg",499 printf("TEST ERROR: Result[%d] %lg not equal to expected %lg", 711 500 i, outputOrd->data.F64[i], Dpoly4DResult[i]); 712 return i*5;501 testStatus = false; 713 502 } 714 503 if(fabs(Dpoly4DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) { 715 p sError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %lg not equal to expected %lg",504 printf("TEST ERROR: ResultCheb[%d] %lg not equal to expected %lg", 716 505 i, outputCheb->data.F64[i], Dpoly4DChebResult[i]); 717 return i*10;506 testStatus = false; 718 507 } 719 508 } 720 509 721 510 // Attempt to invoke function with null polynomial 722 511 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial"); 723 512 if(psPolynomial4DEvalVector(NULL,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 724 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");725 return 60;726 } 727 513 printf("TEST ERROR: Return of NULL expected for NULL polynomial"); 514 testStatus = false; 515 } 516 728 517 // Attempt to invoke function with null input vector 729 518 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 730 519 if(psPolynomial4DEvalVector(polyOrd,NULL,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 731 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");732 return 61;520 printf("TEST ERROR: Return of NULL expected for NULL input vector"); 521 testStatus = false; 733 522 } 734 523 // Attempt to invoke function with null input vector 735 524 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 736 525 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,NULL,inputOrdY,inputOrdZ) != NULL) { 737 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");738 return 62;526 printf("TEST ERROR: Return of NULL expected for NULL input vector"); 527 testStatus = false; 739 528 } 740 529 // Attempt to invoke function with null input vector 741 530 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 742 531 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,NULL,inputOrdZ) != NULL) { 743 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");744 return 63;532 printf("TEST ERROR: Return of NULL expected for NULL input vector"); 533 testStatus = false; 745 534 } 746 535 // Attempt to invoke function with null input vector 747 536 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 748 537 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,NULL) != NULL) { 749 p sError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");750 return 64;751 } 752 538 printf("TEST ERROR: Return of NULL expected for NULL input vector"); 539 testStatus = false; 540 } 541 753 542 // Attempt to invoke function with a non F64 type input vector 754 543 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 755 544 inputOrdX->type.type = PS_TYPE_U8; 756 545 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 757 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");758 return 65;546 printf("TEST ERROR: Return NULL expected for non-F64 input vector"); 547 testStatus = false; 759 548 } 760 549 inputOrdX->type.type = PS_TYPE_F64; … … 763 552 inputOrdY->type.type = PS_TYPE_U8; 764 553 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 765 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");766 return 66;554 printf("TEST ERROR: Return NULL expected for non-F64 input vector"); 555 testStatus = false; 767 556 } 768 557 inputOrdY->type.type = PS_TYPE_F64; … … 771 560 inputOrdZ->type.type = PS_TYPE_U8; 772 561 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 773 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");774 return 67;562 printf("TEST ERROR: Return NULL expected for non-F64 input vector"); 563 testStatus = false; 775 564 } 776 565 inputOrdZ->type.type = PS_TYPE_F64; … … 779 568 inputOrdW->type.type = PS_TYPE_U8; 780 569 if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) { 781 p sError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");782 return 68;570 printf("TEST ERROR: Return NULL expected for non-F64 input vector"); 571 testStatus = false; 783 572 } 784 573 inputOrdW->type.type = PS_TYPE_F64; 785 574 786 575 psFree(inputOrdX); 787 576 psFree(inputOrdY); … … 796 585 psFree(polyOrd); 797 586 psFree(polyCheb); 798 799 return 0;587 588 return(testStatus); 800 589 } 801 590 591 */ -
trunk/psLib/test/math/tst_psMinimize04.c
r5090 r5092 62 62 "psVectorFitPolynomial2D(): equal difference in variable fErr"); 63 63 64 printf("TEST: calling psVectorFitPolynomial2D() with f, fErr, y, x as F32 vectors.\n");65 64 psVectorFitPolynomial2D(myPoly, NULL, 0, f, fErr, x, y); 66 65 -
trunk/psLib/test/math/verified/tst_psMinimize04.stderr
r5091 r5092 1 <HOST>|E|psGaussJordan (FILE:LINENO)2 Input matrix contains NaNs.3 <HOST>|E|psGaussJordan (FILE:LINENO)4 Input matrix contains NaNs.5 1 <HOST>|E|psVectorFitPolynomial2D (FILE:LINENO) 6 2 Unallowable operation: polynomial poly or its coeffs is NULL. -
trunk/psLib/test/math/verified/tst_psMinimize04.stdout
r4999 r5092 5 5 \**********************************************************************************/ 6 6 7 TEST: calling psVectorFitPolynomial2D() with f, fErr, y, x as F32 vectors.8 7 Running test with fErr set to NULL. 9 8 Running test with x, y set to NULL. Should generate error. -
trunk/psLib/test/math/verified/tst_psMinimizeVector2D_F32.stderr
r5091 r5092 1 <HOST>|E|psGaussJordan (FILE:LINENO)2 Input matrix contains NaNs.3 <HOST>|E|psGaussJordan (FILE:LINENO)4 Input matrix contains NaNs.5 1 <HOST>|E|psVectorFitPolynomial2D (FILE:LINENO) 6 2 Unallowable operation: polynomial poly or its coeffs is NULL.
Note:
See TracChangeset
for help on using the changeset viewer.
