Changeset 6437 for trunk/psLib/src/math/psPolynomial.c
- Timestamp:
- Feb 16, 2006, 2:56:48 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psPolynomial.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psPolynomial.c
r6348 r6437 4 4 * routines. 5 5 * 6 * This file will hold the functions for allocated, freeing, and evaluating6 * This file will hold the routiness for allocating, freeing, and evaluating 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.14 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-02- 07 23:36:15$9 * @version $Revision: 1.143 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-02-17 00:56:48 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 159 159 used frequently and the data structure created here does not contain the 160 160 outer coefficients of the Chebyshev polynomials. 161 162 161 *****************************************************************************/ 163 162 psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys) … … 165 164 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL); 166 165 167 if (0) { 168 psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *)); 169 for (psS32 i = 0; i < numPolys; i++) { 170 chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i); 171 chebPolys[i]->coeff[i] = 1; 172 } 173 return (chebPolys); 174 } else { 175 psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *)); 176 for (psS32 i = 0; i < numPolys; i++) { 177 chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i); 178 } 179 180 // Create the Chebyshev polynomials. 181 // Polynomial i has i-th order. 182 chebPolys[0]->coeff[0] = 1.0; 183 if (numPolys >= 2) { 184 chebPolys[1]->coeff[1] = 1.0; 185 186 for (psS32 i = 2; i < numPolys; i++) { 187 for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) { 188 chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j]; 189 } 190 for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) { 191 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j]; 192 } 193 } 194 } 195 196 if (psTraceGetLevel(__func__) >= 6) { 197 for (psS32 j = 0; j < numPolys; j++) { 198 PS_POLY_PRINT_1D(chebPolys[j]); 199 } 200 } 201 return (chebPolys); 202 } 166 psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *)); 167 for (psS32 i = 0; i < numPolys; i++) { 168 chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i); 169 } 170 171 // Create the Chebyshev polynomials. 172 // Polynomial i has i-th order. 173 chebPolys[0]->coeff[0] = 1.0; 174 if (numPolys >= 2) { 175 chebPolys[1]->coeff[1] = 1.0; 176 177 for (psS32 i = 2; i < numPolys; i++) { 178 for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) { 179 chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j]; 180 } 181 for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) { 182 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j]; 183 } 184 } 185 } 186 187 if (psTraceGetLevel(__func__) >= 6) { 188 for (psS32 j = 0; j < numPolys; j++) { 189 PS_POLY_PRINT_1D(chebPolys[j]); 190 } 191 } 192 return (chebPolys); 203 193 } 204 194 … … 223 213 for (loop_x = 0; loop_x < poly->nX+1; loop_x++) { 224 214 if (poly->mask[loop_x] == 0) { 225 // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to226 // 2 or higher in the test code, you get seg faults.227 215 psTrace(__func__, 8, 228 216 "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]); … … 238 226 // XXX: You can do this without having to psAlloc() vector d. 239 227 // XXX: How does the mask vector effect Crenshaw's formula? 240 // XXX: We assume that x is scaled between -1.0 and 1.0;228 // NOTE: We assume that x is scaled between -1.0 and 1.0; 241 229 // XXX: Create a faster version for low-order Chebyshevs. 242 230 static psF64 chebPolynomial1DEval( … … 298 286 psFree(d); 299 287 } else { 300 // This is old code that does not use Clenshaw's formula. Get rid of it.288 // XXX: This is old code that does not use Clenshaw's formula. Get rid of it. 301 289 psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX); 302 290
Note:
See TracChangeset
for help on using the changeset viewer.
