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_psFunc09.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                               {testPoly2DEval,583,"psPolynomial2DEval",0,false},
    25                               {testPoly2DEvalVector,000,"psPolynomial2DEvalVector",0,false},
     24                              {testPoly2DEval,583,"psPolynomial2DEval",true,false},
     25                              {testPoly2DEvalVector,000,"psPolynomial2DEvalVector",true,false},
    2626                              {NULL}
    2727                          };
     
    8282
    8383// This test will verify operation of 1D polynomial evaluation
    84 /*psS32 testPoly2DEval(void)
     84psS32 testPoly2DEval(void)
    8585{
    86     psF32  result;
    87     psF32  resultCheb;
    88  
     86    psF64  result;
     87    psF64  resultCheb;
     88    psBool testStatus = true;
     89
    8990    // Allocate polynomial structure
    9091    psPolynomial2D*  polyOrd = psPolynomial2DAlloc(TERMS-1, TERMS-1, PS_POLYNOMIAL_ORD);
     
    101102    // Evaluate test points and verify results
    102103    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;
    114113        }
    115114    }
    116115    psFree(polyOrd);
    117116    psFree(polyCheb);
    118  
     117
    119118    // Allocate polynomial with invalid type
    120119    polyOrd = psPolynomial2DAlloc(TERMS-1, TERMS-1, 99);
     
    124123    if ( !isnan(result) ) {
    125124        psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");
    126         return 20;
     125        testStatus = false;
    127126    }
    128127    psFree(polyOrd);
    129  
    130     return 0;
     128
     129    return(testStatus);
    131130}
    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
    296132psS32 testPoly2DEvalVector(void)
    297133{
     134    psBool testStatus = true;
    298135    // Allocate polynomial
    299136    psPolynomial2D* polyOrd = psPolynomial2DAlloc(TERMS-1,TERMS-1,PS_POLYNOMIAL_ORD);
     
    325162    psVector* outputOrd = psPolynomial2DEvalVector(polyOrd, inputOrdX, inputOrdY);
    326163    if(outputOrd == NULL) {
    327         psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
    328         return 1;
     164        printf("TEST ERROR: Unexpected return of NULL.\n");
     165        testStatus = false;
    329166    }
    330167    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;
    334170    }
    335171    psVector* outputCheb = psPolynomial2DEvalVector(polyCheb, inputChebX, inputChebY);
    336172    if(outputCheb == NULL) {
    337         psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
    338         return 1;
     173        printf("TEST ERROR: Unexpected return of NULL.\n");
     174        testStatus = false;
    339175    }
    340176    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;
    344179    }
    345180
     
    347182    for(psS32 i = 0; i < TESTPOINTS; i++) {
    348183        if(fabs(poly2DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) {
    349             psError(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;
    352187        }
    353188        if(fabs(poly2DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) {
    354             psError(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;
    357192        }
    358193    }
     
    361196    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
    362197    if(psPolynomial2DEvalVector(NULL, inputOrdX, inputOrdY) != NULL) {
    363         psError(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;
    365200    }
    366201
     
    368203    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
    369204    if(psPolynomial2DEvalVector(polyOrd,NULL,inputOrdY) != NULL) {
    370         psError(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;
    372207    }
    373208    // Attempt to invoke function with null input vector
    374209    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
    375210    if(psPolynomial2DEvalVector(polyOrd,inputOrdX,NULL) != NULL) {
    376         psError(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;
    378213    }
    379214
     
    382217    inputOrdX->type.type = PS_TYPE_U8;
    383218    if(psPolynomial2DEvalVector(polyOrd,inputOrdX, inputOrdY) != NULL) {
    384         psError(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;
    386221    }
    387222    inputOrdX->type.type = PS_TYPE_F64;
     
    390225    inputOrdY->type.type = PS_TYPE_U8;
    391226    if(psPolynomial2DEvalVector(polyOrd,inputOrdX, inputOrdY) != NULL) {
    392         psError(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;
    394229    }
    395230    inputOrdY->type.type = PS_TYPE_F64;
     
    404239    psFree(polyCheb);
    405240
    406     return 0;
     241    return(testStatus);
    407242}
    408243
Note: See TracChangeset for help on using the changeset viewer.