Changeset 5066 for trunk/psLib/src/math/psPolynomial.c
- Timestamp:
- Sep 19, 2005, 9:53:13 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psPolynomial.c (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psPolynomial.c
r4991 r5066 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.12 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-09-1 1 22:18:40$9 * @version $Revision: 1.121 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-09-19 19:53:13 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 162 162 outer coefficients of the Chebyshev polynomials. 163 163 *****************************************************************************/ 164 static psPolynomial1D **createChebyshevPolys( psS32maxChebyPoly)164 static psPolynomial1D **createChebyshevPolys(unsigned int maxChebyPoly) 165 165 { 166 166 PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL); … … 169 169 170 170 chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *)); 171 for ( psS32i = 0; i < maxChebyPoly; i++) {171 for (unsigned int i = 0; i < maxChebyPoly; i++) { 172 172 chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD); 173 173 } … … 191 191 } else { 192 192 // XXX: Code this. 193 printf("WARNING: % d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);193 printf("WARNING: %u-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly); 194 194 } 195 195 … … 200 200 Polynomial coefficients will be accessed in [w][x][y][z] fashion. 201 201 *****************************************************************************/ 202 static psF64 ordPolynomial1DEval(psF64 x, const psPolynomial1D* poly) 203 { 204 psS32 loop_x = 0; 202 static psF64 ordPolynomial1DEval(psF64 x, 203 const psPolynomial1D* poly) 204 { 205 unsigned int loop_x = 0; 205 206 psF64 polySum = 0.0; 206 207 psF64 xSum = 1.0; … … 209 210 "---- Calling ordPolynomial1DEval(%lf)\n", x); 210 211 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 211 "Polynomial order is % d\n", poly->n);212 "Polynomial order is %u\n", poly->n); 212 213 for (loop_x = 0; loop_x < poly->n; loop_x++) { 213 214 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 214 "Polynomial coeff[% d] is %lf\n", loop_x, poly->coeff[loop_x]);215 "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]); 215 216 } 216 217 … … 230 231 // XXX: How does the mask vector effect Crenshaw's formula? 231 232 // XXX: We assume that x is scaled between -1.0 and 1.0; 232 static psF64 chebPolynomial1DEval(psF64 x, const psPolynomial1D* poly) 233 static psF64 chebPolynomial1DEval(psF64 x, 234 const psPolynomial1D* poly) 233 235 { 234 236 PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0); 235 237 // XXX: Create a macro for this in psConstants.h 236 238 if (poly->n < 1) { 237 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order % d.", poly->n);239 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %u.", poly->n); 238 240 return(NAN); 239 241 } 240 242 psVector *d; 241 psS32n = poly->n;242 psS32i;243 unsigned int n = poly->n; 244 unsigned int i; 243 245 psF64 tmp = 0.0; 244 246 … … 318 320 PS_ASSERT_POLY_NON_NULL(poly, NAN); 319 321 320 psS32loop_x = 0;321 psS32loop_y = 0;322 unsigned int loop_x = 0; 323 unsigned int loop_y = 0; 322 324 psF64 polySum = 0.0; 323 325 psF64 xSum = 1.0; … … 338 340 } 339 341 340 static psF64 chebPolynomial2DEval(psF64 x, psF64 y, const psPolynomial2D* poly) 342 static psF64 chebPolynomial2DEval(psF64 x, 343 psF64 y, 344 const psPolynomial2D* poly) 341 345 { 342 346 PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0); … … 344 348 PS_ASSERT_POLY_NON_NULL(poly, NAN); 345 349 346 psS32loop_x = 0;347 psS32loop_y = 0;348 psS32i = 0;350 unsigned int loop_x = 0; 351 unsigned int loop_y = 0; 352 unsigned int i = 0; 349 353 psF64 polySum = 0.0; 350 354 psPolynomial1D* *chebPolys = NULL; 351 psS32maxChebyPoly = 0;355 unsigned int maxChebyPoly = 0; 352 356 353 357 // Determine how many Chebyshev polynomials … … 375 379 } 376 380 377 static psF64 ordPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psPolynomial3D* poly) 378 { 379 psS32 loop_x = 0; 380 psS32 loop_y = 0; 381 psS32 loop_z = 0; 381 static psF64 ordPolynomial3DEval(psF64 x, 382 psF64 y, 383 psF64 z, 384 const psPolynomial3D* poly) 385 { 386 unsigned int loop_x = 0; 387 unsigned int loop_y = 0; 388 unsigned int loop_z = 0; 382 389 psF64 polySum = 0.0; 383 390 psF64 xSum = 1.0; … … 403 410 } 404 411 405 static psF64 chebPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psPolynomial3D* poly) 412 static psF64 chebPolynomial3DEval(psF64 x, 413 psF64 y, 414 psF64 z, 415 const psPolynomial3D* poly) 406 416 { 407 417 PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0); 408 418 PS_ASSERT_DOUBLE_WITHIN_RANGE(y, -1.0, 1.0, 0.0); 409 419 PS_ASSERT_DOUBLE_WITHIN_RANGE(z, -1.0, 1.0, 0.0); 410 psS32loop_x = 0;411 psS32loop_y = 0;412 psS32loop_z = 0;413 psS32i = 0;420 unsigned int loop_x = 0; 421 unsigned int loop_y = 0; 422 unsigned int loop_z = 0; 423 unsigned int i = 0; 414 424 psF64 polySum = 0.0; 415 425 psPolynomial1D* *chebPolys = NULL; 416 psS32maxChebyPoly = 0;426 unsigned int maxChebyPoly = 0; 417 427 418 428 // Determine how many Chebyshev polynomials … … 447 457 } 448 458 449 static psF64 ordPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psPolynomial4D* poly) 450 { 451 psS32 loop_x = 0; 452 psS32 loop_y = 0; 453 psS32 loop_z = 0; 454 psS32 loop_t = 0; 459 static psF64 ordPolynomial4DEval(psF64 x, 460 psF64 y, 461 psF64 z, 462 psF64 t, 463 const psPolynomial4D* poly) 464 { 465 unsigned int loop_x = 0; 466 unsigned int loop_y = 0; 467 unsigned int loop_z = 0; 468 unsigned int loop_t = 0; 455 469 psF64 polySum = 0.0; 456 470 psF64 xSum = 1.0; … … 481 495 } 482 496 483 static psF64 chebPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psPolynomial4D* poly) 497 static psF64 chebPolynomial4DEval(psF64 x, 498 psF64 y, 499 psF64 z, 500 psF64 t, 501 const psPolynomial4D* poly) 484 502 { 485 503 PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0); … … 487 505 PS_ASSERT_DOUBLE_WITHIN_RANGE(z, -1.0, 1.0, 0.0); 488 506 PS_ASSERT_DOUBLE_WITHIN_RANGE(t, -1.0, 1.0, 0.0); 489 psS32loop_x = 0;490 psS32loop_y = 0;491 psS32loop_z = 0;492 psS32loop_t = 0;493 psS32i = 0;507 unsigned int loop_x = 0; 508 unsigned int loop_y = 0; 509 unsigned int loop_z = 0; 510 unsigned int loop_t = 0; 511 unsigned int i = 0; 494 512 psF64 polySum = 0.0; 495 513 psPolynomial1D* *chebPolys = NULL; 496 psS32maxChebyPoly = 0;514 unsigned int maxChebyPoly = 0; 497 515 498 516 // Determine how many Chebyshev polynomials … … 542 560 evaluated Gaussian is: \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f] 543 561 *****************************************************************************/ 544 float psGaussian(float x, float mean, float sigma, bool normal) 562 float psGaussian(float x, 563 float mean, 564 float sigma, 565 bool normal) 545 566 { 546 567 psF32 tmp = 1.0; … … 568 589 *****************************************************************************/ 569 590 #define PS_XXX_GAUSSIAN_SEED 1995 570 psVector* p_psGaussianDev(psF32 mean, psF32 sigma, psS32 Npts) 591 psVector* p_psGaussianDev(psF32 mean, 592 psF32 sigma, 593 unsigned int Npts) 571 594 { 572 595 PS_ASSERT_INT_NONNEGATIVE(Npts, NULL); … … 575 598 psRandom *r = psRandomAlloc(PS_RANDOM_TAUS, PS_XXX_GAUSSIAN_SEED); 576 599 psVector* gauss = psVectorAlloc(Npts, PS_TYPE_F32); 577 for ( psS32i = 0; i < Npts; i++) {600 for (unsigned int i = 0; i < Npts; i++) { 578 601 gauss->data.F32[i] = mean + p_psRandomGaussian(r, sigma); 579 602 } … … 586 609 This routine must allocate memory for the polynomial structures. 587 610 *****************************************************************************/ 588 psPolynomial1D* psPolynomial1DAlloc( int n,611 psPolynomial1D* psPolynomial1DAlloc(unsigned int n, 589 612 psPolynomialType type) 590 613 { 591 614 PS_ASSERT_INT_POSITIVE(n, NULL); 592 615 593 int i = 0;616 unsigned int i = 0; 594 617 psPolynomial1D* newPoly = NULL; 595 618 … … 601 624 newPoly->coeff = psAlloc(n * sizeof(psF64)); 602 625 newPoly->coeffErr = psAlloc(n * sizeof(psF64)); 603 newPoly->mask = ( char *)psAlloc(n * sizeof(char));626 newPoly->mask = (psMaskType *)psAlloc(n * sizeof(psMaskType)); 604 627 for (i = 0; i < n; i++) { 605 628 newPoly->coeff[i] = 0.0; … … 611 634 } 612 635 613 psPolynomial2D* psPolynomial2DAlloc( int nX, int nY, 636 psPolynomial2D* psPolynomial2DAlloc( unsigned int nX, 637 unsigned int nY, 614 638 psPolynomialType type) 615 639 { … … 617 641 PS_ASSERT_INT_POSITIVE(nY, NULL); 618 642 619 int x = 0;620 int y = 0;643 unsigned int x = 0; 644 unsigned int y = 0; 621 645 psPolynomial2D* newPoly = NULL; 622 646 … … 630 654 newPoly->coeff = psAlloc(nX * sizeof(psF64 *)); 631 655 newPoly->coeffErr = psAlloc(nX * sizeof(psF64 *)); 632 newPoly->mask = ( char **)psAlloc(nX * sizeof(char*));656 newPoly->mask = (psMaskType **)psAlloc(nX * sizeof(psMaskType *)); 633 657 for (x = 0; x < nX; x++) { 634 658 newPoly->coeff[x] = psAlloc(nY * sizeof(psF64)); 635 659 newPoly->coeffErr[x] = psAlloc(nY * sizeof(psF64)); 636 newPoly->mask[x] = ( char *)psAlloc(nY * sizeof(char));660 newPoly->mask[x] = (psMaskType *)psAlloc(nY * sizeof(psMaskType)); 637 661 } 638 662 for (x = 0; x < nX; x++) { … … 647 671 } 648 672 649 psPolynomial3D* psPolynomial3DAlloc( int nX, int nY, int nZ, 673 psPolynomial3D* psPolynomial3DAlloc( unsigned int nX, 674 unsigned int nY, 675 unsigned int nZ, 650 676 psPolynomialType type) 651 677 { … … 654 680 PS_ASSERT_INT_POSITIVE(nZ, NULL); 655 681 656 psS32x = 0;657 psS32y = 0;658 psS32z = 0;682 unsigned int x = 0; 683 unsigned int y = 0; 684 unsigned int z = 0; 659 685 psPolynomial3D* newPoly = NULL; 660 686 … … 669 695 newPoly->coeff = psAlloc(nX * sizeof(psF64 **)); 670 696 newPoly->coeffErr = psAlloc(nX * sizeof(psF64 **)); 671 newPoly->mask = ( char ***)psAlloc(nX * sizeof(char**));697 newPoly->mask = (psMaskType ***)psAlloc(nX * sizeof(psMaskType **)); 672 698 for (x = 0; x < nX; x++) { 673 699 newPoly->coeff[x] = psAlloc(nY * sizeof(psF64 *)); 674 700 newPoly->coeffErr[x] = psAlloc(nY * sizeof(psF64 *)); 675 newPoly->mask[x] = ( char **)psAlloc(nY * sizeof(char*));701 newPoly->mask[x] = (psMaskType **)psAlloc(nY * sizeof(psMaskType *)); 676 702 for (y = 0; y < nY; y++) { 677 703 newPoly->coeff[x][y] = psAlloc(nZ * sizeof(psF64)); 678 704 newPoly->coeffErr[x][y] = psAlloc(nZ * sizeof(psF64)); 679 newPoly->mask[x][y] = ( char *)psAlloc(nZ * sizeof(char));705 newPoly->mask[x][y] = (psMaskType *)psAlloc(nZ * sizeof(psMaskType)); 680 706 } 681 707 } … … 693 719 } 694 720 695 psPolynomial4D* psPolynomial4DAlloc( int nX, int nY, int nZ, int nT, 721 psPolynomial4D* psPolynomial4DAlloc( unsigned int nX, 722 unsigned int nY, 723 unsigned int nZ, 724 unsigned int nT, 696 725 psPolynomialType type) 697 726 { … … 701 730 PS_ASSERT_INT_POSITIVE(nT, NULL); 702 731 703 psS32x = 0;704 psS32y = 0;705 psS32z = 0;706 psS32t = 0;732 unsigned int x = 0; 733 unsigned int y = 0; 734 unsigned int z = 0; 735 unsigned int t = 0; 707 736 psPolynomial4D* newPoly = NULL; 708 737 … … 718 747 newPoly->coeff = psAlloc(nX * sizeof(psF64 ***)); 719 748 newPoly->coeffErr = psAlloc(nX * sizeof(psF64 ***)); 720 newPoly->mask = ( char ****)psAlloc(nX * sizeof(char***));749 newPoly->mask = (psMaskType ****)psAlloc(nX * sizeof(psMaskType ***)); 721 750 for (x = 0; x < nX; x++) { 722 751 newPoly->coeff[x] = psAlloc(nY * sizeof(psF64 **)); 723 752 newPoly->coeffErr[x] = psAlloc(nY * sizeof(psF64 **)); 724 newPoly->mask[x] = ( char ***)psAlloc(nY * sizeof(char**));753 newPoly->mask[x] = (psMaskType ***)psAlloc(nY * sizeof(psMaskType **)); 725 754 for (y = 0; y < nY; y++) { 726 755 newPoly->coeff[x][y] = psAlloc(nZ * sizeof(psF64 *)); 727 756 newPoly->coeffErr[x][y] = psAlloc(nZ * sizeof(psF64 *)); 728 newPoly->mask[x][y] = ( char **)psAlloc(nZ * sizeof(char*));757 newPoly->mask[x][y] = (psMaskType **)psAlloc(nZ * sizeof(psMaskType *)); 729 758 for (z = 0; z < nZ; z++) { 730 759 newPoly->coeff[x][y][z] = psAlloc(nT * sizeof(psF64)); 731 760 newPoly->coeffErr[x][y][z] = psAlloc(nT * sizeof(psF64)); 732 newPoly->mask[x][y][z] = ( char *)psAlloc(nT * sizeof(char));761 newPoly->mask[x][y][z] = (psMaskType *)psAlloc(nT * sizeof(psMaskType)); 733 762 } 734 763 } … … 749 778 } 750 779 751 psF64 psPolynomial1DEval(const psPolynomial1D* poly, psF64 x) 780 psF64 psPolynomial1DEval(const psPolynomial1D* poly, 781 psF64 x) 752 782 { 753 783 PS_ASSERT_POLY_NON_NULL(poly, NAN); … … 775 805 776 806 tmp = psVectorAlloc(x->n, PS_TYPE_F64); 777 for ( psS32i=0;i<x->n;i++) {807 for (unsigned int i=0;i<x->n;i++) { 778 808 tmp->data.F64[i] = psPolynomial1DEval(poly, x->data.F64[i]); 779 809 } … … 782 812 } 783 813 784 psF64 psPolynomial2DEval(const psPolynomial2D* poly, psF64 x, psF64 y) 814 psF64 psPolynomial2DEval(const psPolynomial2D* poly, 815 psF64 x, 816 psF64 y) 785 817 { 786 818 PS_ASSERT_POLY_NON_NULL(poly, NAN); … … 810 842 811 843 psVector *tmp; 812 psS32vecLen=x->n;844 unsigned int vecLen=x->n; 813 845 814 846 // Determine the length of the output vector to by the minimum of the x,y vectors … … 821 853 822 854 // Evaluate the polynomial at the specified points 823 for ( psS32i=0; i<vecLen; i++) {855 for (unsigned int i=0; i<vecLen; i++) { 824 856 tmp->data.F64[i] = psPolynomial2DEval(poly,x->data.F64[i],y->data.F64[i]); 825 857 } … … 829 861 } 830 862 831 psF64 psPolynomial3DEval(const psPolynomial3D* poly, psF64 x, psF64 y, psF64 z) 863 psF64 psPolynomial3DEval(const psPolynomial3D* poly, 864 psF64 x, 865 psF64 y, 866 psF64 z) 832 867 { 833 868 PS_ASSERT_POLY_NON_NULL(poly, NAN); … … 860 895 861 896 psVector *tmp; 862 psS32vecLen=x->n;897 unsigned int vecLen=x->n; 863 898 864 899 // Determine the length of output vector from min of the input vectors … … 874 909 875 910 // Evaluate polynomial 876 for ( psS32i = 0; i < vecLen; i++) {911 for (unsigned int i = 0; i < vecLen; i++) { 877 912 tmp->data.F64[i] = psPolynomial3DEval(poly, 878 913 x->data.F64[i], … … 885 920 } 886 921 887 psF64 psPolynomial4DEval(const psPolynomial4D* poly, psF64 x, psF64 y, psF64 z, psF64 t) 922 psF64 psPolynomial4DEval(const psPolynomial4D* poly, 923 psF64 x, 924 psF64 y, 925 psF64 z, 926 psF64 t) 888 927 { 889 928 PS_ASSERT_POLY_NON_NULL(poly, NAN); … … 918 957 919 958 psVector *tmp; 920 psS32vecLen=x->n;959 unsigned int vecLen=x->n; 921 960 922 961 // Determine output vector size from min of input vectors … … 935 974 936 975 // Evaluate polynomial 937 for ( psS32i = 0; i < vecLen; i++) {976 for (unsigned int i = 0; i < vecLen; i++) { 938 977 tmp->data.F64[i] = psPolynomial4DEval(poly, 939 978 x->data.F64[i],
Note:
See TracChangeset
for help on using the changeset viewer.
