IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12434


Ignore:
Timestamp:
Mar 13, 2007, 4:36:28 PM (19 years ago)
Author:
magnier
Message:

changing p_psVectorBinDisect to psVectorBinaryDisect, adding psVectorBinaryDisectResult

Location:
trunk/psLib/src/math
Files:
4 edited

Legend:

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

    r11759 r12434  
    55 *  @author GLG (MHPCC), EAM (IfA)
    66 *
    7  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-02-13 03:01:24 $
     7 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-03-14 02:36:28 $
    99 *
    1010 *  Copyright 2006 IfA, University of Hawaii
     
    306306                    // correct bin number requires a bit more work.
    307307                    tmpScalar.data.F32 = inF32->data.F32[i];
    308                     binNum = p_psVectorBinDisect( *(psVector* *)&out->bounds, &tmpScalar);
    309                     if (binNum < 0) {
    310                         psLogMsg(__func__, PS_LOG_WARN,
    311                                  "WARNING: psVectorHistogram(): element outside histogram bounds.\n");
    312                     } else {
    313                         if (errorsF32 != NULL) {
    314                             if (!UpdateHistogramBins(binNum, out, inF32->data.F32[i], errors->data.F32[i])) {
    315                                 psLogMsg(__func__, PS_LOG_WARN, "WARNING: Failed to update the histogram "
    316                                          "bins with the errors vector.\n");
    317                             }
    318                         } else {
    319                             out->nums->data.F32[binNum] += 1.0;
    320                         }
    321                     }
     308                    psVectorBinaryDisectResult result;
     309                    binNum = psVectorBinaryDisect(&result, out->bounds, &tmpScalar);
     310                    if (result != PS_BINARY_DISECT_PASS) {
     311                        continue;
     312                    }
     313                    if (errorsF32 != NULL) {
     314                        if (!UpdateHistogramBins(binNum, out, inF32->data.F32[i], errors->data.F32[i])) {
     315                            psLogMsg(__func__, PS_LOG_WARN, "WARNING: Failed to update the histogram "
     316                                     "bins with the errors vector.\n");
     317                        }
     318                    } else {
     319                        out->nums->data.F32[binNum] += 1.0;
     320                    }
    322321                }
    323322            }
  • trunk/psLib/src/math/psMathUtils.c

    r10999 r12434  
    33 *  This file contains standard math routines.
    44 *
    5  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-01-09 22:38:53 $
     5 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-03-14 02:36:28 $
    77 *
    88 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3131#include "psAssert.h"
    3232#include "psConstants.h"
     33#include "psAbort.h"
    3334
    3435/*****************************************************************************/
     
    5556This is a macro covering the various types for the below function.
    5657 *****************************************************************************/
    57 #define VECTOR_BIN_DISECT_CASE(TYPE) \
     58#define VECTOR_BINARY_DISECT_CASE(TYPE) \
    5859case PS_TYPE_##TYPE: { \
    5960    ps##TYPE *bounds = bins->data.TYPE; \
     
    6566    /* psTrace("psLib.math", 6, "Determining the bin for: %f\n", x); */\
    6667    if (value < bounds[0]) { \
    67         psLogMsg(__func__, PS_LOG_WARN, \
    68                  "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
    69                  #TYPE, (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
    70         return(-2); \
     68        psTrace("psLib.math", 3, \
     69                 "psVectorBinaryDisect : ordinate %f is outside vector range (%f - %f).", \
     70                 (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
     71        *status = PS_BINARY_DISECT_OUTSIDE_RANGE; \
     72        return (0); \
    7173    } \
    7274    if (value > bounds[numBins-1]) { \
    73         psLogMsg(__func__, PS_LOG_WARN, \
    74                  "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
    75                  #TYPE, (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
    76         return(-1); \
     75        psTrace("psLib.math", 3, \
     76                 "psVectorBinaryDisect : ordinate %f is outside vector range (%f - %f).", \
     77                 (double)value, (double)bounds[0], (double)bounds[numBins-1]); \
     78        *status = PS_BINARY_DISECT_OUTSIDE_RANGE; \
     79        return (numBins-1); \
    7780    } \
    7881    \
     
    97100
    98101/*****************************************************************************
    99 p_psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data.
     102psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data.
    100103The input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all i).  This routine does a
    101104binary disection of the vector and returns "i" such that (v[i] <= x <= v[i+1).  If x lies outside the range of
    102105v[], then this routine prints a warning message and returns (-2 or -1).
    103106  *****************************************************************************/
    104 psS32 p_psVectorBinDisect(
     107psS32 psVectorBinaryDisect(
     108    psVectorBinaryDisectResult *status,
    105109    const psVector *bins,
    106110    const psScalar *x)
    107111{
    108     PS_ASSERT_VECTOR_NON_NULL(bins, -4);
    109     PS_ASSERT_VECTOR_NON_EMPTY(bins, -4);
    110     PS_ASSERT_PTR_NON_NULL(x, -6);
    111     PS_ASSERT_PTR_TYPE_EQUAL(x, bins, -3);
     112    PS_ASSERT_GENERAL_VECTOR_NON_NULL (bins, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
     113    PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(bins, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
     114    PS_ASSERT_GENERAL_PTR_NON_NULL(x, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
     115    PS_ASSERT_GENERAL_PTR_TYPE_EQUAL(x, bins, *status = PS_BINARY_DISECT_INVALID_INPUT; return 0);
    112116    long numBins = bins->n;             // Number of bins
    113117
     118    *status = PS_BINARY_DISECT_PASS;
     119
    114120    switch (x->type.type) {
    115         VECTOR_BIN_DISECT_CASE(S8);
    116         VECTOR_BIN_DISECT_CASE(S16);
    117         VECTOR_BIN_DISECT_CASE(S32);
    118         VECTOR_BIN_DISECT_CASE(S64);
    119         VECTOR_BIN_DISECT_CASE(U8);
    120         VECTOR_BIN_DISECT_CASE(U16);
    121         VECTOR_BIN_DISECT_CASE(U32);
    122         VECTOR_BIN_DISECT_CASE(U64);
    123         VECTOR_BIN_DISECT_CASE(F32);
    124         VECTOR_BIN_DISECT_CASE(F64);
     121        VECTOR_BINARY_DISECT_CASE(S8);
     122        VECTOR_BINARY_DISECT_CASE(S16);
     123        VECTOR_BINARY_DISECT_CASE(S32);
     124        VECTOR_BINARY_DISECT_CASE(S64);
     125        VECTOR_BINARY_DISECT_CASE(U8);
     126        VECTOR_BINARY_DISECT_CASE(U16);
     127        VECTOR_BINARY_DISECT_CASE(U32);
     128        VECTOR_BINARY_DISECT_CASE(U64);
     129        VECTOR_BINARY_DISECT_CASE(F32);
     130        VECTOR_BINARY_DISECT_CASE(F64);
    125131    default: {
    126132            char* strType;
    127133            PS_TYPE_NAME(strType, x->type.type);
    128134            psError(PS_ERR_BAD_PARAMETER_TYPE, "psLib type %s is not supported.", strType);
    129             return -1;
     135            *status = PS_BINARY_DISECT_INVALID_TYPE;
     136            return 0;
    130137        }
    131138    }
    132     return(-3);
     139    psAbort ("programming error");
     140    return (0);
    133141}
    134142
     
    151159    } \
    152160    psVector *p = psVectorCopy(NULL, range, PS_TYPE_##TYPE); \
    153     psS32 binNum = p_psVectorBinDisect(domain, x); \
     161    psVectorBinaryDisectResult result; \
     162    psS32 binNum = psVectorBinaryDisect(&result, domain, x); \
    154163    \
    155164    psS32 numIntPoints = order+1; \
  • trunk/psLib/src/math/psMathUtils.h

    r11248 r12434  
    66 * @author GLG, MHPCC
    77 *
    8  * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-01-23 22:47:23 $
     8 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2007-03-14 02:36:28 $
    1010 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1111 */
     
    2525#include "psPolynomial.h"
    2626
     27typedef enum {
     28    PS_BINARY_DISECT_PASS,
     29    PS_BINARY_DISECT_OUTSIDE_RANGE,
     30    PS_BINARY_DISECT_INVALID_INPUT,
     31    PS_BINARY_DISECT_INVALID_TYPE,
     32} psVectorBinaryDisectResult;
     33
    2734/** Performs a binary disection on a monotonically non-decreasing vector.
    2835 *  Searches through an array of data for a specified value.
     
    3037 *  @return psS32    corresponding index number of specified value
    3138 */
    32 psS32 p_psVectorBinDisect(
     39psS32 psVectorBinaryDisect(
     40    psVectorBinaryDisectResult *status,
    3341    const psVector *bins,               ///< Array of non-decreasing values
    3442    const psScalar *x                   ///< Target value to find
  • trunk/psLib/src/math/psSpline.c

    r10999 r12434  
    66*  This file contains the routines that allocate, free, and evaluate splines.
    77*
    8 *  @version $Revision: 1.157 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2007-01-09 22:38:53 $
     8*  @version $Revision: 1.158 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2007-03-14 02:36:28 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    386386    tmpScalar.type.type = PS_TYPE_F32;
    387387    tmpScalar.data.F32 = x;
    388     psS32 binNum = p_psVectorBinDisect(spline->knots, &tmpScalar);
    389     if (binNum < 0) {
     388    psVectorBinaryDisectResult result;
     389    psS32 binNum = psVectorBinaryDisect(&result, spline->knots, &tmpScalar);
     390    if (result != PS_BINARY_DISECT_PASS) {
    390391        psError(PS_ERR_UNKNOWN, false, "Could not perform bin dissection on spline->knots.\n");
    391392        return(NAN);
Note: See TracChangeset for help on using the changeset viewer.