Changeset 6186 for trunk/psLib/src/math/psPolynomial.c
- Timestamp:
- Jan 23, 2006, 12:25:31 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psPolynomial.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psPolynomial.c
r6101 r6186 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.13 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-01-2 1 02:43:31 $9 * @version $Revision: 1.136 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-01-23 22:25:31 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 14 14 * XXX: Should the "coeffErr[]" be used as well? Bug ???. Ignore coeffErr 15 15 * 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 16 */ 19 17 /*****************************************************************************/ … … 154 152 155 153 /***************************************************************************** 156 createChebyshevPolys(n): this routine takes as input the required order n,154 p_psCreateChebyshevPolys(n): this routine takes as input the required order n, 157 155 and returns as output as a pointer to an array of n psPolynomial1D 158 156 structures, corresponding to the first n Chebyshev polynomials. … … 162 160 outer coefficients of the Chebyshev polynomials. 163 161 164 XXX: From the poly nOrder/nTerm changem the maxChebyPoly here is still nTerms,165 not nOrder.166 162 *****************************************************************************/ 167 psPolynomial1D ** createChebyshevPolys(psS32 numPolys)163 psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys) 168 164 { 169 165 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL); … … 202 198 } 203 199 204 /*205 static psPolynomial1D **createChebyshevPolysOld(psS32 maxChebyPoly)206 {207 PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);208 209 psPolynomial1D **chebPolys = NULL;210 211 chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));212 for (psS32 i = 0; i < maxChebyPoly; i++) {213 chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);214 }215 216 // Create the Chebyshev polynomials.217 // Polynomial i has i-th order.218 chebPolys[0]->coeff[0] = 1;219 220 // XXX: Bug 296221 if (maxChebyPoly > 1) {222 chebPolys[1]->coeff[1] = 1;223 224 for (psS32 i = 2; i < maxChebyPoly; i++) {225 for (psS32 j = 0; j < chebPolys[i - 1]->nX; j++) {226 chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];227 }228 for (psS32 j = 0; j < chebPolys[i - 2]->nX; j++) {229 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];230 }231 }232 } else {233 // XXX: Code this.234 printf("WARNING: %u-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);235 }236 237 return (chebPolys);238 }239 */240 200 241 201 /***************************************************************************** 242 202 Polynomial coefficients will be accessed in [w][x][y][z] fashion. 243 203 *****************************************************************************/ 244 static psF64 ordPolynomial1DEval(psF64 x, 245 const psPolynomial1D* poly) 204 static psF64 ordPolynomial1DEval( 205 psF64 x, 206 const psPolynomial1D* poly) 246 207 { 247 208 unsigned int loop_x = 0; … … 249 210 psF64 xSum = 1.0; 250 211 251 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 252 "---- Calling ordPolynomial1DEval(%lf)\n", x); 253 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 254 "Polynomial order is %u\n", poly->nX); 212 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 213 psTrace(__func__, 4, "Polynomial order is %u\n", poly->nX); 255 214 for (loop_x = 0; loop_x < poly->nX+1; loop_x++) { 256 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 257 "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]); 215 psTrace(__func__, 4, "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]); 258 216 } 259 217 … … 262 220 // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to 263 221 // 2 or higher in the test code, you get seg faults. 264 psTrace( ".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 8,222 psTrace(__func__, 8, 265 223 "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]); 266 224 polySum += xSum * poly->coeff[loop_x]; … … 269 227 } 270 228 229 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 271 230 return(polySum); 272 231 } … … 284 243 psVector *d; 285 244 286 // XXX: n should be nTerms here (for clarity). Or get rid of the variable.287 245 unsigned int nTerms = 1 + poly->nX; 288 246 unsigned int i; … … 338 296 } else { 339 297 // This is old code that does not use Clenshaw's formula. Get rid of it. 340 psPolynomial1D **chebPolys = createChebyshevPolys(1 + poly->nX);298 psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX); 341 299 342 300 tmp = 0.0; … … 402 360 maxChebyPoly = poly->nY; 403 361 } 404 chebPolys = createChebyshevPolys(maxChebyPoly + 1);362 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1); 405 363 406 364 for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) { … … 476 434 maxChebyPoly = poly->nZ; 477 435 } 478 chebPolys = createChebyshevPolys(maxChebyPoly + 1);436 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1); 479 437 480 438 for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) { … … 567 525 maxChebyPoly = poly->nT; 568 526 } 569 // XXX: Add 1 since createChebyshevPolys() takes nTerms, not nOrder.570 chebPolys = createChebyshevPolys(maxChebyPoly + 1);527 // Add 1 since p_psCreateChebyshevPolys() takes nTerms, not nOrder. 528 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1); 571 529 572 530 for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) { … … 648 606 /***************************************************************************** 649 607 This routine must allocate memory for the polynomial structures. 650 XXX: replaces nterms variables with nOrder. Lots of potential for bugs651 here. Probably should create separately named private variables652 in these functions.653 608 *****************************************************************************/ 654 psPolynomial1D* psPolynomial1DAlloc(unsigned int n, 655 psPolynomialType type) 609 psPolynomial1D* psPolynomial1DAlloc( 610 unsigned int n, 611 psPolynomialType type) 656 612 { 657 613 PS_ASSERT_INT_NONNEGATIVE(n, NULL); 658 659 unsigned int i = 0; 660 psPolynomial1D* newPoly = NULL; 661 662 newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D)); 614 psU32 nOrder = n; 615 psPolynomial1D *newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D)); 663 616 psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree); 664 617 665 618 newPoly->type = type; 666 newPoly->nX = n ;619 newPoly->nX = nOrder; 667 620 newPoly->p_min = NAN; 668 621 newPoly->p_max = NAN; 669 newPoly->coeff = psAlloc((n + 1) * sizeof(psF64));670 newPoly->coeffErr = psAlloc((n + 1) * sizeof(psF64));671 newPoly->mask = (psMaskType *)psAlloc((n + 1) * sizeof(psMaskType));672 for ( i = 0; i < (n+ 1); i++) {622 newPoly->coeff = psAlloc((nOrder + 1) * sizeof(psF64)); 623 newPoly->coeffErr = psAlloc((nOrder + 1) * sizeof(psF64)); 624 newPoly->mask = (psMaskType *)psAlloc((nOrder + 1) * sizeof(psMaskType)); 625 for (psU32 i = 0; i < (nOrder + 1); i++) { 673 626 newPoly->coeff[i] = 0.0; 674 627 newPoly->coeffErr[i] = 0.0; … … 967 920 // XXX: The output of this routine is always psF64 while 1D and 2D are 968 921 // dependent on the input vectors. 969 psVector *psPolynomial3DEvalVector( const psPolynomial3D *poly,970 const psVector *x,971 const psVector *y,972 const psVector *z)973 922 psVector *psPolynomial3DEvalVector( 923 const psPolynomial3D *poly, 924 const psVector *x, 925 const psVector *y, 926 const psVector *z) 974 927 { 975 928 PS_ASSERT_POLY_NON_NULL(poly, NULL); … … 1036 989 } 1037 990 1038 psF64 psPolynomial4DEval(const psPolynomial4D* poly, 1039 psF64 x, 1040 psF64 y, 1041 psF64 z, 1042 psF64 t) 991 psF64 psPolynomial4DEval( 992 const psPolynomial4D* poly, 993 psF64 x, 994 psF64 y, 995 psF64 z, 996 psF64 t) 1043 997 { 1044 998 PS_ASSERT_POLY_NON_NULL(poly, NAN); … … 1056 1010 } 1057 1011 1058 psVector *psPolynomial4DEvalVector(const psPolynomial4D *poly, 1059 const psVector *x, 1060 const psVector *y, 1061 const psVector *z, 1062 const psVector *t) 1012 psVector *psPolynomial4DEvalVector( 1013 const psPolynomial4D *poly, 1014 const psVector *x, 1015 const psVector *y, 1016 const psVector *z, 1017 const psVector *t) 1063 1018 { 1064 1019 PS_ASSERT_POLY_NON_NULL(poly, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.
