IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 22, 2005, 10:45:43 AM (21 years ago)
Author:
gusciora
Message:

Implementing the polynomial nTerm -> nOrder switch,

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/math/tst_psFunc10.c

    r5090 r5092  
    44*  ORD and CHEB type polynomials.
    55*
    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 $
    88*
    99* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    2222
    2323testDescription 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},
    2626                              {NULL}
    2727                          };
     
    133133
    134134// This test will verify operation of 1D polynomial evaluation
    135 /*psS32 testPoly3DEval(void)
    136 {
    137     psF32  result;
    138     psF32  resultCheb;
    139  
    140     // Allocate polynomial structure
    141     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 members
    144     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 results
    155     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 type
    175     polyOrd = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1, 99);
    176     // Attempt to evaluation invalid polynomial type
    177     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 evaluation
    189135psS32 testPoly3DEval(void)
    190136{
    191137    psF64  result;
    192138    psF64  resultCheb;
     139    psBool testStatus = true;
    193140
    194141    // Allocate polynomial structure
     
    211158                                    Dpoly3DXYZValue[i][2]);
    212159        if(fabs(Dpoly3DResult[i]-result) > ERROR_TOL ) {
    213             psError(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;
    216163        }
    217164        resultCheb = psPolynomial3DEval(polyCheb,Dpoly3DXYZChebValue[i][0],Dpoly3DXYZChebValue[i][1],
    218165                                        Dpoly3DXYZChebValue[i][2]);
    219166        if(fabs(Dpoly3DChebResult[i]-resultCheb) > ERROR_TOL ) {
    220             psError(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;
    223170        }
    224171    }
     
    232179    result = psPolynomial3DEval(polyOrd,0.0, 0.0, 0.0);
    233180    if ( !isnan(result) ) {
    234         psError(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;
    236183    }
    237184    psFree(polyOrd);
     
    240187}
    241188
    242 /*psS32 testPoly3DEvalVector(void)
    243 {
    244     // Allocate polynomial
    245     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 members
    249     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 vectors
    261     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 vectors
    277     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 results
    299     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 polynomial
    313     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 vector
    320     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 vector
    326     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 vector
    332     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 vector
    339     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 vector
    347     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 vector
    355     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 */
    377189psS32 testPoly3DEvalVector(void)
    378190{
     191    psBool testStatus = true;
    379192    // Allocate polynomial
    380193    psPolynomial3D* polyOrd = psPolynomial3DAlloc(TERMS-1, TERMS-1, TERMS-1,PS_POLYNOMIAL_ORD);
     
    412225    psVector* outputOrd = psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ);
    413226    if(outputOrd == NULL) {
    414         psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
    415         return 1;
     227        printf("TEST ERROR: Unexpected return of NULL.\n");
     228        testStatus = false;
    416229    }
    417230    if(outputOrd->type.type != PS_TYPE_F64) {
    418         psError(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;
    421234    }
    422235    psVector* outputCheb = psPolynomial3DEvalVector(polyCheb,inputChebX,inputChebY,inputChebZ);
    423236    if(outputCheb == NULL) {
    424         psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
    425         return 1;
     237        printf("TEST ERROR: Unexpected return of NULL.\n");
     238        testStatus = false;
    426239    }
    427240    if(outputCheb->type.type != PS_TYPE_F64) {
    428         psError(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;
    431244    }
    432245
     
    434247    for(psS32 i = 0; i < TESTPOINTS; i++) {
    435248        if(fabs(Dpoly3DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) {
    436             psError(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;
    439252        }
    440253        if(fabs(Dpoly3DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) {
    441             psError(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;
    444257        }
    445258    }
     
    448261    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
    449262    if(psPolynomial3DEvalVector(NULL,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
    450         psError(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;
    452265    }
    453266
     
    455268    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
    456269    if(psPolynomial3DEvalVector(polyOrd,NULL,inputOrdY,inputOrdZ) != NULL) {
    457         psError(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;
    459272    }
    460273    // Attempt to invoke function with null input vector
    461274    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
    462275    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,NULL,inputOrdZ) != NULL) {
    463         psError(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;
    465278    }
    466279    // Attempt to invoke function with null input vector
    467280    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
    468281    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,NULL) != NULL) {
    469         psError(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;
    471284    }
    472285
     
    475288    inputOrdX->type.type = PS_TYPE_U8;
    476289    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
    477         psError(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;
    479292    }
    480293    inputOrdX->type.type = PS_TYPE_F64;
     
    483296    inputOrdY->type.type = PS_TYPE_U8;
    484297    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
    485         psError(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;
    487300    }
    488301    inputOrdY->type.type = PS_TYPE_F64;
     
    491304    inputOrdZ->type.type = PS_TYPE_U8;
    492305    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
    493         psError(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;
    495308    }
    496309    inputOrdZ->type.type = PS_TYPE_F64;
Note: See TracChangeset for help on using the changeset viewer.