IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4580


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

New version of spline fit functions in the SDRS.

Location:
trunk/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psFunctions.c

    r4570 r4580  
    11/** @file  psFunctions.c
    2  *
    3  *  @brief Contains basic function allocation, deallocation, and evaluation
    4  *         routines.
    5  *
    6  *  This file will hold the functions for allocated, freeing, and evaluating
    7  *  polynomials.  It also contains a Gaussian functions.
    8  *
    9  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-07-16 00:42:28 $
    11  *
    12  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    13  *
    14  *  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
    15  *
    16  *  XXX: In the various polyAlloc(n) functions, n is really the order of the
    17  *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
    18  */
     2*
     3*  @brief Contains basic function allocation, deallocation, and evaluation
     4*         routines.
     5*
     6*  This file will hold the functions for allocated, freeing, and evaluating
     7*  polynomials.  It also contains a Gaussian functions.
     8*
     9*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2005-07-19 02:55:54 $
     11*
     12*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     13*
     14*  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
     15*
     16*  XXX: In the various polyAlloc(n) functions, n is really the order of the
     17*  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
     18*/
    1919/*****************************************************************************/
    2020/*  INCLUDE FILES                                                            */
     
    19181918    for (psS32 i=0;i<bounds->n-1;i++) {
    19191919        if (FLT_EPSILON >= fabs(bounds->data.F32[i+1]-bounds->data.F32[i])) {
    1920             psError(PS_ERR_UNKNOWN, true, "data points must be distinct\n");
     1920            psError(PS_ERR_UNKNOWN, true, "data points must be distinct ([%d] %f %f)\n", i, bounds->data.F32[i], bounds->data.F32[i+1]);
    19211921            return(NULL);
    19221922        }
  • trunk/psLib/src/math/psMinimize.c

    r4570 r4580  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.126 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-07-16 00:42:28 $
     11 *  @version $Revision: 1.127 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-07-19 02:55:54 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    520520    psVector *y32 = yPtr;
    521521
    522 
    523522    // If these are linear splines, which means their polynomials will have
    524523    // two coefficients, then we do the simple calculation.
     
    638637    psTrace(".psLib.dataManip.psVectorFitSpline1D", 4,
    639638            "---- psVectorFitSpline1D() end ----\n");
     639
    640640    return(mySpline);
    641641}
  • 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.