IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 18, 2005, 4:55:54 PM (21 years ago)
Author:
gusciora
Message:

New version of spline fit functions in the SDRS.

File:
1 edited

Legend:

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

    r4547 r4580  
    99XXX: The spline eval functions are F32 only, while the spline fit functions
    1010are F32 and F64.
     11 
     12XXX: Must call the spline fit functions with unallowable input parameters.
    1113 *****************************************************************************/
    1214#include <stdio.h>
     
    1719#include "psFunctions.h"
    1820
     21#define VERBOSE 0
    1922#define NUM_SPLINES 50
    2023#define A 4.0
     
    5154    newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32);
    5255    y = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32);
    53     tmpSpline = psSpline1DAlloc(NUM_SPLINES, 3, MIN, MAX);
     56
     57
     58    psF32 width = (MAX - MIN) / ((psF32) NUM_SPLINES);
     59    x->data.F32[0] = MIN;
     60    for (psS32 i=1;i<NUM_SPLINES;i++) {
     61        x->data.F32[i] = MIN + (width * (psF32) i);
     62    }
     63    x->data.F32[NUM_SPLINES] = MAX;
    5464
    5565    for (i=0;i<NUM_SPLINES+1;i++) {
    56         x->data.F32[i] = tmpSpline->knots->data.F32[i];
    5766        y->data.F32[i] = myFunc(x->data.F32[i]);
    5867    }
     
    6978                            "psSpline1DAlloc(), psVectorFitSpline1D, psSpline1DEvalVector: F32 versions");
    7079
    71     psVectorFitSpline1D(tmpSpline, x, y, NULL);
    72     newY = psSpline1DEvalVector(
    73                tmpSpline,
    74                newX
    75            );
    76 
    77     for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) {
    78         if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) {
    79             printf("ERROR[%d]: f(%f) is %f.  Should be %f\n", i,
    80                    newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i]));
    81             testStatus = false;
     80    tmpSpline = psVectorFitSpline1DNEW(x, y, NUM_SPLINES);
     81    if (tmpSpline == NULL) {
     82        printf("TEST ERROR: psVectorFitSpline1DNEW() returned NULL.\n");
     83        testStatus = false;
     84    } else {
     85        newY = psSpline1DEvalVector(tmpSpline, newX);
     86
     87        for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) {
     88            if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) {
     89                printf("ERROR[%d]: f(%f) is %f.  Should be %f\n", i,
     90                       newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i]));
     91                testStatus = false;
     92            } else {
     93                if (VERBOSE) {
     94                    printf("COOL[%d]: f(%f) is %f.  Should be %f\n", i,
     95                           newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i]));
     96                }
     97            }
    8298        }
    83     }
    84 
     99        psFree(tmpSpline);
     100        psFree(newY);
     101    }
    85102    psFree(x);
     103    psFree(y);
    86104    psFree(newX);
    87     psFree(y);
    88     psFree(tmpSpline);
    89     psFree(newY);
    90105
    91106    psMemCheckCorruption(1);
     
    123138    newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F64);
    124139    y = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F64);
    125     tmpSpline = psSpline1DAlloc(NUM_SPLINES, 3, MIN, MAX);
     140
     141    psF64 width = (MAX - MIN) / ((psF32) NUM_SPLINES);
     142    x->data.F64[0] = MIN;
     143    for (psS32 i=1;i<NUM_SPLINES;i++) {
     144        x->data.F64[i] = MIN + (width * (psF64) i);
     145    }
     146    x->data.F64[NUM_SPLINES] = MAX;
    126147
    127148    for (i=0;i<NUM_SPLINES+1;i++) {
    128         x->data.F64[i] = tmpSpline->knots->data.F32[i];
    129149        y->data.F64[i] = myFunc(x->data.F64[i]);
    130150    }
     
    141161                            "psSpline1DAlloc(), psVectorFitSpline1D, psSpline1DEvalVector: F64 versions");
    142162
    143     psVectorFitSpline1D(tmpSpline, x, y, NULL);
    144     newY = psSpline1DEvalVector(
    145                tmpSpline,
    146                newX
    147            );
    148 
    149     for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) {
    150         if ( fabs( newY->data.F32[i] - myFunc(newX->data.F64[i]) ) > fabs( ERROR_TOLERANCE * myFunc((float)newX->data.F64[i]) ) ) {
    151             printf("ERROR[%d]: f(%f) is %f.  Should be %f\n", i,
    152                    newX->data.F64[i], newY->data.F32[i], myFunc((float)newX->data.F64[i]));
    153             testStatus = false;
     163    tmpSpline = psVectorFitSpline1DNEW(x, y, NUM_SPLINES);
     164    if (tmpSpline == NULL) {
     165        printf("TEST ERROR: psVectorFitSpline1DNEW() returned NULL.\n");
     166        testStatus = false;
     167    } else {
     168        newY = psSpline1DEvalVector(tmpSpline, newX);
     169
     170        for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) {
     171            if ( fabs( newY->data.F32[i] - myFunc(newX->data.F64[i]) ) > fabs( ERROR_TOLERANCE * myFunc((float)newX->data.F64[i]) ) ) {
     172                printf("ERROR[%d]: f(%f) is %f.  Should be %f\n", i,
     173                       newX->data.F64[i], newY->data.F32[i], myFunc((float)newX->data.F64[i]));
     174                testStatus = false;
     175            } else {
     176                if (VERBOSE) {
     177                    printf("COOL[%d]: f(%f) is %f.  Should be %f\n", i,
     178                           newX->data.F64[i], newY->data.F32[i], myFunc((float)newX->data.F64[i]));
     179                }
     180            }
    154181        }
    155     }
    156 
     182        psFree(tmpSpline);
     183        psFree(newY);
     184    }
    157185    psFree(x);
    158186    psFree(newX);
    159187    psFree(y);
    160     psFree(tmpSpline);
    161     psFree(newY);
    162188
    163189    psMemCheckCorruption(1);
     
    177203psS32 main()
    178204{
    179     //    t00();
     205    psLogSetFormat("HLNM");
     206    t00();
    180207    t01();
    181208}
Note: See TracChangeset for help on using the changeset viewer.