IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 19, 2005, 3:21:13 PM (21 years ago)
Author:
drobbin
Message:

changed psPolynomial fxns to use F64 and removed psDPoly fxns

File:
1 edited

Legend:

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

    r4547 r4581  
    44*  ORD and CHEB type polynomials.
    55*
    6 *  @version  $Revision: 1.1 $  $Name: not supported by cvs2svn $
    7 *  @date  $Date: 2005-07-13 02:47:00 $
     6*  @version  $Revision: 1.2 $  $Name: not supported by cvs2svn $
     7*  @date  $Date: 2005-07-20 01:21:13 $
    88*
    99*  XXX: Probably should test single- and multi-dimensional polynomials in
     
    2222
    2323static psS32 testPoly1DEval(void);
    24 static psS32 testDPoly1DEval(void);
    2524static psS32 testPoly1DEvalVector(void);
    26 static psS32 testDPoly1DEvalVector(void);
    2725
    2826testDescription tests[] = {
    2927                              {testPoly1DEval,000,"psPolynomial1DEval",0,false},
    30                               {testDPoly1DEval,000,"psDPolynomial1DEval",0,false},
    3128                              {testPoly1DEvalVector,000,"psPolynomial1DEvalVector",0,false},
    32                               {testDPoly1DEvalVector,000,"psDPolynomial1DEvalVector",0,false},
    3329                              {NULL}
    3430                          };
     
    5854psS32 testPoly1DEval(void)
    5955{
    60     psF32  result;
    61     psF32  resultCheb;
     56    psF64  result;
     57    psF64  resultCheb;
    6258
    6359    // Allocate polynomial structure
     
    10399}
    104100
    105 // This test will verify operation of 1D polynomial evaluation
    106 psS32 testDPoly1DEval(void)
    107 {
    108     psF64  result;
    109     psF64  resultCheb;
    110 
    111     // Allocate polynomial structure
    112     psDPolynomial1D*  polyOrd = psDPolynomial1DAlloc(TERMS, PS_POLYNOMIAL_ORD);
    113     psDPolynomial1D*  polyCheb = psDPolynomial1DAlloc(TERMS, PS_POLYNOMIAL_CHEB);
    114     // Set polynomial members
    115     for(psS32 i = 0; i < TERMS; i++) {
    116         polyOrd->coeff[i] = Dpoly1DCoeff[i];
    117         polyOrd->mask[i]  = poly1DMask[i];
    118         polyCheb->coeff[i] = 1.0;
    119         polyCheb->mask[i]  = poly1DMask[i];
    120     }
    121     // Evaluate test points and verify results
    122     for(psS32 i = 0; i < TESTPOINTS; i++) {
    123         result = psDPolynomial1DEval(polyOrd,Dpoly1DXValue[i]);
    124         if(fabs(Dpoly1DXResult[i]-result) > ERROR_TOL ) {
    125             psError(PS_ERR_UNKNOWN,true,"Evaluated value %lg not as expected %lg",
    126                     result, Dpoly1DXResult[i]);
    127             return i;
    128         }
    129         resultCheb = psDPolynomial1DEval(polyCheb,Dpoly1DXChebValue[i]);
    130         if(fabs(Dpoly1DXChebResult[i]-resultCheb) > ERROR_TOL ) {
    131             psError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg",
    132                     resultCheb, Dpoly1DXChebResult[i]);
    133             return 5*i;
    134         }
    135     }
    136     psFree(polyOrd);
    137     psFree(polyCheb);
    138 
    139     // Allocate polynomial with invalid type
    140     polyOrd = psDPolynomial1DAlloc(TERMS, 99);
    141     // Attempt to evaluation invalid polynomial type
    142     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type");
    143     result = psDPolynomial1DEval(polyOrd,0.0);
    144     if ( !isnan(result) ) {
    145         psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");
    146         return 20;
    147     }
    148     psFree(polyOrd);
    149 
    150     return 0;
    151 }
    152101
    153102psS32 testPoly1DEvalVector(void)
     
    156105    psPolynomial1D* polyOrd = psPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_ORD);
    157106    psPolynomial1D* polyCheb = psPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_CHEB);
    158 
    159     // Set polynomial members
    160     for(psS32 i = 0; i < TERMS; i++) {
    161         polyOrd->coeff[i] = poly1DCoeff[i];
    162         polyOrd->mask[i]  = poly1DMask[i];
    163         polyCheb->coeff[i] = 1.0;
    164         polyCheb->mask[i]  = poly1DMask[i];
    165     }
    166 
    167     // Create input vectors
    168     psVector* inputOrd = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);
    169     psVector* inputCheb = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);
    170     for(psS32 i = 0; i < TESTPOINTS; i++) {
    171         inputOrd->data.F32[i] = poly1DXValue[i];
    172         inputCheb->data.F32[i] = poly1DXChebValue[i];
    173     }
    174 
    175     // Evaluate the vectors
    176     psVector* outputOrd = psPolynomial1DEvalVector(polyOrd, inputOrd);
    177     if(outputOrd == NULL) {
    178         psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
    179         return 1;
    180     }
    181     if(outputOrd->type.type != PS_TYPE_F32) {
    182         psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",
    183                 outputOrd->type.type, PS_TYPE_F32);
    184         return 2;
    185     }
    186     psVector* outputCheb = psPolynomial1DEvalVector(polyCheb, inputCheb);
    187     if(outputCheb == NULL) {
    188         psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
    189         return 1;
    190     }
    191     if(outputCheb->type.type != PS_TYPE_F32) {
    192         psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",
    193                 outputCheb->type.type, PS_TYPE_F32);
    194         return 2;
    195     }
    196 
    197     // Verify the results
    198     for(psS32 i = 0; i < TESTPOINTS; i++) {
    199         if(fabs(poly1DXResult[i]-outputOrd->data.F32[i]) > ERROR_TOL) {
    200             psError(PS_ERR_UNKNOWN,true,"Result[%d] %g not equal to expected %g",
    201                     i, outputOrd->data.F32[i], poly1DXResult[i]);
    202             return i*5;
    203         }
    204         if(fabs(poly1DXChebResult[i]-outputCheb->data.F32[i]) > ERROR_TOL) {
    205             psError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %g not equal to expected %g",
    206                     i, outputCheb->data.F32[i], poly1DXChebResult[i]);
    207             return i*10;
    208         }
    209     }
    210 
    211     // Attempt to invoke function with null polynomial
    212     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
    213     if(psPolynomial1DEvalVector(NULL, inputOrd) != NULL) {
    214         psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");
    215         return 60;
    216     }
    217 
    218     // Attempt to invoke function with null input vector
    219     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
    220     if(psPolynomial1DEvalVector(polyOrd,NULL) != NULL) {
    221         psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");
    222         return 61;
    223     }
    224 
    225     // Attempt to invoke function with a non F32 type input vector
    226     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
    227     inputOrd->type.type = PS_TYPE_U8;
    228     if(psPolynomial1DEvalVector(polyOrd,inputOrd) != NULL) {
    229         psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector");
    230         return 62;
    231     }
    232     inputOrd->type.type = PS_TYPE_F32;
    233 
    234     psFree(inputOrd);
    235     psFree(inputCheb);
    236     psFree(outputOrd);
    237     psFree(outputCheb);
    238     psFree(polyOrd);
    239     psFree(polyCheb);
    240 
    241     return 0;
    242 }
    243 
    244 psS32 testDPoly1DEvalVector(void)
    245 {
    246     // Allocate polynomial
    247     psDPolynomial1D* polyOrd = psDPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_ORD);
    248     psDPolynomial1D* polyCheb = psDPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_CHEB);
    249107
    250108    // Set polynomial members
     
    265123
    266124    // Evaluate the vectors
    267     psVector* outputOrd = psDPolynomial1DEvalVector(polyOrd, inputOrd);
     125    psVector* outputOrd = psPolynomial1DEvalVector(polyOrd, inputOrd);
    268126    if(outputOrd == NULL) {
    269127        psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
     
    275133        return 2;
    276134    }
    277     psVector* outputCheb = psDPolynomial1DEvalVector(polyCheb, inputCheb);
     135    psVector* outputCheb = psPolynomial1DEvalVector(polyCheb, inputCheb);
    278136    if(outputCheb == NULL) {
    279137        psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
     
    302160    // Attempt to invoke function with null polynomial
    303161    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
    304     if(psDPolynomial1DEvalVector(NULL, inputOrd) != NULL) {
     162    if(psPolynomial1DEvalVector(NULL, inputOrd) != NULL) {
    305163        psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");
    306164        return 60;
     
    309167    // Attempt to invoke function with null input vector
    310168    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
    311     if(psDPolynomial1DEvalVector(polyOrd,NULL) != NULL) {
     169    if(psPolynomial1DEvalVector(polyOrd,NULL) != NULL) {
    312170        psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");
    313171        return 61;
     
    317175    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
    318176    inputOrd->type.type = PS_TYPE_U8;
    319     if(psDPolynomial1DEvalVector(polyOrd,inputOrd) != NULL) {
     177    if(psPolynomial1DEvalVector(polyOrd,inputOrd) != NULL) {
    320178        psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");
    321179        return 62;
Note: See TracChangeset for help on using the changeset viewer.