Changeset 12434
- Timestamp:
- Mar 13, 2007, 4:36:28 PM (19 years ago)
- Location:
- trunk/psLib/src/math
- Files:
-
- 4 edited
-
psHistogram.c (modified) (2 diffs)
-
psMathUtils.c (modified) (6 diffs)
-
psMathUtils.h (modified) (3 diffs)
-
psSpline.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psHistogram.c
r11759 r12434 5 5 * @author GLG (MHPCC), EAM (IfA) 6 6 * 7 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 2-13 03:01:24$7 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-03-14 02:36:28 $ 9 9 * 10 10 * Copyright 2006 IfA, University of Hawaii … … 306 306 // correct bin number requires a bit more work. 307 307 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 } 322 321 } 323 322 } -
trunk/psLib/src/math/psMathUtils.c
r10999 r12434 3 3 * This file contains standard math routines. 4 4 * 5 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 1-09 22:38:53$5 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-03-14 02:36:28 $ 7 7 * 8 8 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 31 31 #include "psAssert.h" 32 32 #include "psConstants.h" 33 #include "psAbort.h" 33 34 34 35 /*****************************************************************************/ … … 55 56 This is a macro covering the various types for the below function. 56 57 *****************************************************************************/ 57 #define VECTOR_BIN _DISECT_CASE(TYPE) \58 #define VECTOR_BINARY_DISECT_CASE(TYPE) \ 58 59 case PS_TYPE_##TYPE: { \ 59 60 ps##TYPE *bounds = bins->data.TYPE; \ … … 65 66 /* psTrace("psLib.math", 6, "Determining the bin for: %f\n", x); */\ 66 67 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); \ 71 73 } \ 72 74 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); \ 77 80 } \ 78 81 \ … … 97 100 98 101 /***************************************************************************** 99 p _psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data.102 psVectorBinDisect(): This function takes as input an array of data as well as a single value for that data. 100 103 The input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all i). This routine does a 101 104 binary disection of the vector and returns "i" such that (v[i] <= x <= v[i+1). If x lies outside the range of 102 105 v[], then this routine prints a warning message and returns (-2 or -1). 103 106 *****************************************************************************/ 104 psS32 p_psVectorBinDisect( 107 psS32 psVectorBinaryDisect( 108 psVectorBinaryDisectResult *status, 105 109 const psVector *bins, 106 110 const psScalar *x) 107 111 { 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); 112 116 long numBins = bins->n; // Number of bins 113 117 118 *status = PS_BINARY_DISECT_PASS; 119 114 120 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); 125 131 default: { 126 132 char* strType; 127 133 PS_TYPE_NAME(strType, x->type.type); 128 134 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; 130 137 } 131 138 } 132 return(-3); 139 psAbort ("programming error"); 140 return (0); 133 141 } 134 142 … … 151 159 } \ 152 160 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); \ 154 163 \ 155 164 psS32 numIntPoints = order+1; \ -
trunk/psLib/src/math/psMathUtils.h
r11248 r12434 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 1-23 22:47:23$8 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-03-14 02:36:28 $ 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 11 11 */ … … 25 25 #include "psPolynomial.h" 26 26 27 typedef 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 27 34 /** Performs a binary disection on a monotonically non-decreasing vector. 28 35 * Searches through an array of data for a specified value. … … 30 37 * @return psS32 corresponding index number of specified value 31 38 */ 32 psS32 p_psVectorBinDisect( 39 psS32 psVectorBinaryDisect( 40 psVectorBinaryDisectResult *status, 33 41 const psVector *bins, ///< Array of non-decreasing values 34 42 const psScalar *x ///< Target value to find -
trunk/psLib/src/math/psSpline.c
r10999 r12434 6 6 * This file contains the routines that allocate, free, and evaluate splines. 7 7 * 8 * @version $Revision: 1.15 7$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 1-09 22:38:53$8 * @version $Revision: 1.158 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-03-14 02:36:28 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 386 386 tmpScalar.type.type = PS_TYPE_F32; 387 387 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) { 390 391 psError(PS_ERR_UNKNOWN, false, "Could not perform bin dissection on spline->knots.\n"); 391 392 return(NAN);
Note:
See TracChangeset
for help on using the changeset viewer.
