IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3988


Ignore:
Timestamp:
May 19, 2005, 12:53:47 PM (21 years ago)
Author:
gusciora
Message:

I fixed the bug where the Chebyshev poly had order 1.

Location:
trunk/psLib/src
Files:
3 edited

Legend:

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

    r3884 r3988  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-05-11 22:02:16 $
     9 *  @version $Revision: 1.102 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-05-19 22:53:47 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1313 *
    14  *  XXX: What happens if the polyEval functions are called with data of the wrong
    15  *       type?
    1614 *  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
    1715 *
    1816 *  XXX: In the various polyAlloc(n) functions, n is really the order of the
    1917 *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
    20  *
    21  *  XXX: potential bug: for a multi-dimensional polynomial with order (m, n)
    22  *  the functions in this file currently do not ignore many of the
    23  *  coefficients in the coeff matrix that ...
    24  *
    2518 */
    2619/*****************************************************************************/
     
    255248    PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL);
    256249
     250    printf("HERE: 00\n");
     251
    257252    psPolynomial1D **chebPolys = NULL;
    258253
     
    269264    if (maxChebyPoly > 1) {
    270265        chebPolys[1]->coeff[1] = 1;
    271     }
    272     for (psS32 i = 2; i < maxChebyPoly; i++) {
    273         for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
    274             chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
    275         }
    276         for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
    277             chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    278         }
     266
     267        for (psS32 i = 2; i < maxChebyPoly; i++) {
     268            for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
     269                chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
     270            }
     271            for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
     272                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
     273            }
     274        }
     275    } else {
     276        // XXX: Code this.
     277        printf("WARNING: %d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
    279278    }
    280279
     
    318317{
    319318    PS_FLOAT_CHECK_RANGE(x, -1.0, 1.0, 0.0);
     319    // XXX: Create a macro for this in psConstants.h
     320    if (myPoly->n < 1) {
     321        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %d.", myPoly->n);
     322        return(NAN);
     323    }
    320324    psVector *d;
    321     psS32 n;
     325    psS32 n = myPoly->n;
    322326    psS32 i;
    323     psF32 tmp;
    324 
    325     n = myPoly->n;
     327    psF32 tmp = 0.0;
     328
     329    // Special case where the Chebyshev poly is constant.
     330    if (n == 1) {
     331        if (myPoly->mask[0] == 0) {
     332            tmp += myPoly->coeff[0];
     333        }
     334        return(tmp);
     335    }
     336
     337    // Special case where the Chebyshev poly is linear.
     338    if (n == 2) {
     339        if (myPoly->mask[0] == 0) {
     340            tmp+= myPoly->coeff[0];
     341        }
     342        if (myPoly->mask[1] == 0) {
     343            tmp+= myPoly->coeff[1] * x;
     344        }
     345        return(tmp);
     346    }
     347
     348    // General case where the Chebyshev poly has 2 or more terms.
    326349    d = psVectorAlloc(n, PS_TYPE_F32);
    327350    if(myPoly->mask[n-1] == 0) {
     
    330353        d->data.F32[n-1] = 0.0;
    331354    }
     355
    332356    d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]);
    333357    if(myPoly->mask[n-2] == 0) {
    334358        d->data.F32[n-2] += myPoly->coeff[n-2];
    335359    }
     360
    336361    for (i=n-3;i>=1;i--) {
    337362        d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
     
    350375    return(tmp);
    351376
    352     /*
     377    /* This is old code that does not use Clenshaw's formula.  Get rid of it.
    353378
    354379    psS32 n;
  • trunk/psLib/src/math/psPolynomial.c

    r3884 r3988  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-05-11 22:02:16 $
     9 *  @version $Revision: 1.102 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-05-19 22:53:47 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1313 *
    14  *  XXX: What happens if the polyEval functions are called with data of the wrong
    15  *       type?
    1614 *  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
    1715 *
    1816 *  XXX: In the various polyAlloc(n) functions, n is really the order of the
    1917 *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
    20  *
    21  *  XXX: potential bug: for a multi-dimensional polynomial with order (m, n)
    22  *  the functions in this file currently do not ignore many of the
    23  *  coefficients in the coeff matrix that ...
    24  *
    2518 */
    2619/*****************************************************************************/
     
    255248    PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL);
    256249
     250    printf("HERE: 00\n");
     251
    257252    psPolynomial1D **chebPolys = NULL;
    258253
     
    269264    if (maxChebyPoly > 1) {
    270265        chebPolys[1]->coeff[1] = 1;
    271     }
    272     for (psS32 i = 2; i < maxChebyPoly; i++) {
    273         for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
    274             chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
    275         }
    276         for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
    277             chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    278         }
     266
     267        for (psS32 i = 2; i < maxChebyPoly; i++) {
     268            for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
     269                chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
     270            }
     271            for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
     272                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
     273            }
     274        }
     275    } else {
     276        // XXX: Code this.
     277        printf("WARNING: %d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
    279278    }
    280279
     
    318317{
    319318    PS_FLOAT_CHECK_RANGE(x, -1.0, 1.0, 0.0);
     319    // XXX: Create a macro for this in psConstants.h
     320    if (myPoly->n < 1) {
     321        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %d.", myPoly->n);
     322        return(NAN);
     323    }
    320324    psVector *d;
    321     psS32 n;
     325    psS32 n = myPoly->n;
    322326    psS32 i;
    323     psF32 tmp;
    324 
    325     n = myPoly->n;
     327    psF32 tmp = 0.0;
     328
     329    // Special case where the Chebyshev poly is constant.
     330    if (n == 1) {
     331        if (myPoly->mask[0] == 0) {
     332            tmp += myPoly->coeff[0];
     333        }
     334        return(tmp);
     335    }
     336
     337    // Special case where the Chebyshev poly is linear.
     338    if (n == 2) {
     339        if (myPoly->mask[0] == 0) {
     340            tmp+= myPoly->coeff[0];
     341        }
     342        if (myPoly->mask[1] == 0) {
     343            tmp+= myPoly->coeff[1] * x;
     344        }
     345        return(tmp);
     346    }
     347
     348    // General case where the Chebyshev poly has 2 or more terms.
    326349    d = psVectorAlloc(n, PS_TYPE_F32);
    327350    if(myPoly->mask[n-1] == 0) {
     
    330353        d->data.F32[n-1] = 0.0;
    331354    }
     355
    332356    d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]);
    333357    if(myPoly->mask[n-2] == 0) {
    334358        d->data.F32[n-2] += myPoly->coeff[n-2];
    335359    }
     360
    336361    for (i=n-3;i>=1;i--) {
    337362        d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
     
    350375    return(tmp);
    351376
    352     /*
     377    /* This is old code that does not use Clenshaw's formula.  Get rid of it.
    353378
    354379    psS32 n;
  • trunk/psLib/src/math/psSpline.c

    r3884 r3988  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-05-11 22:02:16 $
     9 *  @version $Revision: 1.102 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-05-19 22:53:47 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1313 *
    14  *  XXX: What happens if the polyEval functions are called with data of the wrong
    15  *       type?
    1614 *  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
    1715 *
    1816 *  XXX: In the various polyAlloc(n) functions, n is really the order of the
    1917 *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
    20  *
    21  *  XXX: potential bug: for a multi-dimensional polynomial with order (m, n)
    22  *  the functions in this file currently do not ignore many of the
    23  *  coefficients in the coeff matrix that ...
    24  *
    2518 */
    2619/*****************************************************************************/
     
    255248    PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL);
    256249
     250    printf("HERE: 00\n");
     251
    257252    psPolynomial1D **chebPolys = NULL;
    258253
     
    269264    if (maxChebyPoly > 1) {
    270265        chebPolys[1]->coeff[1] = 1;
    271     }
    272     for (psS32 i = 2; i < maxChebyPoly; i++) {
    273         for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
    274             chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
    275         }
    276         for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
    277             chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    278         }
     266
     267        for (psS32 i = 2; i < maxChebyPoly; i++) {
     268            for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
     269                chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
     270            }
     271            for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
     272                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
     273            }
     274        }
     275    } else {
     276        // XXX: Code this.
     277        printf("WARNING: %d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
    279278    }
    280279
     
    318317{
    319318    PS_FLOAT_CHECK_RANGE(x, -1.0, 1.0, 0.0);
     319    // XXX: Create a macro for this in psConstants.h
     320    if (myPoly->n < 1) {
     321        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %d.", myPoly->n);
     322        return(NAN);
     323    }
    320324    psVector *d;
    321     psS32 n;
     325    psS32 n = myPoly->n;
    322326    psS32 i;
    323     psF32 tmp;
    324 
    325     n = myPoly->n;
     327    psF32 tmp = 0.0;
     328
     329    // Special case where the Chebyshev poly is constant.
     330    if (n == 1) {
     331        if (myPoly->mask[0] == 0) {
     332            tmp += myPoly->coeff[0];
     333        }
     334        return(tmp);
     335    }
     336
     337    // Special case where the Chebyshev poly is linear.
     338    if (n == 2) {
     339        if (myPoly->mask[0] == 0) {
     340            tmp+= myPoly->coeff[0];
     341        }
     342        if (myPoly->mask[1] == 0) {
     343            tmp+= myPoly->coeff[1] * x;
     344        }
     345        return(tmp);
     346    }
     347
     348    // General case where the Chebyshev poly has 2 or more terms.
    326349    d = psVectorAlloc(n, PS_TYPE_F32);
    327350    if(myPoly->mask[n-1] == 0) {
     
    330353        d->data.F32[n-1] = 0.0;
    331354    }
     355
    332356    d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]);
    333357    if(myPoly->mask[n-2] == 0) {
    334358        d->data.F32[n-2] += myPoly->coeff[n-2];
    335359    }
     360
    336361    for (i=n-3;i>=1;i--) {
    337362        d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
     
    350375    return(tmp);
    351376
    352     /*
     377    /* This is old code that does not use Clenshaw's formula.  Get rid of it.
    353378
    354379    psS32 n;
Note: See TracChangeset for help on using the changeset viewer.