Changeset 4580
- Timestamp:
- Jul 18, 2005, 4:55:54 PM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 3 edited
-
src/math/psFunctions.c (modified) (2 diffs)
-
src/math/psMinimize.c (modified) (3 diffs)
-
test/math/tst_psFunc07.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psFunctions.c
r4570 r4580 1 1 /** @file psFunctions.c 2 *3 * @brief Contains basic function allocation, deallocation, and evaluation4 * routines.5 *6 * This file will hold the functions for allocated, freeing, and evaluating7 * 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 Hawaii13 *14 * XXX: Should the "coeffErr[]" be used as well? Bug ???. Ignore coeffErr15 *16 * XXX: In the various polyAlloc(n) functions, n is really the order of the17 * 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 */ 19 19 /*****************************************************************************/ 20 20 /* INCLUDE FILES */ … … 1918 1918 for (psS32 i=0;i<bounds->n-1;i++) { 1919 1919 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]); 1921 1921 return(NULL); 1922 1922 } -
trunk/psLib/src/math/psMinimize.c
r4570 r4580 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.12 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-07-1 6 00:42:28$11 * @version $Revision: 1.127 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-07-19 02:55:54 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 520 520 psVector *y32 = yPtr; 521 521 522 523 522 // If these are linear splines, which means their polynomials will have 524 523 // two coefficients, then we do the simple calculation. … … 638 637 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 639 638 "---- psVectorFitSpline1D() end ----\n"); 639 640 640 return(mySpline); 641 641 } -
trunk/psLib/test/math/tst_psFunc07.c
r4547 r4580 9 9 XXX: The spline eval functions are F32 only, while the spline fit functions 10 10 are F32 and F64. 11 12 XXX: Must call the spline fit functions with unallowable input parameters. 11 13 *****************************************************************************/ 12 14 #include <stdio.h> … … 17 19 #include "psFunctions.h" 18 20 21 #define VERBOSE 0 19 22 #define NUM_SPLINES 50 20 23 #define A 4.0 … … 51 54 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 52 55 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; 54 64 55 65 for (i=0;i<NUM_SPLINES+1;i++) { 56 x->data.F32[i] = tmpSpline->knots->data.F32[i];57 66 y->data.F32[i] = myFunc(x->data.F32[i]); 58 67 } … … 69 78 "psSpline1DAlloc(), psVectorFitSpline1D, psSpline1DEvalVector: F32 versions"); 70 79 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 } 82 98 } 83 } 84 99 psFree(tmpSpline); 100 psFree(newY); 101 } 85 102 psFree(x); 103 psFree(y); 86 104 psFree(newX); 87 psFree(y);88 psFree(tmpSpline);89 psFree(newY);90 105 91 106 psMemCheckCorruption(1); … … 123 138 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F64); 124 139 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; 126 147 127 148 for (i=0;i<NUM_SPLINES+1;i++) { 128 x->data.F64[i] = tmpSpline->knots->data.F32[i];129 149 y->data.F64[i] = myFunc(x->data.F64[i]); 130 150 } … … 141 161 "psSpline1DAlloc(), psVectorFitSpline1D, psSpline1DEvalVector: F64 versions"); 142 162 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 } 154 181 } 155 } 156 182 psFree(tmpSpline); 183 psFree(newY); 184 } 157 185 psFree(x); 158 186 psFree(newX); 159 187 psFree(y); 160 psFree(tmpSpline);161 psFree(newY);162 188 163 189 psMemCheckCorruption(1); … … 177 203 psS32 main() 178 204 { 179 // t00(); 205 psLogSetFormat("HLNM"); 206 t00(); 180 207 t01(); 181 208 }
Note:
See TracChangeset
for help on using the changeset viewer.
