Changeset 1982
- Timestamp:
- Oct 6, 2004, 11:30:53 AM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 11 edited
-
src/collections/psVector.h (modified) (2 diffs)
-
src/dataManip/psFunctions.c (modified) (2 diffs)
-
src/dataManip/psMinimize.c (modified) (9 diffs)
-
src/dataManip/psMinimize.h (modified) (1 diff)
-
src/math/psMinimize.c (modified) (9 diffs)
-
src/math/psMinimize.h (modified) (1 diff)
-
src/math/psPolynomial.c (modified) (2 diffs)
-
src/math/psSpline.c (modified) (2 diffs)
-
src/mathtypes/psVector.h (modified) (2 diffs)
-
test/dataManip/tst_psFunc04.c (modified) (2 diffs)
-
test/dataManip/tst_psFunc07.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psVector.h
r1953 r1982 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 3$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-10-0 5 01:43:57$13 * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-06 21:30:52 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 59 59 60 60 /*****************************************************************************/ 61 61 62 62 63 /** Allocate a vector. -
trunk/psLib/src/dataManip/psFunctions.c
r1968 r1982 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1. 49$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-06 00:48:15$9 * @version $Revision: 1.50 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-06 21:30:53 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 2074 2074 n = spline->n; 2075 2075 binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x); 2076 if (binNum == -1) {2076 if (binNum < 0) { 2077 2077 psLogMsg(__func__, PS_LOG_WARN, 2078 2078 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).", -
trunk/psLib/src/dataManip/psMinimize.c
r1964 r1982 7 7 * fit a 1-D polynomial to a set of data points. 8 8 * 9 * @author G eorge Gusciora, MHPCC9 * @author GLF, MHPCC 10 10 * 11 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-0 5 23:14:15$11 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-06 21:30:53 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 227 227 supplied, but does not equal the domains specified in mySpline? 228 228 XXX: can psSpline be NULL? 229 230 XXX: reimplement this assuming that mySpline is NULL? 231 232 XXX: What happens if X is NULL, then an index vector is generated for X, but 233 that index vector lies outside the range vectors in mySpline? 229 234 *****************************************************************************/ 230 235 psSpline1D *psVectorFitSpline1D(psSpline1D *mySpline, ///< The spline which will be generated. … … 269 274 CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static); 270 275 } 271 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x , y);272 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr , y);273 274 if (y ->n != (1 + mySpline->n)) {276 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x32, y32); 277 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr32, y32); 278 279 if (y32->n != (1 + mySpline->n)) { 275 280 psError(__func__, "data size / spline size mismatch (%d %d)\n", 276 y ->n, mySpline->n);281 y32->n, mySpline->n); 277 282 return(NULL); 278 283 } … … 282 287 if (2 == (mySpline->spline[0])->n) { 283 288 for (i=0;i<mySpline->n;i++) { 284 slope = (y ->data.F32[i+1] - y->data.F32[i]) /289 slope = (y32->data.F32[i+1] - y32->data.F32[i]) / 285 290 (mySpline->domains[i+1] - mySpline->domains[i]); 286 (mySpline->spline[i])->coeff[0] = y ->data.F32[i] -291 (mySpline->spline[i])->coeff[0] = y32->data.F32[i] - 287 292 (slope * mySpline->domains[i]); 288 293 … … 307 312 // If we get here, then we know these are cubic splines. We first 308 313 // generate the second derivatives at each data point. 309 mySpline->p_psDeriv2 = CalculateSecondDerivs(x , y);310 for (i=0;i<y ->n;i++)314 mySpline->p_psDeriv2 = CalculateSecondDerivs(x32, y32); 315 for (i=0;i<y32->n;i++) 311 316 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 312 317 "Second deriv[%d] is %f\n", i, mySpline->p_psDeriv2[i]); … … 316 321 // and Numerical Recipes in C. 317 322 for (i=0;i<numSplines;i++) { 318 H = x ->data.F32[i+1] - x->data.F32[i];323 H = x32->data.F32[i+1] - x32->data.F32[i]; 319 324 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 320 325 "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H); … … 323 328 // 324 329 // From (1) 325 (mySpline->spline[i])->coeff[0] = (y ->data.F32[i] * x->data.F32[i+1]/H);330 (mySpline->spline[i])->coeff[0] = (y32->data.F32[i] * x32->data.F32[i+1]/H); 326 331 // From (2) 327 ((mySpline->spline[i])->coeff[0])-= ((y ->data.F32[i+1] * x->data.F32[i])/H);332 ((mySpline->spline[i])->coeff[0])-= ((y32->data.F32[i+1] * x32->data.F32[i])/H); 328 333 // From (3) 329 tmp = (x ->data.F32[i+1] * x->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);330 tmp-= (x ->data.F32[i+1] / H);334 tmp = (x32->data.F32[i+1] * x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 335 tmp-= (x32->data.F32[i+1] / H); 331 336 tmp*= (mySpline->p_psDeriv2)[i] * H * H / 6.0; 332 337 ((mySpline->spline[i])->coeff[0])+= tmp; 333 338 // From (4) 334 tmp = -(x ->data.F32[i] * x->data.F32[i] * x->data.F32[i]) / (H * H * H);335 tmp+= (x ->data.F32[i] / H);339 tmp = -(x32->data.F32[i] * x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 340 tmp+= (x32->data.F32[i] / H); 336 341 tmp*= (mySpline->p_psDeriv2)[i+1] * H * H / 6.0; 337 342 ((mySpline->spline[i])->coeff[0])+= tmp; … … 341 346 // 342 347 // From (1) 343 (mySpline->spline[i])->coeff[1] = -(y ->data.F32[i]) / H;348 (mySpline->spline[i])->coeff[1] = -(y32->data.F32[i]) / H; 344 349 // From (2) 345 ((mySpline->spline[i])->coeff[1])+= (y ->data.F32[i+1] / H);350 ((mySpline->spline[i])->coeff[1])+= (y32->data.F32[i+1] / H); 346 351 // From (3) 347 tmp = -3.0 * (x ->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);352 tmp = -3.0 * (x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 348 353 tmp+= (1.0 / H); 349 354 tmp*= ((mySpline->p_psDeriv2)[i]) * H * H / 6.0; 350 355 ((mySpline->spline[i])->coeff[1])+= tmp; 351 356 // From (4) 352 tmp = 3.0 * (x ->data.F32[i] * x->data.F32[i]) / (H * H * H);357 tmp = 3.0 * (x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 353 358 tmp-= (1.0 / H); 354 359 tmp*= ((mySpline->p_psDeriv2)[i+1]) * H * H / 6.0; … … 359 364 // 360 365 // From (3) 361 (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x ->data.F32[i+1] / (6.0 * H);366 (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x32->data.F32[i+1] / (6.0 * H); 362 367 // From (4) 363 ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x ->data.F32[i] / (6.0 * H));368 ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x32->data.F32[i] / (6.0 * H)); 364 369 365 370 // -
trunk/psLib/src/dataManip/psMinimize.h
r1963 r1982 6 6 * chi-squared minimization, and 1-D polynomial fitting routines. 7 7 * 8 * @author G eorge Gusciora, MHPCC8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.2 7$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-10-0 5 22:47:21$10 * @version $Revision: 1.28 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-10-06 21:30:53 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/math/psMinimize.c
r1964 r1982 7 7 * fit a 1-D polynomial to a set of data points. 8 8 * 9 * @author G eorge Gusciora, MHPCC9 * @author GLF, MHPCC 10 10 * 11 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-0 5 23:14:15$11 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-06 21:30:53 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 227 227 supplied, but does not equal the domains specified in mySpline? 228 228 XXX: can psSpline be NULL? 229 230 XXX: reimplement this assuming that mySpline is NULL? 231 232 XXX: What happens if X is NULL, then an index vector is generated for X, but 233 that index vector lies outside the range vectors in mySpline? 229 234 *****************************************************************************/ 230 235 psSpline1D *psVectorFitSpline1D(psSpline1D *mySpline, ///< The spline which will be generated. … … 269 274 CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static); 270 275 } 271 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x , y);272 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr , y);273 274 if (y ->n != (1 + mySpline->n)) {276 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x32, y32); 277 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr32, y32); 278 279 if (y32->n != (1 + mySpline->n)) { 275 280 psError(__func__, "data size / spline size mismatch (%d %d)\n", 276 y ->n, mySpline->n);281 y32->n, mySpline->n); 277 282 return(NULL); 278 283 } … … 282 287 if (2 == (mySpline->spline[0])->n) { 283 288 for (i=0;i<mySpline->n;i++) { 284 slope = (y ->data.F32[i+1] - y->data.F32[i]) /289 slope = (y32->data.F32[i+1] - y32->data.F32[i]) / 285 290 (mySpline->domains[i+1] - mySpline->domains[i]); 286 (mySpline->spline[i])->coeff[0] = y ->data.F32[i] -291 (mySpline->spline[i])->coeff[0] = y32->data.F32[i] - 287 292 (slope * mySpline->domains[i]); 288 293 … … 307 312 // If we get here, then we know these are cubic splines. We first 308 313 // generate the second derivatives at each data point. 309 mySpline->p_psDeriv2 = CalculateSecondDerivs(x , y);310 for (i=0;i<y ->n;i++)314 mySpline->p_psDeriv2 = CalculateSecondDerivs(x32, y32); 315 for (i=0;i<y32->n;i++) 311 316 psTrace(".psLib.dataManip.psVectorFitSpline1D", 6, 312 317 "Second deriv[%d] is %f\n", i, mySpline->p_psDeriv2[i]); … … 316 321 // and Numerical Recipes in C. 317 322 for (i=0;i<numSplines;i++) { 318 H = x ->data.F32[i+1] - x->data.F32[i];323 H = x32->data.F32[i+1] - x32->data.F32[i]; 319 324 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 320 325 "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H); … … 323 328 // 324 329 // From (1) 325 (mySpline->spline[i])->coeff[0] = (y ->data.F32[i] * x->data.F32[i+1]/H);330 (mySpline->spline[i])->coeff[0] = (y32->data.F32[i] * x32->data.F32[i+1]/H); 326 331 // From (2) 327 ((mySpline->spline[i])->coeff[0])-= ((y ->data.F32[i+1] * x->data.F32[i])/H);332 ((mySpline->spline[i])->coeff[0])-= ((y32->data.F32[i+1] * x32->data.F32[i])/H); 328 333 // From (3) 329 tmp = (x ->data.F32[i+1] * x->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);330 tmp-= (x ->data.F32[i+1] / H);334 tmp = (x32->data.F32[i+1] * x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 335 tmp-= (x32->data.F32[i+1] / H); 331 336 tmp*= (mySpline->p_psDeriv2)[i] * H * H / 6.0; 332 337 ((mySpline->spline[i])->coeff[0])+= tmp; 333 338 // From (4) 334 tmp = -(x ->data.F32[i] * x->data.F32[i] * x->data.F32[i]) / (H * H * H);335 tmp+= (x ->data.F32[i] / H);339 tmp = -(x32->data.F32[i] * x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 340 tmp+= (x32->data.F32[i] / H); 336 341 tmp*= (mySpline->p_psDeriv2)[i+1] * H * H / 6.0; 337 342 ((mySpline->spline[i])->coeff[0])+= tmp; … … 341 346 // 342 347 // From (1) 343 (mySpline->spline[i])->coeff[1] = -(y ->data.F32[i]) / H;348 (mySpline->spline[i])->coeff[1] = -(y32->data.F32[i]) / H; 344 349 // From (2) 345 ((mySpline->spline[i])->coeff[1])+= (y ->data.F32[i+1] / H);350 ((mySpline->spline[i])->coeff[1])+= (y32->data.F32[i+1] / H); 346 351 // From (3) 347 tmp = -3.0 * (x ->data.F32[i+1] * x->data.F32[i+1]) / (H * H * H);352 tmp = -3.0 * (x32->data.F32[i+1] * x32->data.F32[i+1]) / (H * H * H); 348 353 tmp+= (1.0 / H); 349 354 tmp*= ((mySpline->p_psDeriv2)[i]) * H * H / 6.0; 350 355 ((mySpline->spline[i])->coeff[1])+= tmp; 351 356 // From (4) 352 tmp = 3.0 * (x ->data.F32[i] * x->data.F32[i]) / (H * H * H);357 tmp = 3.0 * (x32->data.F32[i] * x32->data.F32[i]) / (H * H * H); 353 358 tmp-= (1.0 / H); 354 359 tmp*= ((mySpline->p_psDeriv2)[i+1]) * H * H / 6.0; … … 359 364 // 360 365 // From (3) 361 (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x ->data.F32[i+1] / (6.0 * H);366 (mySpline->spline[i])->coeff[2] = ((mySpline->p_psDeriv2)[i]) * 3.0 * x32->data.F32[i+1] / (6.0 * H); 362 367 // From (4) 363 ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x ->data.F32[i] / (6.0 * H));368 ((mySpline->spline[i])->coeff[2])-= (((mySpline->p_psDeriv2)[i+1]) * 3.0 * x32->data.F32[i] / (6.0 * H)); 364 369 365 370 // -
trunk/psLib/src/math/psMinimize.h
r1963 r1982 6 6 * chi-squared minimization, and 1-D polynomial fitting routines. 7 7 * 8 * @author G eorge Gusciora, MHPCC8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.2 7$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-10-0 5 22:47:21$10 * @version $Revision: 1.28 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-10-06 21:30:53 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/math/psPolynomial.c
r1968 r1982 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1. 49$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-06 00:48:15$9 * @version $Revision: 1.50 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-06 21:30:53 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 2074 2074 n = spline->n; 2075 2075 binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x); 2076 if (binNum == -1) {2076 if (binNum < 0) { 2077 2077 psLogMsg(__func__, PS_LOG_WARN, 2078 2078 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).", -
trunk/psLib/src/math/psSpline.c
r1968 r1982 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1. 49$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-06 00:48:15$9 * @version $Revision: 1.50 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-06 21:30:53 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 2074 2074 n = spline->n; 2075 2075 binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x); 2076 if (binNum == -1) {2076 if (binNum < 0) { 2077 2077 psLogMsg(__func__, PS_LOG_WARN, 2078 2078 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).", -
trunk/psLib/src/mathtypes/psVector.h
r1953 r1982 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 3$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-10-0 5 01:43:57$13 * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-06 21:30:52 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 59 59 60 60 /*****************************************************************************/ 61 61 62 62 63 /** Allocate a vector. -
trunk/psLib/test/dataManip/tst_psFunc04.c
r1946 r1982 17 17 #define N 8 18 18 19 int main()19 int t00() 20 20 { 21 21 int testStatus = true; … … 68 68 return (!testStatus); 69 69 } 70 71 int t01() 72 { 73 int testStatus = true; 74 int memLeaks=0; 75 int i; 76 float x; 77 float y; 78 int currentId = psMemGetId(); 79 psSpline1D *tmpSpline; 80 psVector *data; 81 82 psTraceSetLevel(".", 0); 83 84 /****************************************************************************/ 85 /****************************************************************************/ 86 testStatus = true; 87 printPositiveTestHeader(stdout, 88 "psFunction functions", 89 "psSpline1DAlloc()"); 90 data = psVectorAlloc(N+1, PS_TYPE_F32); 91 tmpSpline = psSpline1DAlloc(N, 1, 1.0, 10.0); 92 93 for (i=0;i<N+1;i++) { 94 data->data.F32[i] = tmpSpline->domains[i]; 95 } 96 psVectorFitSpline1D(tmpSpline, data, data, NULL); 97 98 for (i=0;i<N+1;i++) { 99 x = 0.5 + (float) i+1; 100 y = psSpline1DEval(tmpSpline, x); 101 if (fabs(x-y) > FLT_EPSILON) { 102 printf("ERROR: f(%f) is %f\n", x, y); 103 testStatus = true; 104 } 105 } 106 107 p_psSpline1DFree(tmpSpline); 108 psMemCheckCorruption(1); 109 psFree(data); 110 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 111 if (0 != memLeaks) { 112 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 113 } 114 115 printFooter(stdout, 116 "psFunctions functions", 117 "psSpline1DAlloc()", 118 testStatus); 119 120 return (!testStatus); 121 } 122 123 int main() 124 { 125 t00(); 126 // t01(); 127 } -
trunk/psLib/test/dataManip/tst_psFunc07.c
r1946 r1982 12 12 #include "psFunctions.h" 13 13 14 #define NUM_SPLINES 5 14 #define NUM_SPLINES 50 15 15 #define A 4.0 16 16 #define B -3.0 … … 20 20 #define MAX 30 21 21 #define ERROR_TOLERANCE 0.10 22 #define OFFSET (NUM_SPLINES * ERROR_TOLERANCE) 22 23 23 24 float myFunc(float x) … … 26 27 } 27 28 28 int main()29 int t00() 29 30 { 30 31 int testStatus = true; … … 37 38 psVector *y = NULL; 38 39 psVector *newY = NULL; 39 float NRX[NUM_SPLINES+2];40 float NRY[NUM_SPLINES+2];41 // float tmpY;42 // float derivs[NUM_SPLINES+2];43 40 44 41 psTraceSetLevel(".", 0); … … 46 43 /****************************************************************************/ 47 44 testStatus = true; 48 printPositiveTestHeader(stdout,49 "psFunction functions",50 "psSpline1DAlloc()");51 45 x = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 52 46 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); … … 55 49 56 50 for (i=0;i<NUM_SPLINES+1;i++) { 57 NRX[i+1] = x->data.F32[i] = tmpSpline->domains[i]; 58 NRY[i+1] = y->data.F32[i] = myFunc(x->data.F32[i]); 59 // printf("DATA: (x, y) is (%f, %f)\n", x->data.F32[i], y->data.F32[i]); 51 x->data.F32[i] = tmpSpline->domains[i]; 52 y->data.F32[i] = myFunc(x->data.F32[i]); 60 53 } 54 61 55 for (i=0;i<NUM_SPLINES;i++) { 62 56 newX->data.F32[i]= ((x->data.F32[i] + x->data.F32[i+1])/2.0); … … 66 60 /* psLib Code */ 67 61 /****************************************************************************/ 62 printPositiveTestHeader(stdout, 63 "psFunction functions", 64 "psSpline1DAlloc()"); 68 65 69 66 psVectorFitSpline1D(tmpSpline, x, y, NULL); 70 67 newY = psSpline1DEvalVector(newX, tmpSpline); 71 68 72 for (i= 0;i<NUM_SPLINES+1;i++) {69 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 73 70 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) { 74 71 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 75 72 newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i])); 76 73 } 77 // tmpY = p_psNRSpline1DEval(tmpSpline, x, y, newX->data.F32[i]);78 // printf("HMMM: p_psNRSpline1DEval(%f) is %f. Should be %f\n",79 // newX->data.F32[i], tmpY, myFunc(newX->data.F32[i]));80 74 } 81 75 … … 99 93 return (!testStatus); 100 94 } 95 96 int t00() 97 { 98 int testStatus = true; 99 int memLeaks=0; 100 int currentId = psMemGetId(); 101 int i; 102 psSpline1D *tmpSpline = NULL; 103 psVector *x = NULL; 104 psVector *newX = NULL; 105 psVector *y = NULL; 106 psVector *newY = NULL; 107 108 psTraceSetLevel(".", 0); 109 /****************************************************************************/ 110 /****************************************************************************/ 111 testStatus = true; 112 x = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 113 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 114 y = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 115 tmpSpline = psSpline1DAlloc(NUM_SPLINES, 3, MIN, MAX); 116 117 for (i=0;i<NUM_SPLINES+1;i++) { 118 x->data.F32[i] = tmpSpline->domains[i]; 119 y->data.F32[i] = myFunc(x->data.F32[i]); 120 } 121 122 for (i=0;i<NUM_SPLINES;i++) { 123 newX->data.F32[i]= ((x->data.F32[i] + x->data.F32[i+1])/2.0); 124 } 125 newX->data.F32[NUM_SPLINES] = x->data.F32[NUM_SPLINES]; 126 /****************************************************************************/ 127 /* psLib Code */ 128 /****************************************************************************/ 129 printPositiveTestHeader(stdout, 130 "psFunction functions", 131 "psSpline1DAlloc()"); 132 133 psVectorFitSpline1D(tmpSpline, x, y, NULL); 134 newY = psSpline1DEvalVector(newX, tmpSpline); 135 136 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 137 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) { 138 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 139 newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i])); 140 } 141 } 142 143 psFree(x); 144 psFree(newX); 145 psFree(y); 146 p_psSpline1DFree(tmpSpline); 147 psFree(newY); 148 149 psMemCheckCorruption(1); 150 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 151 if (0 != memLeaks) { 152 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 153 } 154 155 printFooter(stdout, 156 "psFunctions functions", 157 "psSpline1DAlloc()", 158 testStatus); 159 160 return (!testStatus); 161 } 162 163 int main() 164 { 165 t00(); 166 }
Note:
See TracChangeset
for help on using the changeset viewer.
