IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 16, 2006, 2:56:48 PM (20 years ago)
Author:
gusciora
Message:

* empty log message *

File:
1 edited

Legend:

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

    r6348 r6437  
    44*         routines.
    55*
    6 *  This file will hold the functions for allocated, freeing, and evaluating
     6*  This file will hold the routiness for allocating, freeing, and evaluating
    77*  polynomials.  It also contains a Gaussian functions.
    88*
    9 *  @version $Revision: 1.142 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-02-07 23:36:15 $
     9*  @version $Revision: 1.143 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-02-17 00:56:48 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    159159used frequently and the data structure created here does not contain the
    160160outer coefficients of the Chebyshev polynomials.
    161  
    162161 *****************************************************************************/
    163162psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys)
     
    165164    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL);
    166165
    167     if (0) {
    168         psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
    169         for (psS32 i = 0; i < numPolys; i++) {
    170             chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
    171             chebPolys[i]->coeff[i] = 1;
    172         }
    173         return (chebPolys);
    174     } else {
    175         psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
    176         for (psS32 i = 0; i < numPolys; i++) {
    177             chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
    178         }
    179 
    180         // Create the Chebyshev polynomials.
    181         // Polynomial i has i-th order.
    182         chebPolys[0]->coeff[0] = 1.0;
    183         if (numPolys >= 2) {
    184             chebPolys[1]->coeff[1] = 1.0;
    185 
    186             for (psS32 i = 2; i < numPolys; i++) {
    187                 for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) {
    188                     chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j];
    189                 }
    190                 for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) {
    191                     chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    192                 }
    193             }
    194         }
    195 
    196         if (psTraceGetLevel(__func__) >= 6) {
    197             for (psS32 j = 0; j < numPolys; j++) {
    198                 PS_POLY_PRINT_1D(chebPolys[j]);
    199             }
    200         }
    201         return (chebPolys);
    202     }
     166    psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
     167    for (psS32 i = 0; i < numPolys; i++) {
     168        chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
     169    }
     170
     171    // Create the Chebyshev polynomials.
     172    // Polynomial i has i-th order.
     173    chebPolys[0]->coeff[0] = 1.0;
     174    if (numPolys >= 2) {
     175        chebPolys[1]->coeff[1] = 1.0;
     176
     177        for (psS32 i = 2; i < numPolys; i++) {
     178            for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) {
     179                chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j];
     180            }
     181            for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) {
     182                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
     183            }
     184        }
     185    }
     186
     187    if (psTraceGetLevel(__func__) >= 6) {
     188        for (psS32 j = 0; j < numPolys; j++) {
     189            PS_POLY_PRINT_1D(chebPolys[j]);
     190        }
     191    }
     192    return (chebPolys);
    203193}
    204194
     
    223213    for (loop_x = 0; loop_x < poly->nX+1; loop_x++) {
    224214        if (poly->mask[loop_x] == 0) {
    225             // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to
    226             // 2 or higher in the test code, you get seg faults.
    227215            psTrace(__func__, 8,
    228216                    "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]);
     
    238226// XXX: You can do this without having to psAlloc() vector d.
    239227// XXX: How does the mask vector effect Crenshaw's formula?
    240 // XXX: We assume that x is scaled between -1.0 and 1.0;
     228// NOTE: We assume that x is scaled between -1.0 and 1.0;
    241229// XXX: Create a faster version for low-order Chebyshevs.
    242230static psF64 chebPolynomial1DEval(
     
    298286        psFree(d);
    299287    } else {
    300         // This is old code that does not use Clenshaw's formula.  Get rid of it.
     288        // XXX: This is old code that does not use Clenshaw's formula.  Get rid of it.
    301289        psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX);
    302290
Note: See TracChangeset for help on using the changeset viewer.