Changeset 10848
- Timestamp:
- Dec 28, 2006, 6:38:42 PM (19 years ago)
- Location:
- trunk/psLib
- Files:
-
- 27 edited
-
src/astro/psCoord.c (modified) (5 diffs)
-
src/math/psMinimizePolyFit.c (modified) (72 diffs)
-
src/math/psMinimizePolyFit.h (modified) (9 diffs)
-
src/math/psPolynomial.c (modified) (5 diffs)
-
src/math/psPolynomial.h (modified) (2 diffs)
-
src/math/psPolynomialUtils.c (modified) (4 diffs)
-
src/math/psPolynomialUtils.h (modified) (1 diff)
-
src/math/psStats.c (modified) (2 diffs)
-
test/math (modified) (1 prop)
-
test/math/.cvsignore (modified) (1 diff)
-
test/math/Makefile.am (modified) (2 diffs)
-
test/math/tap_psPolyFit1D.c (modified) (2 diffs)
-
test/math/tap_psPolyFit2D.c (modified) (2 diffs)
-
test/math/tap_psPolyFit3D.c (modified) (2 diffs)
-
test/math/tap_psPolyFit4D.c (modified) (2 diffs)
-
test/math/tap_psPolynomialEval2D.c (modified) (2 diffs)
-
test/math/tap_psPolynomialEval3D.c (modified) (2 diffs)
-
test/math/tap_psPolynomialEval4D.c (modified) (2 diffs)
-
test/math/tap_psPolynomialUtils_Derivatives.c (modified) (9 diffs)
-
test/math/tap_psStats00.c (modified) (16 diffs)
-
test/math/tap_psStats01.c (modified) (9 diffs)
-
test/math/tap_psStats02.c (modified) (9 diffs)
-
test/math/tap_psStats03.c (modified) (2 diffs)
-
test/math/tap_psStats06.c (modified) (2 diffs)
-
test/math/tap_psStats07.c (modified) (2 diffs)
-
test/math/tap_psStats08.c (modified) (4 diffs)
-
test/math/tap_psStats09.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psCoord.c
r10823 r10848 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.12 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-12-2 2 21:19:47$12 * @version $Revision: 1.129 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-12-29 04:38:42 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 905 905 } 906 906 907 trans->x = psVectorFitPolynomial2D(trans->x, NULL, 0, xOut, NULL, xIn, yIn); 908 trans->y = psVectorFitPolynomial2D(trans->y, NULL, 0, yOut, NULL, xIn, yIn); 907 bool result = true; 908 result &= psVectorFitPolynomial2D(trans->x, NULL, 0, xOut, NULL, xIn, yIn); 909 result &= psVectorFitPolynomial2D(trans->y, NULL, 0, yOut, NULL, xIn, yIn); 909 910 psFree(xIn); 910 911 psFree(yIn); … … 912 913 psFree(yOut); 913 914 914 if ( (trans->x == NULL) || (trans->y == NULL)) {915 if (!result) { 915 916 psError( PS_ERR_UNKNOWN, true, "psVectorFitPolynomial2D() returned NULL: could not fit a 2-D polynomial to the data.\n"); 916 917 return(false); … … 997 998 } 998 999 999 myPT->x = psVectorFitPolynomial2D(myPT->x, NULL, 0, xOut, NULL, xIn, yIn); 1000 myPT->y = psVectorFitPolynomial2D(myPT->y, NULL, 0, yOut, NULL, xIn, yIn); 1000 bool result = true; 1001 result &= psVectorFitPolynomial2D(myPT->x, NULL, 0, xOut, NULL, xIn, yIn); 1002 result &= psVectorFitPolynomial2D(myPT->y, NULL, 0, yOut, NULL, xIn, yIn); 1001 1003 1002 1004 psFree(inCoord); … … 1007 1009 psFree(yOut); 1008 1010 1009 if ( (myPT->x == NULL) || (myPT->y == NULL)) {1011 if (!result) { 1010 1012 psError( PS_ERR_UNKNOWN, true, "psVectorFitPolynomial2D() returned NULL: could not fit a 2-D polynomial to the data.\n"); 1011 1013 psFree(out); -
trunk/psLib/src/math/psMinimizePolyFit.c
r10778 r10848 10 10 * @author EAM, IfA 11 11 * 12 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-12- 17 09:43:48$12 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-12-29 04:38:42 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 55 55 }\ 56 56 }\ 57 58 // free a local temporary F64 vector (TEMP) which is a copy of a non-F64 vector (ORIG) 59 # define PS_FREE_TEMP_F64_VECTOR(ORIG, TEMP) \ 60 if ((ORIG != NULL) && (ORIG->type.type != PS_TYPE_F64)) { psFree(TEMP); } 57 61 58 62 /*****************************************************************************/ … … 281 285 *****************************************************************************/ 282 286 283 284 287 /****************************************************************************** 285 288 ****************************************************************************** … … 288 291 *****************************************************************************/ 289 292 290 static psPolynomial1D* VectorFitPolynomial1DOrd(291 psPolynomial1D* myPoly,292 const psVector *mask,293 psMaskType maskValue,294 const psVector *f,295 const psVector *fErr,296 const psVector *x);297 298 293 /****************************************************************************** 299 294 vectorFitPolynomial1DCheb(): This routine will fit a Chebyshev … … 301 296 coefficients of that polynomial. 302 297 *****************************************************************************/ 303 static psPolynomial1D *vectorFitPolynomial1DCheb(298 static bool vectorFitPolynomial1DCheb( 304 299 psPolynomial1D* myPoly, 305 300 const psVector *mask, … … 404 399 if (!psMatrixGJSolve(A, B)) { 405 400 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n"); 406 psFree(myPoly); 407 myPoly = NULL; 401 goto escape_GJ; 408 402 } else { 409 403 // the first nTerm entries in B correspond directly to the desired … … 427 421 if (ALUD == NULL) { 428 422 psError(PS_ERR_UNKNOWN, false, "Could not do LUD decomposition on matrix. Returning NULL.\n"); 429 psFree(myPoly); 430 myPoly = NULL; 423 goto escape_LUD; 431 424 } else { 432 425 coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm); 433 426 if (coeffs == NULL) { 434 427 psError(PS_ERR_UNKNOWN, false, "Could not solve LUD matrix. Returning NULL.\n"); 435 psFree(myPoly); 436 myPoly = NULL; 428 goto escape_LUD; 437 429 } else { 438 430 for (psS32 k = 0; k < numTerms; k++) { … … 441 433 } 442 434 } 443 444 445 435 psFree(ALUD); 446 436 psFree(coeffs); 447 437 psFree(outPerm); 448 438 } 449 450 439 psFree(A); 451 440 psFree(B); 452 453 return(myPoly); 441 return true; 442 443 escape_LUD: 444 // XXX drop the LUD version! 445 psFree(A); 446 psFree(B); 447 return false; 448 449 escape_GJ: 450 psFree(A); 451 psFree(B); 452 return false; 454 453 } 455 454 … … 459 458 x and fErr vectors may be NULL. All non-NULL vectors must be of type 460 459 PS_TYPE_F64. 461 *****************************************************************************/ 462 static psPolynomial1D* VectorFitPolynomial1DOrd( 460 461 XXX EAM : since this is a private function, can we drop the ASSERTS? 462 XXX EAM : can we drop the LUD version? it does not calculate coeffErr values!! 463 *****************************************************************************/ 464 static bool VectorFitPolynomial1DOrd( 463 465 psPolynomial1D* myPoly, 464 466 const psVector *mask, … … 469 471 { 470 472 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 471 PS_ASSERT_POLY_NON_NULL(myPoly, NULL);472 PS_ASSERT_VECTOR_NON_NULL(f, NULL);473 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, NULL);473 PS_ASSERT_POLY_NON_NULL(myPoly, false); 474 PS_ASSERT_VECTOR_NON_NULL(f, false); 475 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, false); 474 476 if (mask) { 475 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);476 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);477 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 478 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 477 479 } 478 480 if (x) { 479 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);480 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);481 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 482 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, false); 481 483 } 482 484 if (fErr) { 483 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL);484 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, NULL);485 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 486 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, false); 485 487 } 486 488 … … 510 512 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 511 513 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 512 psFree(myPoly);513 514 psFree(A); 514 515 psFree(B); 515 516 psTrace("psLib.math", 4, "---- %s() End ----\n", __func__); 516 return (NULL);517 return false; 517 518 } 518 519 … … 596 597 if (!psMatrixGJSolve(A, B)) { 597 598 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n"); 598 psFree(myPoly); 599 myPoly = NULL; 599 goto escape_GJ; 600 600 } else { 601 601 // the first nTerm entries in B correspond directly to the desired … … 617 617 if (ALUD == NULL) { 618 618 psError(PS_ERR_UNKNOWN, false, "Could not do LUD decomposition on matrix. Returning NULL.\n"); 619 psFree(myPoly); 620 myPoly = NULL; 619 goto escape_LUD; 621 620 } else { 622 621 coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm); 623 622 if (coeffs == NULL) { 624 623 psError(PS_ERR_UNKNOWN, false, "Could not solve LUD matrix. Returning NULL.\n"); 625 psFree(myPoly); 626 myPoly = NULL; 624 goto escape_LUD; 627 625 } else { 628 626 for (psS32 k = 0; k < nTerm; k++) { … … 632 630 } 633 631 } 634 635 632 psFree(ALUD); 636 633 psFree(coeffs); 637 634 psFree(outPerm); 638 635 } 639 640 641 636 psFree(A); 642 637 psFree(B); 643 638 644 639 psTrace("psLib.math", 4, "---- %s() End ----\n", __func__); 645 return (myPoly); 640 return true; 641 642 escape_LUD: 643 psFree(A); 644 psFree(B); 645 return false; 646 647 escape_GJ: 648 psFree(A); 649 psFree(B); 650 return false; 646 651 } 647 652 … … 653 658 conversion only. 654 659 *****************************************************************************/ 655 psPolynomial1D *psVectorFitPolynomial1D(660 bool psVectorFitPolynomial1D( 656 661 psPolynomial1D *poly, 657 662 const psVector *mask, … … 661 666 const psVector *x) 662 667 { 663 // Internal pointers for possibly NULL or mis-typed vectors. 668 PS_ASSERT_POLY_NON_NULL(poly, false); 669 PS_ASSERT_INT_NONNEGATIVE(poly->nX, false); 670 671 PS_ASSERT_VECTOR_NON_NULL(f, false); 672 PS_ASSERT_VECTOR_NON_EMPTY(f, false); 673 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 674 if (mask != NULL) { 675 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 676 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 677 } 678 if (fErr != NULL) { 679 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 680 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, false); 681 } 682 if (x != NULL) { 683 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 684 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, false); 685 } 686 687 // Convert input vectors to F64 if necessary. 688 psVector *f64 = (f->type.type == PS_TYPE_F64) ? (psVector *) f : psVectorCopy (NULL, f, PS_TYPE_F64); 664 689 psVector *x64 = NULL; 665 psVector *f64 = NULL; 690 if (x != NULL) { 691 x64 = (x->type.type == PS_TYPE_F64) ? (psVector *) x : psVectorCopy (NULL, x, PS_TYPE_F64); 692 } 666 693 psVector *fErr64 = NULL; 667 668 PS_ASSERT_POLY_NON_NULL(poly, NULL);669 //PS_ASSERT_INT_NONNEGATIVE(poly->nX, NULL);670 PS_ASSERT_VECTOR_NON_NULL(f, NULL);671 PS_ASSERT_VECTOR_NON_EMPTY(f, NULL);672 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);673 if (mask != NULL) {674 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);675 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);676 }677 if (x != NULL) {678 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);679 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL);680 }681 694 if (fErr != NULL) { 682 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); 683 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, NULL); 684 } 685 686 f64 = (f->type.type == PS_TYPE_F64) ? (psVector *) f : psVectorCopy(NULL, f, PS_TYPE_F64); 687 688 if (x != NULL) { 689 x64 = (x->type.type == PS_TYPE_F64) ? (psVector *) x : psVectorCopy(NULL, x, PS_TYPE_F64); 690 } 691 692 if (fErr != NULL) { 693 fErr64 = (fErr->type.type == PS_TYPE_F64) ? (psVector *) fErr : psVectorCopy(NULL, fErr, PS_TYPE_F64); 694 } 695 fErr64 = (fErr->type.type == PS_TYPE_F64) ? (psVector *) fErr : psVectorCopy (NULL, fErr, PS_TYPE_F64); 696 } 697 698 bool result = true; 695 699 696 700 switch (poly->type) { 697 701 case PS_POLYNOMIAL_ORD: 698 poly= VectorFitPolynomial1DOrd(poly, mask, maskValue, f64, fErr64, x64);699 if ( poly == NULL) {702 result = VectorFitPolynomial1DOrd(poly, mask, maskValue, f64, fErr64, x64); 703 if (!result) { 700 704 psError(PS_ERR_UNKNOWN, false, "Could not fit polynomial. Returning NULL.\n"); 701 705 } … … 703 707 case PS_POLYNOMIAL_CHEB: 704 708 if (mask != NULL) { 705 //psLogMsg(__func__, PS_LOG_WARN, "WARNING: ignoring mask and maskValue with Chebyshev polynomials.\n");709 psLogMsg(__func__, PS_LOG_WARN, "WARNING: ignoring mask and maskValue with Chebyshev polynomials.\n"); 706 710 } 707 711 if (fErr != NULL) { … … 713 717 } 714 718 715 poly = vectorFitPolynomial1DCheb(poly, mask, maskValue, f64, fErr64, x64); 719 result = vectorFitPolynomial1DCheb(poly, mask, maskValue, f64, fErr64, x64); 720 if (!result) { 721 psError(PS_ERR_UNKNOWN, false, "Could not fit polynomial. Returning NULL.\n"); 722 } 716 723 717 724 if (x == NULL) { … … 721 728 default: 722 729 psError(PS_ERR_UNKNOWN, true, "Incorrect polynomial type (%d). Returning NULL.\n", poly->type); 723 poly = NULL;730 result = false; 724 731 break; 725 732 } 726 733 727 734 // Free psVectors that were created for NULL arguments. 728 if (f->type.type != PS_TYPE_F64) { 729 psFree(f64); 730 } 731 732 if ((x != NULL) && (x->type.type != PS_TYPE_F64)) { 733 psFree(x64); 734 } 735 736 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 737 psFree(fErr64); 738 } 739 740 return(poly); 735 PS_FREE_TEMP_F64_VECTOR (f, f64); 736 PS_FREE_TEMP_F64_VECTOR (x, x64); 737 PS_FREE_TEMP_F64_VECTOR (fErr, fErr64); 738 739 return result; 741 740 } 742 741 743 742 // This function accepts F32 and F64 input vectors. 744 psPolynomial1D *psVectorClipFitPolynomial1D(743 bool psVectorClipFitPolynomial1D( 745 744 psPolynomial1D *poly, 746 745 psStats *stats, … … 752 751 { 753 752 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 754 PS_ASSERT_POLY_NON_NULL(poly, NULL); 755 PS_ASSERT_PTR_NON_NULL(stats, NULL); 756 PS_ASSERT_VECTOR_NON_NULL(f, NULL); 757 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL); 758 PS_ASSERT_VECTOR_NON_NULL(mask, NULL); 759 PS_ASSERT_VECTORS_SIZE_EQUAL(mask, f, NULL); 760 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL); 753 PS_ASSERT_POLY_NON_NULL(poly, false); 754 PS_ASSERT_PTR_NON_NULL(stats, false); 755 PS_ASSERT_VECTOR_NON_NULL(f, false); 756 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 757 PS_ASSERT_VECTOR_NON_NULL(mask, false); 758 PS_ASSERT_VECTORS_SIZE_EQUAL(mask, f, false); 759 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 760 761 761 if (fErr != NULL) { 762 PS_ASSERT_VECTORS_SIZE_EQUAL(fErr, f, NULL);763 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, NULL);762 PS_ASSERT_VECTORS_SIZE_EQUAL(fErr, f, false); 763 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, false); 764 764 } 765 765 … … 767 767 psVector *x = NULL; 768 768 if (xIn != NULL) { 769 PS_ASSERT_VECTORS_SIZE_EQUAL(xIn, f, NULL);770 PS_ASSERT_VECTOR_TYPE(xIn, f->type.type, NULL);769 PS_ASSERT_VECTORS_SIZE_EQUAL(xIn, f, false); 770 PS_ASSERT_VECTOR_TYPE(xIn, f->type.type, false); 771 771 x = (psVector *) xIn; 772 772 } else { … … 781 781 } else { 782 782 psError(PS_ERR_UNKNOWN, true, "Error, bad poly type.\n"); 783 return(NULL); 784 } 783 return false; 784 } 785 } 786 787 // the user supplies one of various stats option pairs, 788 // determine the desired mean and stdev STATS options: 789 // XXX enforce consistency? 790 // XXX psStatsGetValue() probably has inverted precedence 791 psStatsOptions meanOption = stats->options & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN | PS_STAT_FITTED_MEAN_V2); 792 psStatsOptions stdevOption = stats->options & (PS_STAT_SAMPLE_STDEV | PS_STAT_ROBUST_STDEV | PS_STAT_CLIPPED_STDEV | PS_STAT_FITTED_STDEV | PS_STAT_FITTED_STDEV_V2); 793 if (!meanOption) { 794 psError(PS_ERR_UNKNOWN, true, "no valid mean stats option selected"); 795 return false; 796 } 797 if (!stdevOption) { 798 psError(PS_ERR_UNKNOWN, true, "no valid stdev stats option selected"); 799 return false; 785 800 } 786 801 … … 798 813 minClipSigma = fabs(stats->clipSigma); 799 814 } 800 801 psVector *fit = NULL;802 815 psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64); 803 816 804 // eventual expansion: user supplies one of various stats option pairs,805 // eg (SAMPLE_MEAN | SAMPLE_STDEV) and the correct pair is used to806 // evaluate the clipping sigma807 // for now, for the SAMPLE_MEDIAN and SAMPLE_STDEV to be used808 stats->options |= (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);809 stats->options |= (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);810 817 psTrace("psLib.math", 4, "stats->clipIter is %d\n", stats->clipIter); 811 818 psTrace("psLib.math", 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma); … … 822 829 } 823 830 } 824 poly = psVectorFitPolynomial1D(poly, mask, maskValue, f, fErr, x); 825 if (poly == NULL) { 826 psError(PS_ERR_UNKNOWN, false, "Could not fit polynomial. Returning NULL.\n"); 831 if (!psVectorFitPolynomial1D(poly, mask, maskValue, f, fErr, x)) { 832 psError(PS_ERR_UNKNOWN, false, "Could not fit polynomial. Returning false.\n"); 827 833 if (xIn == NULL) { 828 834 psFree(x); 829 835 } 830 return (NULL);831 } 832 833 fit = psPolynomial1DEvalVector(poly, x);836 return false; 837 } 838 839 psVector *fit = psPolynomial1DEvalVector(poly, x); 834 840 if (fit == NULL) { 835 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning NULL.\n");841 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning false.\n"); 836 842 psFree(resid); 837 return (NULL);843 return false; 838 844 } 839 845 for (psS32 i = 0 ; i < f->n ; i++) { … … 856 862 857 863 if (!psVectorStats(stats, resid, NULL, mask, maskValue)) { 858 psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector. Returning NULL.\n"); 859 psFree(resid) 860 psFree(fit) 861 return(NULL); 862 } 863 # if (USE_ROBUST_STATS_FOR_CLIPPING) 864 psTrace("psLib.math", 5, "Median is %f\n", stats->robustMedian); 865 psTrace("psLib.math", 5, "Stdev is %f\n", stats->robustStdev); 866 psF32 minClipValue = -minClipSigma*stats->robustStdev; 867 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 868 psF32 clipMedian = stats->robustMedian; 869 # else 870 871 psTrace("psLib.math", 5, "Median is %f\n", stats->sampleMedian); 872 psTrace("psLib.math", 5, "Stdev is %f\n", stats->sampleStdev); 873 psF32 minClipValue = -minClipSigma*stats->robustStdev; 874 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 875 psF32 clipMedian = stats->sampleMedian; 876 # endif 864 psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector. Returning false.\n"); 865 psFree(resid); 866 psFree(fit); 867 return false; 868 } 869 870 double meanValue = psStatsGetValue (stats, meanOption); 871 double stdevValue = psStatsGetValue (stats, stdevOption); 872 873 psTrace("psLib.math", 5, "Mean is %f\n", meanValue); 874 psTrace("psLib.math", 5, "Stdev is %f\n", stdevValue); 875 psF32 minClipValue = -minClipSigma*stdevValue; 876 psF32 maxClipValue = +maxClipSigma*stdevValue; 877 877 878 878 // set mask if pts are not valid … … 884 884 } 885 885 886 if ((resid->data.F64[i] - clipMedian > maxClipValue) || (resid->data.F64[i] - clipMedian< minClipValue)) {886 if ((resid->data.F64[i] - meanValue > maxClipValue) || (resid->data.F64[i] - meanValue < minClipValue)) { 887 887 if (f->type.type == PS_TYPE_F64) { 888 888 psTrace("psLib.math", 6, "Masking element %d (%f). resid->data.F64[%d] is %f\n", … … 906 906 // 907 907 psTrace("psLib.math", 6, "keeping %d of %ld pts for fit\n", Nkeep, x->n); 908 stats->clippedNvalues = Nkeep; 908 909 psFree(fit); 909 910 } … … 917 918 918 919 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 919 return (poly);920 return true; 920 921 } 921 922 … … 933 934 934 935 *****************************************************************************/ 935 static psPolynomial2D*VectorFitPolynomial2DOrd(936 static bool VectorFitPolynomial2DOrd( 936 937 psPolynomial2D* myPoly, 937 938 const psVector* mask, … … 943 944 { 944 945 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 945 PS_ASSERT_POLY_NON_NULL(myPoly, NULL);946 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL);947 PS_ASSERT_INT_NONNEGATIVE(myPoly->nY, NULL);948 PS_ASSERT_VECTOR_NON_NULL(f, NULL);949 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, NULL);946 PS_ASSERT_POLY_NON_NULL(myPoly, false); 947 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, false); 948 PS_ASSERT_INT_NONNEGATIVE(myPoly->nY, false); 949 PS_ASSERT_VECTOR_NON_NULL(f, false); 950 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, false); 950 951 if (fErr != NULL) { 951 PS_ASSERT_VECTORS_SIZE_EQUAL(y, fErr, NULL);952 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, NULL);953 } 954 PS_ASSERT_VECTOR_NON_NULL(x, NULL);955 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);956 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);957 PS_ASSERT_VECTOR_NON_NULL(y, NULL);958 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);959 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);952 PS_ASSERT_VECTORS_SIZE_EQUAL(y, fErr, false); 953 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, false); 954 } 955 PS_ASSERT_VECTOR_NON_NULL(x, false); 956 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, false); 957 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 958 PS_ASSERT_VECTOR_NON_NULL(y, false); 959 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, false); 960 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 960 961 if (mask != NULL) { 961 PS_ASSERT_VECTORS_SIZE_EQUAL(y, mask, NULL);962 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);962 PS_ASSERT_VECTORS_SIZE_EQUAL(y, mask, false); 963 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 963 964 } 964 965 … … 974 975 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 975 976 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 976 psFree(myPoly);977 977 psFree(A); 978 978 psFree(B); 979 979 psTrace("psLib.math", 4, "---- %s() End ----\n", __func__); 980 return (NULL);980 return false; 981 981 } 982 982 … … 1040 1040 if (!psMatrixGJSolve(A, B)) { 1041 1041 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n"); 1042 psFree( myPoly);1043 myPoly = NULL;1044 } else {1045 // select the appropriate solution entries1046 for (int i = 0; i < nTerm; i++) { 1047 int l = i / nYterm; // x index1048 int m = i % nYterm; // y index1049 myPoly->coeff[l][m] = B->data.F64[i];1050 myPoly->coeffErr[l][m] = sqrt(A->data.F64[i][i]);1051 }1052 }1053 1042 psFree(A); 1043 psFree(B); 1044 return false; 1045 } 1046 1047 // select the appropriate solution entries 1048 for (int i = 0; i < nTerm; i++) { 1049 int l = i / nYterm; // x index 1050 int m = i % nYterm; // y index 1051 myPoly->coeff[l][m] = B->data.F64[i]; 1052 myPoly->coeffErr[l][m] = sqrt(A->data.F64[i][i]); 1053 } 1054 1054 psFree(A); 1055 1055 psFree(B); 1056 1056 1057 1057 psTrace("psLib.math", 4, "---- %s() end ----\n", __func__); 1058 return (myPoly);1058 return true; 1059 1059 } 1060 1060 … … 1065 1065 vector conversion only. 1066 1066 *****************************************************************************/ 1067 psPolynomial2D *psVectorFitPolynomial2D(1067 bool psVectorFitPolynomial2D( 1068 1068 psPolynomial2D *poly, 1069 1069 const psVector *mask, … … 1074 1074 const psVector *y) 1075 1075 { 1076 // Internal pointers for possibly NULL or mis-typed vectors. 1077 psVector *x64 = NULL; 1078 psVector *y64 = NULL; 1079 psVector *f64 = NULL; 1076 PS_ASSERT_POLY_NON_NULL(poly, false); 1077 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, false); 1078 1079 PS_ASSERT_VECTOR_NON_NULL(f, false); 1080 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 1081 PS_ASSERT_VECTOR_NON_NULL(x, false); 1082 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 1083 PS_ASSERT_VECTOR_NON_NULL(y, false); 1084 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 1085 if (mask != NULL) { 1086 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 1087 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 1088 } 1089 if (fErr != NULL) { 1090 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 1091 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, false); 1092 } 1093 1094 // Convert input vectors to F64 if necessary. 1095 psVector *f64 = (f->type.type == PS_TYPE_F64) ? (psVector *) f : psVectorCopy(NULL, f, PS_TYPE_F64); 1096 psVector *x64 = (x->type.type == PS_TYPE_F64) ? (psVector *) x : psVectorCopy(NULL, x, PS_TYPE_F64); 1097 psVector *y64 = (y->type.type == PS_TYPE_F64) ? (psVector *) y : psVectorCopy(NULL, y, PS_TYPE_F64); 1098 1080 1099 psVector *fErr64 = NULL; 1081 1082 PS_ASSERT_POLY_NON_NULL(poly, NULL);1083 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, NULL);1084 1085 PS_ASSERT_VECTOR_NON_NULL(f, NULL);1086 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);1087 1088 if (mask != NULL) {1089 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);1090 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);1091 }1092 PS_ASSERT_VECTOR_NON_NULL(x, NULL);1093 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);1094 PS_ASSERT_VECTOR_NON_NULL(y, NULL);1095 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);1096 1100 if (fErr != NULL) { 1097 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); 1098 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, NULL); 1099 } 1100 1101 // 1102 // Convert input vectors to F64 if necessary. 1103 // 1104 if (f->type.type != PS_TYPE_F64) { 1105 f64 = psVectorCopy(NULL, f, PS_TYPE_F64); 1106 } else { 1107 f64 = (psVector *) f; 1108 } 1109 1110 if (x->type.type != PS_TYPE_F64) { 1111 x64 = psVectorCopy(NULL, x, PS_TYPE_F64); 1112 } else { 1113 x64 = (psVector *) x; 1114 } 1115 1116 if (y->type.type != PS_TYPE_F64) { 1117 y64 = psVectorCopy(NULL, y, PS_TYPE_F64); 1118 } else { 1119 y64 = (psVector *) y; 1120 } 1121 1122 // 1123 // fErr 1124 // 1125 if (fErr != NULL) { 1126 if (fErr->type.type != PS_TYPE_F64) { 1127 fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64); 1128 } else { 1129 fErr64 = (psVector *) fErr; 1130 } 1131 } 1132 1133 if (poly->type == PS_POLYNOMIAL_ORD) { 1134 poly = VectorFitPolynomial2DOrd(poly, mask, maskValue, f64, fErr64, x64, y64); 1135 if (poly == NULL) { 1101 fErr64 = (fErr->type.type == PS_TYPE_F64) ? (psVector *) fErr : psVectorCopy(NULL, fErr, PS_TYPE_F64); 1102 } 1103 1104 bool result = true; 1105 1106 switch (poly->type) { 1107 case PS_POLYNOMIAL_ORD: 1108 result = VectorFitPolynomial2DOrd(poly, mask, maskValue, f64, fErr64, x64, y64); 1109 if (!result) { 1136 1110 psError(PS_ERR_UNKNOWN, true, "Could not fit polynomial. Returning NULL.\n"); 1137 // Free psVectors that were created for NULL arguments. 1138 if (f->type.type != PS_TYPE_F64) { 1139 psFree(f64); 1140 } 1141 1142 if (x->type.type != PS_TYPE_F64) { 1143 psFree(x64); 1144 } 1145 1146 if (y->type.type != PS_TYPE_F64) { 1147 psFree(y64); 1148 } 1149 1150 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 1151 psFree(fErr64); 1152 } 1153 return(NULL); 1154 } 1155 } else if (poly->type == PS_POLYNOMIAL_CHEB) { 1111 } 1112 break; 1113 case PS_POLYNOMIAL_CHEB: 1156 1114 if (mask != NULL) { 1157 1115 psLogMsg(__func__, PS_LOG_WARN, "WARNING: ignoring mask and maskValue with Chebyshev polynomials.\n"); 1158 1116 } 1159 psLogMsg(__func__, PS_LOG_WARN, "WARNING: 2-D Chebyshev polynomial vector fitting has not been implemented. Returning NULL.\n"); 1160 psFree(poly); 1161 poly = NULL; 1162 } else { 1163 // Free psVectors that were created for NULL arguments. 1164 if (f->type.type != PS_TYPE_F64) { 1165 psFree(f64); 1166 } 1167 1168 if (x->type.type != PS_TYPE_F64) { 1169 psFree(x64); 1170 } 1171 1172 if (y->type.type != PS_TYPE_F64) { 1173 psFree(y64); 1174 } 1175 1176 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 1177 psFree(fErr64); 1178 } 1117 psError(PS_ERR_UNKNOWN, true, "2-D Chebyshev polynomial vector fitting has not been implemented. Returning NULL.\n"); 1118 result = false; 1119 break; 1120 default: 1179 1121 psError(PS_ERR_UNKNOWN, true, "Incorrect polynomial type. Returning NULL.\n"); 1180 } 1181 1122 result = false; 1123 break; 1124 } 1182 1125 1183 1126 // Free psVectors that were created for NULL arguments. 1184 if (f->type.type != PS_TYPE_F64) { 1185 psFree(f64); 1186 } 1187 1188 if (x->type.type != PS_TYPE_F64) { 1189 psFree(x64); 1190 } 1191 1192 if (y->type.type != PS_TYPE_F64) { 1193 psFree(y64); 1194 } 1195 1196 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 1197 psFree(fErr64); 1198 } 1199 1200 return(poly); 1127 PS_FREE_TEMP_F64_VECTOR (f, f64); 1128 PS_FREE_TEMP_F64_VECTOR (x, x64); 1129 PS_FREE_TEMP_F64_VECTOR (y, y64); 1130 PS_FREE_TEMP_F64_VECTOR (fErr, fErr64); 1131 1132 return result; 1201 1133 } 1202 1134 1203 psPolynomial2D *psVectorClipFitPolynomial2D(1135 bool psVectorClipFitPolynomial2D( 1204 1136 psPolynomial2D *poly, 1205 1137 psStats *stats, … … 1212 1144 { 1213 1145 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 1214 PS_ASSERT_POLY_NON_NULL(poly, NULL);1215 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, NULL);1216 PS_ASSERT_PTR_NON_NULL(stats, NULL);1217 PS_ASSERT_VECTOR_NON_NULL(mask, NULL);1218 PS_ASSERT_VECTOR_NON_NULL(f, NULL);1219 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);1220 if (mask != NULL) { 1221 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);1222 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);1223 }1224 PS_ASSERT_VECTOR_NON_NULL(x, NULL); 1225 PS_ASSERT_VECTOR S_SIZE_EQUAL(f, x, NULL);1226 PS_ASSERT_VECTOR _TYPE(x, f->type.type, NULL);1227 1228 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 1229 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);1230 PS_ASSERT_VECTOR_TYPE( y, f->type.type, NULL);1146 PS_ASSERT_POLY_NON_NULL(poly, false); 1147 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, false); 1148 PS_ASSERT_PTR_NON_NULL(stats, false); 1149 PS_ASSERT_VECTOR_NON_NULL(mask, false); 1150 PS_ASSERT_VECTOR_NON_NULL(f, false); 1151 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 1152 1153 PS_ASSERT_VECTOR_NON_NULL(x, false); 1154 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 1155 PS_ASSERT_VECTOR_TYPE(x, f->type.type, false); 1156 1157 PS_ASSERT_VECTOR_NON_NULL(y, false); 1158 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 1159 PS_ASSERT_VECTOR_TYPE(y, f->type.type, false); 1160 1161 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 1162 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 1231 1163 1232 1164 if (fErr != NULL) { 1233 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); 1234 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, NULL); 1165 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 1166 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, false); 1167 } 1168 1169 // the user supplies one of various stats option pairs, 1170 // determine the desired mean and stdev STATS options: 1171 // XXX enforce consistency? 1172 // XXX psStatsGetValue() probably has inverted precedence 1173 psStatsOptions meanOption = stats->options & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN | PS_STAT_FITTED_MEAN_V2); 1174 psStatsOptions stdevOption = stats->options & (PS_STAT_SAMPLE_STDEV | PS_STAT_ROBUST_STDEV | PS_STAT_CLIPPED_STDEV | PS_STAT_FITTED_STDEV | PS_STAT_FITTED_STDEV_V2); 1175 if (!meanOption) { 1176 psError(PS_ERR_UNKNOWN, true, "no valid mean stats option selected"); 1177 return false; 1178 } 1179 if (!stdevOption) { 1180 psError(PS_ERR_UNKNOWN, true, "no valid stdev stats option selected"); 1181 return false; 1235 1182 } 1236 1183 … … 1250 1197 psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64); 1251 1198 1252 // eventual expansion: user supplies one of various stats option pairs,1253 // eg (SAMPLE_MEAN | SAMPLE_STDEV) and the correct pair is used to1254 // evaluate the clipping sigma1255 // for now, for the SAMPLE_MEDIAN and SAMPLE_STDEV to be used1256 stats->options |= (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);1257 stats->options |= (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);1258 1199 psTrace("psLib.math", 4, "stats->clipIter is %d\n", stats->clipIter); 1259 1200 psTrace("psLib.math", 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma); … … 1270 1211 } 1271 1212 1272 poly = psVectorFitPolynomial2D(poly, mask, maskValue, f, fErr, x, y); 1273 if (poly == NULL) { 1274 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data. Returning NULL.\n"); 1213 if (!psVectorFitPolynomial2D(poly, mask, maskValue, f, fErr, x, y)) { 1214 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data. Returning false.\n"); 1275 1215 psFree(resid) 1276 return (NULL);1216 return false; 1277 1217 } 1278 1218 … … 1281 1221 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning NULL.\n"); 1282 1222 psFree(resid) 1283 return (NULL);1223 return false; 1284 1224 } 1285 1225 … … 1307 1247 psFree(resid) 1308 1248 psFree(fit) 1309 return(NULL); 1310 } 1311 # if (USE_ROBUST_STATS_FOR_CLIPPING) 1312 psTrace("psLib.math", 5, "Median is %f\n", stats->robustMedian); 1313 psTrace("psLib.math", 5, "Stdev is %f\n", stats->robustStdev); 1314 psTrace("psLib.math", 5, "Sample Median is %f\n", stats->sampleMedian); 1315 psTrace("psLib.math", 5, "Sample Stdev is %f\n", stats->sampleStdev); 1316 psF32 minClipValue = -minClipSigma*stats->robustStdev; 1317 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 1318 psF32 clipMedian = stats->robustMedian; 1319 # else 1320 1321 psTrace("psLib.math", 5, "Median is %f\n", stats->sampleMedian); 1322 psTrace("psLib.math", 5, "Stdev is %f\n", stats->sampleStdev); 1323 psTrace("psLib.math", 5, "Robust Median is %f\n", stats->robustMedian); 1324 psTrace("psLib.math", 5, "Robust Stdev is %f\n", stats->robustStdev); 1325 psF32 minClipValue = -minClipSigma*stats->robustStdev; 1326 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 1327 psF32 clipMedian = stats->sampleMedian; 1328 # endif 1249 return false; 1250 } 1251 1252 double meanValue = psStatsGetValue (stats, meanOption); 1253 double stdevValue = psStatsGetValue (stats, stdevOption); 1254 1255 psTrace("psLib.math", 5, "Mean is %f\n", meanValue); 1256 psTrace("psLib.math", 5, "Stdev is %f\n", stdevValue); 1257 psF32 minClipValue = -minClipSigma*stdevValue; 1258 psF32 maxClipValue = +maxClipSigma*stdevValue; 1329 1259 1330 1260 // set mask if pts are not valid … … 1336 1266 } 1337 1267 1338 if ((resid->data.F64[i] - clipMedian > maxClipValue) || (resid->data.F64[i] - clipMedian< minClipValue)) {1268 if ((resid->data.F64[i] - meanValue > maxClipValue) || (resid->data.F64[i] - meanValue < minClipValue)) { 1339 1269 if (fit->type.type == PS_TYPE_F64) { 1340 1270 psTrace("psLib.math", 6, "Masking element %d (%f). resid->data.F64[%d] is %f\n", … … 1352 1282 Nkeep++; 1353 1283 } 1354 1355 1284 psTrace("psLib.math", 4, "keeping %d of %ld pts for fit\n", Nkeep, x->n); 1285 stats->clippedNvalues = Nkeep; 1356 1286 psFree(fit); 1357 1287 } … … 1359 1289 psFree(resid); 1360 1290 1361 if (poly == NULL) {1362 psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data. Returning NULL.\n");1363 return(NULL);1364 }1365 1366 1291 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 1367 return (poly);1292 return true; 1368 1293 } 1369 1294 … … 1381 1306 1382 1307 *****************************************************************************/ 1383 static psPolynomial3D*VectorFitPolynomial3DOrd(1308 static bool VectorFitPolynomial3DOrd( 1384 1309 psPolynomial3D* myPoly, 1385 1310 const psVector* mask, … … 1392 1317 { 1393 1318 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 1394 PS_ASSERT_POLY_NON_NULL(myPoly, NULL);1395 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL);1396 PS_ASSERT_INT_NONNEGATIVE(myPoly->nY, NULL);1397 PS_ASSERT_INT_NONNEGATIVE(myPoly->nZ, NULL);1398 1399 PS_ASSERT_VECTOR_NON_NULL(f, NULL);1400 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, NULL);1319 PS_ASSERT_POLY_NON_NULL(myPoly, false); 1320 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, false); 1321 PS_ASSERT_INT_NONNEGATIVE(myPoly->nY, false); 1322 PS_ASSERT_INT_NONNEGATIVE(myPoly->nZ, false); 1323 1324 PS_ASSERT_VECTOR_NON_NULL(f, false); 1325 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, false); 1401 1326 if (fErr != NULL) { 1402 PS_ASSERT_VECTORS_SIZE_EQUAL(y, fErr, NULL);1403 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, NULL);1404 } 1405 PS_ASSERT_VECTOR_NON_NULL(x, NULL);1406 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);1407 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);1408 PS_ASSERT_VECTOR_NON_NULL(y, NULL);1409 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);1410 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);1411 PS_ASSERT_VECTOR_NON_NULL(z, NULL);1412 PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);1413 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL);1327 PS_ASSERT_VECTORS_SIZE_EQUAL(y, fErr, false); 1328 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, false); 1329 } 1330 PS_ASSERT_VECTOR_NON_NULL(x, false); 1331 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, false); 1332 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 1333 PS_ASSERT_VECTOR_NON_NULL(y, false); 1334 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, false); 1335 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 1336 PS_ASSERT_VECTOR_NON_NULL(z, false); 1337 PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, false); 1338 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, false); 1414 1339 if (mask != NULL) { 1415 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL); 1416 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL); 1417 } 1418 1340 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 1341 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 1342 } 1419 1343 1420 1344 int nXterm = 1 + myPoly->nX; // Number of x terms … … 1429 1353 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 1430 1354 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 1431 psFree(myPoly);1432 1355 psFree(A); 1433 1356 psFree(B); 1434 1357 psTrace("psLib.math", 4, "---- %s() End ----\n", __func__); 1435 return (NULL);1358 return false; 1436 1359 } 1437 1360 … … 1511 1434 // The matrices were overflowing, so I switched to LUD. 1512 1435 if (!psMatrixGJSolve(A, B)) { 1513 psFree(A);1514 psFree(B);1515 1436 psError(PS_ERR_UNKNOWN, false, "Failed to perform GaussJordan elimination.\n"); 1516 return(NULL);1437 goto escape_GJ; 1517 1438 } 1518 1439 // select the appropriate solution entries … … 1534 1455 if (ALUD == NULL) { 1535 1456 psError(PS_ERR_UNKNOWN, false, "Could not do LUD decomposition on matrix. Returning NULL.\n"); 1536 psFree(myPoly); 1537 myPoly = NULL; 1457 goto escape_LUD; 1538 1458 } else { 1539 1459 coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm); 1540 1460 if (coeffs == NULL) { 1541 1461 psError(PS_ERR_UNKNOWN, false, "Could not solve LUD matrix. Returning NULL.\n"); 1542 psFree(myPoly); 1543 myPoly = NULL; 1462 goto escape_LUD; 1544 1463 } else { 1545 1464 // select the appropriate solution entries … … 1565 1484 1566 1485 psTrace("psLib.math", 4, "---- %s() end ----\n", __func__); 1567 return (myPoly); 1486 return true; 1487 1488 escape_LUD: 1489 psFree(A); 1490 psFree(B); 1491 return false; 1492 1493 escape_GJ: 1494 1495 psFree(A); 1496 psFree(B); 1497 return false; 1568 1498 } 1569 1499 … … 1574 1504 vector conversion only. 1575 1505 *****************************************************************************/ 1576 psPolynomial3D *psVectorFitPolynomial3D(1506 bool psVectorFitPolynomial3D( 1577 1507 psPolynomial3D *poly, 1578 1508 const psVector *mask, … … 1584 1514 const psVector *z) 1585 1515 { 1586 // Internal pointers for possibly NULL or mis-typed vectors. 1587 psVector *x64 = NULL; 1588 psVector *y64 = NULL; 1589 psVector *z64 = NULL; 1590 psVector *f64 = NULL; 1516 PS_ASSERT_POLY_NON_NULL(poly, false); 1517 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, false); 1518 1519 PS_ASSERT_VECTOR_NON_NULL(f, false); 1520 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 1521 PS_ASSERT_VECTOR_NON_NULL(x, false); 1522 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 1523 PS_ASSERT_VECTOR_NON_NULL(y, false); 1524 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 1525 PS_ASSERT_VECTOR_NON_NULL(z, false); 1526 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, false); 1527 if (mask != NULL) { 1528 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 1529 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 1530 } 1531 if (fErr != NULL) { 1532 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 1533 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, false); 1534 } 1535 1536 // Convert input vectors to F64 if necessary. 1537 psVector *f64 = (f->type.type == PS_TYPE_F64) ? (psVector *) f : psVectorCopy(NULL, f, PS_TYPE_F64); 1538 psVector *x64 = (x->type.type == PS_TYPE_F64) ? (psVector *) x : psVectorCopy(NULL, x, PS_TYPE_F64); 1539 psVector *y64 = (y->type.type == PS_TYPE_F64) ? (psVector *) y : psVectorCopy(NULL, y, PS_TYPE_F64); 1540 psVector *z64 = (z->type.type == PS_TYPE_F64) ? (psVector *) z : psVectorCopy(NULL, z, PS_TYPE_F64); 1541 1591 1542 psVector *fErr64 = NULL; 1592 1593 PS_ASSERT_POLY_NON_NULL(poly, NULL);1594 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, NULL);1595 1596 PS_ASSERT_VECTOR_NON_NULL(f, NULL);1597 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);1598 if (mask != NULL) {1599 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);1600 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);1601 }1602 PS_ASSERT_VECTOR_NON_NULL(x, NULL);1603 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);1604 PS_ASSERT_VECTOR_NON_NULL(y, NULL);1605 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);1606 PS_ASSERT_VECTOR_NON_NULL(z, NULL);1607 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL);1608 1543 if (fErr != NULL) { 1609 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); 1610 // PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, NULL); 1611 } 1612 1613 // 1614 // Convert input vectors to F64 if necessary. 1615 // 1616 if (f->type.type != PS_TYPE_F64) { 1617 f64 = psVectorCopy(NULL, f, PS_TYPE_F64); 1618 } else { 1619 f64 = (psVector *) f; 1620 } 1621 if (x->type.type != PS_TYPE_F64) { 1622 x64 = psVectorCopy(NULL, x, PS_TYPE_F64); 1623 } else { 1624 x64 = (psVector *) x; 1625 } 1626 if (y->type.type != PS_TYPE_F64) { 1627 y64 = psVectorCopy(NULL, y, PS_TYPE_F64); 1628 } else { 1629 y64 = (psVector *) y; 1630 } 1631 1632 if (z->type.type != PS_TYPE_F64) { 1633 z64 = psVectorCopy(NULL, z, PS_TYPE_F64); 1634 } else { 1635 z64 = (psVector *) z; 1636 } 1637 1638 if (fErr != NULL) { 1639 if (fErr->type.type != PS_TYPE_F64) { 1640 fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64); 1641 } else { 1642 fErr64 = (psVector *) fErr; 1643 } 1644 } 1645 1646 if (poly->type == PS_POLYNOMIAL_ORD) { 1647 poly = VectorFitPolynomial3DOrd(poly, mask, maskValue, f64, fErr64, x64, y64, z64); 1648 if (poly == NULL) { 1544 fErr64 = (fErr->type.type == PS_TYPE_F64) ? (psVector *) fErr : psVectorCopy(NULL, fErr, PS_TYPE_F64); 1545 } 1546 1547 bool result = true; 1548 1549 switch (poly->type) { 1550 case PS_POLYNOMIAL_ORD: 1551 result = VectorFitPolynomial3DOrd(poly, mask, maskValue, f64, fErr64, x64, y64, z64); 1552 if (!result) { 1649 1553 psError(PS_ERR_UNKNOWN, true, "Could not fit polynomial. Returning NULL.\n"); 1650 // Free psVectors that were created for NULL arguments. 1651 if (f->type.type != PS_TYPE_F64) { 1652 psFree(f64); 1653 } 1654 1655 if (x->type.type != PS_TYPE_F64) { 1656 psFree(x64); 1657 } 1658 1659 if (y->type.type != PS_TYPE_F64) { 1660 psFree(y64); 1661 } 1662 1663 if (z->type.type != PS_TYPE_F64) { 1664 psFree(z64); 1665 } 1666 1667 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 1668 psFree(fErr64); 1669 } 1670 return(NULL); 1671 } 1672 } else if (poly->type == PS_POLYNOMIAL_CHEB) { 1554 } 1555 break; 1556 case PS_POLYNOMIAL_CHEB: 1673 1557 if (mask != NULL) { 1674 1558 psLogMsg(__func__, PS_LOG_WARN, "WARNING: ignoring mask and maskValue with Chebyshev polynomials.\n"); 1675 1559 } 1676 psLogMsg(__func__, PS_LOG_WARN, "WARNING: 3-D Chebyshev polynomial vector fitting has not been implemented. Returning NULL.\n"); 1677 psFree(poly); 1678 poly = NULL; 1679 } else { 1680 // Free psVectors that were created for NULL arguments. 1681 if (f->type.type != PS_TYPE_F64) { 1682 psFree(f64); 1683 } 1684 1685 if (x->type.type != PS_TYPE_F64) { 1686 psFree(x64); 1687 } 1688 1689 if (y->type.type != PS_TYPE_F64) { 1690 psFree(y64); 1691 } 1692 1693 if (z->type.type != PS_TYPE_F64) { 1694 psFree(z64); 1695 } 1696 1697 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 1698 psFree(fErr64); 1699 } 1560 psError(PS_ERR_UNKNOWN, true, "3-D Chebyshev polynomial vector fitting has not been implemented. Returning NULL.\n"); 1561 result = false; 1562 break; 1563 default: 1700 1564 psError(PS_ERR_UNKNOWN, true, "Incorrect polynomial type. Returning NULL.\n"); 1701 } 1702 1565 result = false; 1566 break; 1567 } 1703 1568 1704 1569 // Free psVectors that were created for NULL arguments. 1705 if (f->type.type != PS_TYPE_F64) { 1706 psFree(f64); 1707 } 1708 1709 if (x->type.type != PS_TYPE_F64) { 1710 psFree(x64); 1711 } 1712 1713 if (y->type.type != PS_TYPE_F64) { 1714 psFree(y64); 1715 } 1716 1717 if (z->type.type != PS_TYPE_F64) { 1718 psFree(z64); 1719 } 1720 1721 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 1722 psFree(fErr64); 1723 } 1724 1725 return(poly); 1570 PS_FREE_TEMP_F64_VECTOR (f, f64); 1571 PS_FREE_TEMP_F64_VECTOR (x, x64); 1572 PS_FREE_TEMP_F64_VECTOR (y, y64); 1573 PS_FREE_TEMP_F64_VECTOR (z, z64); 1574 PS_FREE_TEMP_F64_VECTOR (fErr, fErr64); 1575 1576 return result; 1726 1577 } 1727 1578 1728 psPolynomial3D *psVectorClipFitPolynomial3D(1579 bool psVectorClipFitPolynomial3D( 1729 1580 psPolynomial3D *poly, 1730 1581 psStats *stats, … … 1738 1589 { 1739 1590 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 1740 PS_ASSERT_POLY_NON_NULL(poly, NULL);1741 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, NULL);1742 PS_ASSERT_PTR_NON_NULL(stats, NULL);1743 PS_ASSERT_VECTOR_NON_NULL(mask, NULL);1744 PS_ASSERT_VECTOR_NON_NULL(f, NULL);1745 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);1746 if (mask != NULL) { 1747 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);1748 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);1749 }1750 PS_ASSERT_VECTOR_NON_NULL(x, NULL); 1751 PS_ASSERT_VECTOR S_SIZE_EQUAL(f, x, NULL);1752 PS_ASSERT_VECTOR _TYPE(x, f->type.type, NULL);1753 1754 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 1755 PS_ASSERT_VECTOR S_SIZE_EQUAL(f, y, NULL);1756 PS_ASSERT_VECTOR _TYPE(y, f->type.type, NULL);1757 1758 PS_ASSERT_VECTOR_NON_NULL(z, NULL); 1759 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL);1760 PS_ASSERT_VECTOR_TYPE( z, f->type.type, NULL);1591 PS_ASSERT_POLY_NON_NULL(poly, false); 1592 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, false); 1593 PS_ASSERT_PTR_NON_NULL(stats, false); 1594 PS_ASSERT_VECTOR_NON_NULL(mask, false); 1595 PS_ASSERT_VECTOR_NON_NULL(f, false); 1596 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 1597 1598 PS_ASSERT_VECTOR_NON_NULL(x, false); 1599 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 1600 PS_ASSERT_VECTOR_TYPE(x, f->type.type, false); 1601 1602 PS_ASSERT_VECTOR_NON_NULL(y, false); 1603 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 1604 PS_ASSERT_VECTOR_TYPE(y, f->type.type, false); 1605 1606 PS_ASSERT_VECTOR_NON_NULL(z, false); 1607 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, false); 1608 PS_ASSERT_VECTOR_TYPE(z, f->type.type, false); 1609 1610 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 1611 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 1761 1612 1762 1613 if (fErr != NULL) { 1763 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); 1764 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, NULL); 1614 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 1615 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, false); 1616 } 1617 1618 // the user supplies one of various stats option pairs, 1619 // determine the desired mean and stdev STATS options: 1620 // XXX enforce consistency? 1621 // XXX psStatsGetValue() probably has inverted precedence 1622 psStatsOptions meanOption = stats->options & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN | PS_STAT_FITTED_MEAN_V2); 1623 psStatsOptions stdevOption = stats->options & (PS_STAT_SAMPLE_STDEV | PS_STAT_ROBUST_STDEV | PS_STAT_CLIPPED_STDEV | PS_STAT_FITTED_STDEV | PS_STAT_FITTED_STDEV_V2); 1624 if (!meanOption) { 1625 psError(PS_ERR_UNKNOWN, true, "no valid mean stats option selected"); 1626 return false; 1627 } 1628 if (!stdevOption) { 1629 psError(PS_ERR_UNKNOWN, true, "no valid stdev stats option selected"); 1630 return false; 1765 1631 } 1766 1632 … … 1778 1644 minClipSigma = fabs(stats->clipSigma); 1779 1645 } 1780 psVector *fit = NULL;1781 1646 psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64); 1782 1647 1783 // eventual expansion: user supplies one of various stats option pairs,1784 // eg (SAMPLE_MEAN | SAMPLE_STDEV) and the correct pair is used to1785 // evaluate the clipping sigma1786 // for now, for the SAMPLE_MEDIAN and SAMPLE_STDEV to be used1787 stats->options |= (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);1788 stats->options |= (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);1789 1648 psTrace("psLib.math", 4, "stats->clipIter is %d\n", stats->clipIter); 1790 1649 psTrace("psLib.math", 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma); … … 1801 1660 } 1802 1661 1803 poly = psVectorFitPolynomial3D(poly, mask, maskValue, f, fErr, x, y, z); 1804 if (poly == NULL) { 1662 if (!psVectorFitPolynomial3D(poly, mask, maskValue, f, fErr, x, y, z)) { 1805 1663 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data. Returning NULL.\n"); 1806 1664 psFree(resid) 1807 psFree(fit) 1808 return(NULL); 1809 } 1810 fit = psPolynomial3DEvalVector(poly, x, y, z); 1665 return false; 1666 } 1667 psVector *fit = psPolynomial3DEvalVector(poly, x, y, z); 1811 1668 if (fit == NULL) { 1812 1669 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning NULL.\n"); 1813 1670 psFree(resid) 1814 return (NULL);1671 return false; 1815 1672 } 1816 1673 for (psS32 i = 0 ; i < f->n ; i++) { … … 1837 1694 psFree(resid) 1838 1695 psFree(fit) 1839 return(NULL); 1840 } 1841 1842 # if (USE_ROBUST_STATS_FOR_CLIPPING) 1843 psTrace("psLib.math", 5, "Median is %f\n", stats->robustMedian); 1844 psTrace("psLib.math", 5, "Stdev is %f\n", stats->robustStdev); 1845 psF32 minClipValue = -minClipSigma*stats->robustStdev; 1846 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 1847 psF32 clipMedian = stats->robustMedian; 1848 # else 1849 1850 psTrace("psLib.math", 5, "Median is %f\n", stats->sampleMedian); 1851 psTrace("psLib.math", 5, "Stdev is %f\n", stats->sampleStdev); 1852 psF32 minClipValue = -minClipSigma*stats->robustStdev; 1853 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 1854 psF32 clipMedian = stats->sampleMedian; 1855 # endif 1696 return false; 1697 } 1698 1699 double meanValue = psStatsGetValue (stats, meanOption); 1700 double stdevValue = psStatsGetValue (stats, stdevOption); 1701 1702 psTrace("psLib.math", 5, "Mean is %f\n", meanValue); 1703 psTrace("psLib.math", 5, "Stdev is %f\n", stdevValue); 1704 psF32 minClipValue = -minClipSigma*stdevValue; 1705 psF32 maxClipValue = +maxClipSigma*stdevValue; 1856 1706 1857 1707 // set mask if pts are not valid … … 1863 1713 } 1864 1714 1865 if ((resid->data.F64[i] - clipMedian > maxClipValue) || (resid->data.F64[i] - clipMedian< minClipValue)) {1715 if ((resid->data.F64[i] - meanValue > maxClipValue) || (resid->data.F64[i] - meanValue < minClipValue)) { 1866 1716 if (f->type.type == PS_TYPE_F64) { 1867 1717 psTrace("psLib.math", 6, "Masking element %d (%f). resid->data.F64[%d] is %f\n", … … 1879 1729 Nkeep++; 1880 1730 } 1881 1882 1731 psTrace("psLib.math", 6, "keeping %d of %ld pts for fit\n", Nkeep, x->n); 1732 stats->clippedNvalues = Nkeep; 1883 1733 psFree(fit); 1884 1734 } … … 1886 1736 psFree(resid); 1887 1737 1888 if (poly == NULL) {1889 psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data. Returning NULL.\n");1890 return(NULL);1891 }1892 1893 1738 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 1894 return (poly);1739 return true; 1895 1740 } 1896 1741 … … 1906 1751 1907 1752 *****************************************************************************/ 1908 static psPolynomial4D*VectorFitPolynomial4DOrd(1753 static bool VectorFitPolynomial4DOrd( 1909 1754 psPolynomial4D* myPoly, 1910 1755 const psVector* mask, … … 1918 1763 { 1919 1764 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 1920 PS_ASSERT_POLY_NON_NULL(myPoly, NULL);1921 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL);1922 PS_ASSERT_INT_NONNEGATIVE(myPoly->nY, NULL);1923 PS_ASSERT_INT_NONNEGATIVE(myPoly->nZ, NULL);1924 PS_ASSERT_INT_NONNEGATIVE(myPoly->nT, NULL);1925 PS_ASSERT_VECTOR_NON_NULL(f, NULL);1926 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, NULL);1765 PS_ASSERT_POLY_NON_NULL(myPoly, false); 1766 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, false); 1767 PS_ASSERT_INT_NONNEGATIVE(myPoly->nY, false); 1768 PS_ASSERT_INT_NONNEGATIVE(myPoly->nZ, false); 1769 PS_ASSERT_INT_NONNEGATIVE(myPoly->nT, false); 1770 PS_ASSERT_VECTOR_NON_NULL(f, false); 1771 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F64, false); 1927 1772 if (fErr != NULL) { 1928 PS_ASSERT_VECTORS_SIZE_EQUAL(y, fErr, NULL);1929 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, NULL);1930 } 1931 PS_ASSERT_VECTOR_NON_NULL(x, NULL);1932 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);1933 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);1934 PS_ASSERT_VECTOR_NON_NULL(y, NULL);1935 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);1936 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);1937 PS_ASSERT_VECTOR_NON_NULL(z, NULL);1938 PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);1939 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL);1940 PS_ASSERT_VECTOR_NON_NULL(t, NULL);1941 PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F64, NULL);1942 PS_ASSERT_VECTORS_SIZE_EQUAL(f, t, NULL);1773 PS_ASSERT_VECTORS_SIZE_EQUAL(y, fErr, false); 1774 PS_ASSERT_VECTOR_TYPE(fErr, PS_TYPE_F64, false); 1775 } 1776 PS_ASSERT_VECTOR_NON_NULL(x, false); 1777 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, false); 1778 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 1779 PS_ASSERT_VECTOR_NON_NULL(y, false); 1780 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, false); 1781 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 1782 PS_ASSERT_VECTOR_NON_NULL(z, false); 1783 PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, false); 1784 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, false); 1785 PS_ASSERT_VECTOR_NON_NULL(t, false); 1786 PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F64, false); 1787 PS_ASSERT_VECTORS_SIZE_EQUAL(f, t, false); 1943 1788 if (mask) { 1944 PS_ASSERT_VECTORS_SIZE_EQUAL(y, mask, NULL);1945 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);1789 PS_ASSERT_VECTORS_SIZE_EQUAL(y, mask, false); 1790 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 1946 1791 } 1947 1792 … … 1959 1804 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 1960 1805 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 1961 psFree(myPoly);1962 1806 psFree(A); 1963 1807 psFree(B); 1964 1808 psTrace("psLib.math", 4, "---- %s() End ----\n", __func__); 1965 return (NULL);1809 return false; 1966 1810 } 1967 1811 … … 2051 1895 // The GaussJordan version was overflowing, so I'm using LUD. 2052 1896 if (!psMatrixGJSolve(A, B)) { 2053 psFree(A);2054 psFree(B);2055 1897 psError(PS_ERR_UNKNOWN, false, "Failed to perform GaussJordan elimination.\n"); 2056 return(NULL);1898 goto escape_GJ; 2057 1899 } 2058 1900 … … 2076 1918 if (ALUD == NULL) { 2077 1919 psError(PS_ERR_UNKNOWN, false, "Could not do LUD decomposition on matrix. Returning NULL.\n"); 2078 psFree(myPoly); 2079 myPoly = NULL; 1920 goto escape_LUD; 2080 1921 } else { 2081 1922 coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm); 2082 1923 if (coeffs == NULL) { 2083 1924 psError(PS_ERR_UNKNOWN, false, "Could not solve LUD matrix. Returning NULL.\n"); 2084 psFree(myPoly); 2085 myPoly = NULL; 1925 goto escape_LUD; 2086 1926 } else { 2087 1927 // select the appropriate solution entries … … 2100 1940 } 2101 1941 } 2102 2103 1942 psFree(ALUD); 2104 1943 psFree(coeffs); 2105 1944 psFree(outPerm); 2106 2107 } 2108 1945 } 2109 1946 psFree(A); 2110 1947 psFree(B); 2111 1948 2112 1949 psTrace("psLib.math", 4, "---- %s() end ----\n", __func__); 2113 return (myPoly); 1950 return true; 1951 1952 escape_LUD: 1953 psFree(A); 1954 psFree(B); 1955 return false; 1956 1957 escape_GJ: 1958 psFree(A); 1959 psFree(B); 1960 return false; 2114 1961 } 2115 1962 … … 2120 1967 via vector conversion only. 2121 1968 *****************************************************************************/ 2122 psPolynomial4D *psVectorFitPolynomial4D(1969 bool psVectorFitPolynomial4D( 2123 1970 psPolynomial4D *poly, 2124 1971 const psVector *mask, … … 2131 1978 const psVector *t) 2132 1979 { 2133 // Internal pointers for possibly NULL or mis-typed vectors. 2134 psVector *x64 = NULL; 2135 psVector *y64 = NULL; 2136 psVector *z64 = NULL; 2137 psVector *t64 = NULL; 2138 psVector *f64 = NULL; 1980 PS_ASSERT_POLY_NON_NULL(poly, false); 1981 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, false); 1982 1983 PS_ASSERT_VECTOR_NON_NULL(f, false); 1984 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 1985 PS_ASSERT_VECTOR_NON_NULL(x, false); 1986 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 1987 PS_ASSERT_VECTOR_NON_NULL(y, false); 1988 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 1989 PS_ASSERT_VECTOR_NON_NULL(z, false); 1990 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, false); 1991 PS_ASSERT_VECTOR_NON_NULL(t, false); 1992 PS_ASSERT_VECTORS_SIZE_EQUAL(f, t, false); 1993 if (mask) { 1994 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 1995 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 1996 } 1997 if (fErr != NULL) { 1998 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 1999 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, false); 2000 } 2001 2002 // Convert input vectors to F64 if necessary. 2003 psVector *f64 = (f->type.type == PS_TYPE_F64) ? (psVector *) f : psVectorCopy(NULL, f, PS_TYPE_F64); 2004 psVector *x64 = (x->type.type == PS_TYPE_F64) ? (psVector *) x : psVectorCopy(NULL, x, PS_TYPE_F64); 2005 psVector *y64 = (y->type.type == PS_TYPE_F64) ? (psVector *) y : psVectorCopy(NULL, y, PS_TYPE_F64); 2006 psVector *z64 = (z->type.type == PS_TYPE_F64) ? (psVector *) z : psVectorCopy(NULL, z, PS_TYPE_F64); 2007 psVector *t64 = (t->type.type == PS_TYPE_F64) ? (psVector *) t : psVectorCopy(NULL, t, PS_TYPE_F64); 2008 2139 2009 psVector *fErr64 = NULL; 2140 2141 PS_ASSERT_POLY_NON_NULL(poly, NULL);2142 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, NULL);2143 2144 PS_ASSERT_VECTOR_NON_NULL(f, NULL);2145 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);2146 if (mask) {2147 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);2148 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);2149 }2150 PS_ASSERT_VECTOR_NON_NULL(x, NULL);2151 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);2152 PS_ASSERT_VECTOR_NON_NULL(y, NULL);2153 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);2154 PS_ASSERT_VECTOR_NON_NULL(z, NULL);2155 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL);2156 PS_ASSERT_VECTOR_NON_NULL(t, NULL);2157 PS_ASSERT_VECTORS_SIZE_EQUAL(f, t, NULL);2158 2010 if (fErr != NULL) { 2159 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); 2160 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, NULL); 2161 } 2162 2163 2164 // 2165 // Convert input vector to F64 if necessary. 2166 // 2167 if (f->type.type != PS_TYPE_F64) { 2168 f64 = psVectorCopy(NULL, f, PS_TYPE_F64); 2169 } else { 2170 f64 = (psVector *) f; 2171 } 2172 if (x->type.type != PS_TYPE_F64) { 2173 x64 = psVectorCopy(NULL, x, PS_TYPE_F64); 2174 } else { 2175 x64 = (psVector *) x; 2176 } 2177 if (y->type.type != PS_TYPE_F64) { 2178 y64 = psVectorCopy(NULL, y, PS_TYPE_F64); 2179 } else { 2180 y64 = (psVector *) y; 2181 } 2182 if (z->type.type != PS_TYPE_F64) { 2183 z64 = psVectorCopy(NULL, z, PS_TYPE_F64); 2184 } else { 2185 z64 = (psVector *) z; 2186 } 2187 if (t->type.type != PS_TYPE_F64) { 2188 t64 = psVectorCopy(NULL, t, PS_TYPE_F64); 2189 } else { 2190 t64 = (psVector *) t; 2191 } 2192 // 2193 // fErr 2194 // 2195 if (fErr != NULL) { 2196 if (fErr->type.type != PS_TYPE_F64) { 2197 fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64); 2198 } else { 2199 fErr64 = (psVector *) fErr; 2200 } 2201 } 2202 2203 if (poly->type == PS_POLYNOMIAL_ORD) { 2204 poly = VectorFitPolynomial4DOrd(poly, mask, maskValue, f64, fErr64, x64, y64, z64, t64); 2205 if (poly == NULL) { 2011 fErr64 = (fErr->type.type == PS_TYPE_F64) ? (psVector *) fErr : psVectorCopy(NULL, fErr, PS_TYPE_F64); 2012 } 2013 2014 bool result = true; 2015 2016 switch (poly->type) { 2017 case PS_POLYNOMIAL_ORD: 2018 result = VectorFitPolynomial4DOrd(poly, mask, maskValue, f64, fErr64, x64, y64, z64, t64); 2019 if (!result) { 2206 2020 psError(PS_ERR_UNKNOWN, true, "Could not fit polynomial. Returning NULL.\n"); 2207 // Free psVectors that were created for NULL arguments. 2208 if (f->type.type != PS_TYPE_F64) { 2209 psFree(f64); 2210 } 2211 2212 if (x->type.type != PS_TYPE_F64) { 2213 psFree(x64); 2214 } 2215 2216 if (y->type.type != PS_TYPE_F64) { 2217 psFree(y64); 2218 } 2219 2220 if (z->type.type != PS_TYPE_F64) { 2221 psFree(z64); 2222 } 2223 2224 if (t->type.type != PS_TYPE_F64) { 2225 psFree(t64); 2226 } 2227 2228 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 2229 psFree(fErr64); 2230 } 2231 return(NULL); 2232 } 2233 } else if (poly->type == PS_POLYNOMIAL_CHEB) { 2021 } 2022 break; 2023 case PS_POLYNOMIAL_CHEB: 2234 2024 if (mask != NULL) { 2235 2025 psLogMsg(__func__, PS_LOG_WARN, "WARNING: ignoring mask and maskValue with Chebyshev polynomials.\n"); 2236 2026 } 2237 psLogMsg(__func__, PS_LOG_WARN, "WARNING: 4-D Chebyshev polynomial vector fitting has not been implemented. Returning NULL.\n"); 2238 psFree(poly); 2239 poly = NULL; 2240 } else { 2241 // Free psVectors that were created for NULL arguments. 2242 if (f->type.type != PS_TYPE_F64) { 2243 psFree(f64); 2244 } 2245 2246 if (x->type.type != PS_TYPE_F64) { 2247 psFree(x64); 2248 } 2249 2250 if (y->type.type != PS_TYPE_F64) { 2251 psFree(y64); 2252 } 2253 2254 if (z->type.type != PS_TYPE_F64) { 2255 psFree(z64); 2256 } 2257 2258 if (t->type.type != PS_TYPE_F64) { 2259 psFree(t64); 2260 } 2261 2262 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 2263 psFree(fErr64); 2264 } 2027 psError(PS_ERR_UNKNOWN, true, "4-D Chebyshev polynomial vector fitting has not been implemented. Returning NULL.\n"); 2028 result = false; 2029 break; 2030 default: 2265 2031 psError(PS_ERR_UNKNOWN, true, "Incorrect polynomial type. Returning NULL.\n"); 2266 } 2267 2032 result = false; 2033 break; 2034 } 2268 2035 2269 2036 // Free psVectors that were created for NULL arguments. 2270 if (f->type.type != PS_TYPE_F64) { 2271 psFree(f64); 2272 } 2273 2274 if (x->type.type != PS_TYPE_F64) { 2275 psFree(x64); 2276 } 2277 2278 if (y->type.type != PS_TYPE_F64) { 2279 psFree(y64); 2280 } 2281 2282 if (z->type.type != PS_TYPE_F64) { 2283 psFree(z64); 2284 } 2285 2286 if (t->type.type != PS_TYPE_F64) { 2287 psFree(t64); 2288 } 2289 2290 if ((fErr != NULL) && (fErr->type.type != PS_TYPE_F64)) { 2291 psFree(fErr64); 2292 } 2293 2294 return(poly); 2037 PS_FREE_TEMP_F64_VECTOR (f, f64); 2038 PS_FREE_TEMP_F64_VECTOR (x, x64); 2039 PS_FREE_TEMP_F64_VECTOR (y, y64); 2040 PS_FREE_TEMP_F64_VECTOR (z, z64); 2041 PS_FREE_TEMP_F64_VECTOR (t, t64); 2042 PS_FREE_TEMP_F64_VECTOR (fErr, fErr64); 2043 2044 return result; 2295 2045 } 2296 2046 2297 2047 2298 psPolynomial4D *psVectorClipFitPolynomial4D(2048 bool psVectorClipFitPolynomial4D( 2299 2049 psPolynomial4D *poly, 2300 2050 psStats *stats, … … 2309 2059 { 2310 2060 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 2311 PS_ASSERT_POLY_NON_NULL(poly, NULL);2312 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, NULL);2313 PS_ASSERT_PTR_NON_NULL(stats, NULL);2314 PS_ASSERT_VECTOR_NON_NULL(mask, NULL);2315 PS_ASSERT_VECTOR_NON_NULL(f, NULL);2316 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);2317 if (mask) { 2318 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);2319 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);2320 }2321 PS_ASSERT_VECTOR_NON_NULL(x, NULL); 2322 PS_ASSERT_VECTOR S_SIZE_EQUAL(f, x, NULL);2323 PS_ASSERT_VECTOR _TYPE(x, f->type.type, NULL);2324 2325 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 2326 PS_ASSERT_VECTOR S_SIZE_EQUAL(f, y, NULL);2327 PS_ASSERT_VECTOR _TYPE(y, f->type.type, NULL);2328 2329 PS_ASSERT_VECTOR_NON_NULL(z, NULL); 2330 PS_ASSERT_VECTOR S_SIZE_EQUAL(f, z, NULL);2331 PS_ASSERT_VECTOR _TYPE(z, f->type.type, NULL);2332 2333 PS_ASSERT_VECTOR_NON_NULL(t, NULL); 2334 PS_ASSERT_VECTORS_SIZE_EQUAL(f, t, NULL);2335 PS_ASSERT_VECTOR_TYPE( t, f->type.type, NULL);2061 PS_ASSERT_POLY_NON_NULL(poly, false); 2062 PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, false); 2063 PS_ASSERT_PTR_NON_NULL(stats, false); 2064 PS_ASSERT_VECTOR_NON_NULL(mask, false); 2065 PS_ASSERT_VECTOR_NON_NULL(f, false); 2066 PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, false); 2067 2068 PS_ASSERT_VECTOR_NON_NULL(x, false); 2069 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, false); 2070 PS_ASSERT_VECTOR_TYPE(x, f->type.type, false); 2071 2072 PS_ASSERT_VECTOR_NON_NULL(y, false); 2073 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, false); 2074 PS_ASSERT_VECTOR_TYPE(y, f->type.type, false); 2075 2076 PS_ASSERT_VECTOR_NON_NULL(z, false); 2077 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, false); 2078 PS_ASSERT_VECTOR_TYPE(z, f->type.type, false); 2079 2080 PS_ASSERT_VECTOR_NON_NULL(t, false); 2081 PS_ASSERT_VECTORS_SIZE_EQUAL(f, t, false); 2082 PS_ASSERT_VECTOR_TYPE(t, f->type.type, false); 2083 2084 PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, false); 2085 PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false); 2336 2086 2337 2087 if (fErr != NULL) { 2338 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); 2339 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, NULL); 2088 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, false); 2089 PS_ASSERT_VECTOR_TYPE(fErr, f->type.type, false); 2090 } 2091 2092 // the user supplies one of various stats option pairs, 2093 // determine the desired mean and stdev STATS options: 2094 // XXX enforce consistency? 2095 // XXX psStatsGetValue() probably has inverted precedence 2096 psStatsOptions meanOption = stats->options & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN | PS_STAT_FITTED_MEAN_V2); 2097 psStatsOptions stdevOption = stats->options & (PS_STAT_SAMPLE_STDEV | PS_STAT_ROBUST_STDEV | PS_STAT_CLIPPED_STDEV | PS_STAT_FITTED_STDEV | PS_STAT_FITTED_STDEV_V2); 2098 if (!meanOption) { 2099 psError(PS_ERR_UNKNOWN, true, "no valid mean stats option selected"); 2100 return false; 2101 } 2102 if (!stdevOption) { 2103 psError(PS_ERR_UNKNOWN, true, "no valid stdev stats option selected"); 2104 return false; 2340 2105 } 2341 2106 … … 2353 2118 minClipSigma = fabs(stats->clipSigma); 2354 2119 } 2355 psVector *fit = NULL;2356 2120 psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64); 2357 2121 2358 // eventual expansion: user supplies one of various stats option pairs,2359 // eg (SAMPLE_MEAN | SAMPLE_STDEV) and the correct pair is used to2360 // evaluate the clipping sigma2361 // for now, for the SAMPLE_MEDIAN and SAMPLE_STDEV to be used2362 stats->options |= (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);2363 stats->options |= (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);2364 2122 psTrace("psLib.math", 4, "stats->clipIter is %d\n", stats->clipIter); 2365 2123 psTrace("psLib.math", 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma); … … 2376 2134 } 2377 2135 2378 poly = psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t); 2379 if (poly == NULL) { 2136 if (!psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t)) { 2380 2137 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data. Returning NULL.\n"); 2381 2138 psFree(resid) 2382 psFree(fit) 2383 return(NULL); 2384 } 2385 2386 fit = psPolynomial4DEvalVector (poly, x, y, z, t); 2139 return false; 2140 } 2141 2142 psVector *fit = psPolynomial4DEvalVector (poly, x, y, z, t); 2387 2143 if (fit == NULL) { 2388 2144 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial4DEvalVector(). Returning NULL.\n"); 2389 2145 psFree(resid) 2390 return (NULL);2146 return false; 2391 2147 } 2392 2148 for (psS32 i = 0 ; i < f->n ; i++) { … … 2413 2169 psFree(resid) 2414 2170 psFree(fit) 2415 return(NULL); 2416 } 2417 # if (USE_ROBUST_STATS_FOR_CLIPPING) 2418 psTrace("psLib.math", 5, "Median is %f\n", stats->robustMedian); 2419 psTrace("psLib.math", 5, "Stdev is %f\n", stats->robustStdev); 2420 psF32 minClipValue = -minClipSigma*stats->robustStdev; 2421 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 2422 psF32 clipMedian = stats->robustMedian; 2423 # else 2424 2425 psTrace("psLib.math", 5, "Median is %f\n", stats->sampleMedian); 2426 psTrace("psLib.math", 5, "Stdev is %f\n", stats->sampleStdev); 2427 psF32 minClipValue = -minClipSigma*stats->robustStdev; 2428 psF32 maxClipValue = +maxClipSigma*stats->robustStdev; 2429 psF32 clipMedian = stats->sampleMedian; 2430 # endif 2171 return false; 2172 } 2173 2174 double meanValue = psStatsGetValue (stats, meanOption); 2175 double stdevValue = psStatsGetValue (stats, stdevOption); 2176 2177 psTrace("psLib.math", 5, "Mean is %f\n", meanValue); 2178 psTrace("psLib.math", 5, "Stdev is %f\n", stdevValue); 2179 psF32 minClipValue = -minClipSigma*stdevValue; 2180 psF32 maxClipValue = +maxClipSigma*stdevValue; 2431 2181 2432 2182 // set mask if pts are not valid … … 2438 2188 } 2439 2189 2440 if ((resid->data.F64[i] - clipMedian > maxClipValue) || (resid->data.F64[i] - clipMedian< minClipValue)) {2190 if ((resid->data.F64[i] - meanValue > maxClipValue) || (resid->data.F64[i] - meanValue < minClipValue)) { 2441 2191 if (f->type.type == PS_TYPE_F64) { 2442 2192 psTrace("psLib.math", 6, "Masking element %d (%f). resid->data.F64[%d] is %f\n", … … 2452 2202 continue; 2453 2203 } 2454 2455 2204 Nkeep++; 2456 2205 } 2457 2458 2206 psTrace("psLib.math", 6, "keeping %d of %ld pts for fit\n", Nkeep, x->n); 2207 stats->clippedNvalues = Nkeep; 2459 2208 psFree (fit); 2460 2209 } … … 2462 2211 psFree (resid); 2463 2212 2464 if (poly == NULL) {2465 psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data. Returning NULL.\n");2466 return(NULL);2467 }2468 2469 2213 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 2470 return (poly);2214 return true; 2471 2215 } -
trunk/psLib/src/math/psMinimizePolyFit.h
r6185 r10848 10 10 * XXX: Must Doxygenate. 11 11 * 12 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $13 * @date $Date: 2006- 01-23 20:44:29$12 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-12-29 04:38:42 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 54 54 */ 55 55 56 psPolynomial1D *psVectorFitPolynomial1D(56 bool psVectorFitPolynomial1D( 57 57 psPolynomial1D *poly, 58 58 const psVector *mask, … … 63 63 ); 64 64 65 psPolynomial2D *psVectorFitPolynomial2D(65 bool psVectorFitPolynomial2D( 66 66 psPolynomial2D *poly, 67 67 const psVector *mask, … … 73 73 ); 74 74 75 psPolynomial3D *psVectorFitPolynomial3D(75 bool psVectorFitPolynomial3D( 76 76 psPolynomial3D *poly, 77 77 const psVector *mask, … … 84 84 ); 85 85 86 psPolynomial4D *psVectorFitPolynomial4D(86 bool psVectorFitPolynomial4D( 87 87 psPolynomial4D *poly, 88 88 const psVector *mask, … … 97 97 98 98 99 psPolynomial1D *psVectorClipFitPolynomial1D(99 bool psVectorClipFitPolynomial1D( 100 100 psPolynomial1D *poly, 101 101 psStats *stats, … … 107 107 ); 108 108 109 psPolynomial2D *psVectorClipFitPolynomial2D(109 bool psVectorClipFitPolynomial2D( 110 110 psPolynomial2D *poly, 111 111 psStats *stats, … … 118 118 ); 119 119 120 psPolynomial3D *psVectorClipFitPolynomial3D(120 bool psVectorClipFitPolynomial3D( 121 121 psPolynomial3D *poly, 122 122 psStats *stats, … … 130 130 ); 131 131 132 psPolynomial4D *psVectorClipFitPolynomial4D(132 bool psVectorClipFitPolynomial4D( 133 133 psPolynomial4D *poly, 134 134 psStats *stats, -
trunk/psLib/src/math/psPolynomial.c
r10608 r10848 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.15 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-12- 10 17:28:46$9 * @version $Revision: 1.156 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-12-29 04:38:42 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 581 581 unsigned int nX) 582 582 { 583 //PS_ASSERT_INT_NONNEGATIVE(n, NULL); 583 PS_ASSERT_POLY_VALID_TYPE(type, NULL); 584 584 585 psU32 nOrder = nX; 585 586 psPolynomial1D *newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D)); … … 605 606 unsigned int nY) 606 607 { 607 //PS_ASSERT_INT_NONNEGATIVE(nX, NULL); 608 //PS_ASSERT_INT_NONNEGATIVE(nY, NULL); 608 PS_ASSERT_POLY_VALID_TYPE(type, NULL); 609 609 610 610 unsigned int x = 0; … … 711 711 unsigned int nZ) 712 712 { 713 PS_ASSERT_POLY_VALID_TYPE(type, NULL); 714 713 715 //PS_ASSERT_INT_NONNEGATIVE(nX, NULL); 714 716 //PS_ASSERT_INT_NONNEGATIVE(nY, NULL); … … 761 763 unsigned int nT) 762 764 { 765 PS_ASSERT_POLY_VALID_TYPE(type, NULL); 766 763 767 //PS_ASSERT_INT_NONNEGATIVE(nX, NULL); 764 768 //PS_ASSERT_INT_NONNEGATIVE(nY, NULL); -
trunk/psLib/src/math/psPolynomial.h
r10598 r10848 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1.6 5$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-12- 09 14:19:56$13 * @version $Revision: 1.66 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-12-29 04:38:42 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 329 329 } \ 330 330 331 #define PS_ASSERT_POLY_VALID_TYPE(TYPE, RVAL) \ 332 if ((TYPE != PS_POLYNOMIAL_ORD) && \ 333 (TYPE != PS_POLYNOMIAL_CHEB)) { \ 334 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 335 "Unallowable operation: invalid type %d for polynomial", TYPE); \ 336 return(RVAL); \ 337 } \ 338 331 339 #define PS_POLY_PRINT_1D(NAME) \ 332 340 printf("Poly %s: (nX) is (%d)\n", #NAME, NAME->nX);\ -
trunk/psLib/src/math/psPolynomialUtils.c
r10607 r10848 13 13 #include "psPolynomialUtils.h" 14 14 15 psPolynomial4D *psVectorChiClipFitPolynomial4D(15 bool psVectorChiClipFitPolynomial4D( 16 16 psPolynomial4D *poly, 17 17 psStats *stats, … … 75 75 int Nkeep = 0; 76 76 77 poly = psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t); 77 if (!psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t)) { 78 psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data. Returning NULL.\n"); 79 psFree (resid); 80 return false; 81 } 82 78 83 fit = psPolynomial4DEvalVector (poly, x, y, z, t); 84 if (fit == NULL) { 85 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial4DEvalVector(). Returning NULL.\n"); 86 psFree(resid) 87 return false; 88 } 89 79 90 resid = (psVector *) psBinaryOp (resid, (void *) f, "-", (void *) fit); 80 91 81 92 if (!psVectorStats (stats, resid, NULL, mask, maskValue)) { 82 93 psError(PS_ERR_UNKNOWN, false, "failed to measure vector stats"); 83 return NULL; 94 psFree (fit); 95 psFree (resid); 96 return false; 84 97 } 85 98 psTrace (__func__, 5, "resid stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev); … … 108 121 } 109 122 110 psTrace (__func__, 4, "keeping %d of %ld pts for fit\n", 111 Nkeep, x->n); 112 123 psTrace (__func__, 4, "keeping %d of %ld pts for fit\n", Nkeep, x->n); 113 124 stats->clippedNvalues = Nkeep; 114 125 psFree (fit); … … 117 128 psFree (resid); 118 129 119 if (poly == NULL) { 120 psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data. Returning NULL.\n"); 121 return(NULL); 122 } 123 return(poly); 130 return true; 124 131 } 125 132 -
trunk/psLib/src/math/psPolynomialUtils.h
r10598 r10848 14 14 15 15 // perform vector clip-fit based on significance of deviations 16 psPolynomial4D *psVectorChiClipFitPolynomial4D(16 bool psVectorChiClipFitPolynomial4D( 17 17 psPolynomial4D *poly, // Polynomial to fit 18 18 psStats *stats, // Statistics to use in clipping -
trunk/psLib/src/math/psStats.c
r10773 r10848 13 13 * use ->min and ->max (PS_STAT_USE_RANGE) 14 14 * 15 * @version $Revision: 1.19 6$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-12- 16 05:33:48$15 * @version $Revision: 1.197 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-12-29 04:38:42 $ 17 17 * 18 18 * Copyright 2006 IfA, University of Hawaii … … 1856 1856 // Determine the coefficients of the polynomial. 1857 1857 psPolynomial1D *myPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2); 1858 myPoly = psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x); 1859 if (myPoly == NULL) { 1858 if (!psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x)) { 1860 1859 psError(PS_ERR_UNEXPECTED_NULL, false, 1861 1860 _("Failed to fit a 1-dimensional polynomial to the three specified data points. Returning NAN.")); -
trunk/psLib/test/math
- Property svn:ignore
-
old new 4 4 Makefile 5 5 Makefile.in 6 tst_psFunc017 tst_psHist008 tst_psHist019 tst_psHist0210 tst_psHist0311 tst_psMatrix0112 tst_psMatrix0213 tst_psMatrix0314 tst_psMatrix0415 tst_psMatrix0516 tst_psMatrix0617 tst_psMatrix0718 tst_psMatrixVectorArithmetic0119 tst_psMatrixVectorArithmetic0220 tst_psMatrixVectorArithmetic0321 tst_psMatrixVectorArithmetic0422 tst_psRandom23 tst_psStats0024 tst_psStats0125 tst_psStats0226 tst_psStats0327 tst_psStats0528 tst_psStats0629 tst_psStats0730 tst_psStats0831 tst_psStats0932 6 seed_msglog1.txt 33 7 seed_msglog2.txt 34 tst_psSpline1D35 tst_psMathUtils36 tst_psMinimizeLMM37 tst_psMinimizePowell38 tst_psPolyFit1D39 tst_psPolyFit2D40 tst_psPolyFit3D41 tst_psPolyFit4D42 tst_psPolynomial43 tst_psPolynomialEval1D44 tst_psPolynomialEval2D45 tst_psPolynomialEval3D46 tst_psPolynomialEval4D47 8 *.bb 48 9 *.bbg 49 10 *.da 50 11 gmon.out 12 tap_psHist00 13 tap_psHist01 14 tap_psHist02 15 tap_psHist03 16 tap_psMD5 17 tap_psMatrix01 18 tap_psMatrix02 19 tap_psMatrix03 20 tap_psMatrix04 21 tap_psMatrix05 22 tap_psMatrix06 23 tap_psMatrix07 24 tap_psPolyFit1D 25 tap_psPolyFit2D 26 tap_psPolyFit3D 27 tap_psPolyFit4D 28 tap_psPolynomial 29 tap_psPolynomialEval1D 30 tap_psPolynomialEval2D 31 tap_psPolynomialEval3D 32 tap_psPolynomialEval4D 33 tap_psPolynomialUtils_Derivatives 51 34 tap_psSparse 35 tap_psStats00 36 tap_psStats01 37 tap_psStats02 38 tap_psStats03 39 tap_psStats05 40 tap_psStats06 41 tap_psStats07 42 tap_psStats08 43 tap_psStats09 52 44 tap_psStatsTiming 53 tap_psMD554 45 tap_psStats_Sample_01 55 tap_psPolynomialUtils_Derivatives
-
- Property svn:ignore
-
trunk/psLib/test/math/.cvsignore
r10597 r10848 4 4 Makefile 5 5 Makefile.in 6 tst_psFunc017 tst_psHist008 tst_psHist019 tst_psHist0210 tst_psHist0311 tst_psMatrix0112 tst_psMatrix0213 tst_psMatrix0314 tst_psMatrix0415 tst_psMatrix0516 tst_psMatrix0617 tst_psMatrix0718 tst_psMatrixVectorArithmetic0119 tst_psMatrixVectorArithmetic0220 tst_psMatrixVectorArithmetic0321 tst_psMatrixVectorArithmetic0422 tst_psRandom23 tst_psStats0024 tst_psStats0125 tst_psStats0226 tst_psStats0327 tst_psStats0528 tst_psStats0629 tst_psStats0730 tst_psStats0831 tst_psStats0932 6 seed_msglog1.txt 33 7 seed_msglog2.txt 34 tst_psSpline1D35 tst_psMathUtils36 tst_psMinimizeLMM37 tst_psMinimizePowell38 tst_psPolyFit1D39 tst_psPolyFit2D40 tst_psPolyFit3D41 tst_psPolyFit4D42 tst_psPolynomial43 tst_psPolynomialEval1D44 tst_psPolynomialEval2D45 tst_psPolynomialEval3D46 tst_psPolynomialEval4D47 8 *.bb 48 9 *.bbg 49 10 *.da 50 11 gmon.out 12 13 tap_psHist00 14 tap_psHist01 15 tap_psHist02 16 tap_psHist03 17 tap_psMD5 18 tap_psMatrix01 19 tap_psMatrix02 20 tap_psMatrix03 21 tap_psMatrix04 22 tap_psMatrix05 23 tap_psMatrix06 24 tap_psMatrix07 25 tap_psPolyFit1D 26 tap_psPolyFit2D 27 tap_psPolyFit3D 28 tap_psPolyFit4D 29 tap_psPolynomial 30 tap_psPolynomialEval1D 31 tap_psPolynomialEval2D 32 tap_psPolynomialEval3D 33 tap_psPolynomialEval4D 34 tap_psPolynomialUtils_Derivatives 51 35 tap_psSparse 36 tap_psStats00 37 tap_psStats01 38 tap_psStats02 39 tap_psStats03 40 tap_psStats05 41 tap_psStats06 42 tap_psStats07 43 tap_psStats08 44 tap_psStats09 52 45 tap_psStatsTiming 53 tap_psMD554 46 tap_psStats_Sample_01 55 tap_psPolynomialUtils_Derivatives -
trunk/psLib/test/math/Makefile.am
r10597 r10848 13 13 14 14 TEST_PROGS = \ 15 tap_psHist00 \ 16 tap_psHist01 \ 17 tap_psHist02 \ 18 tap_psHist03 \ 15 19 tap_psMD5 \ 20 tap_psMatrix01 \ 21 tap_psMatrix02 \ 22 tap_psMatrix03 \ 23 tap_psMatrix04 \ 24 tap_psMatrix05 \ 25 tap_psMatrix06 \ 26 tap_psMatrix07 \ 27 tap_psPolyFit1D \ 28 tap_psPolyFit2D \ 29 tap_psPolyFit3D \ 30 tap_psPolyFit4D \ 31 tap_psPolynomial \ 32 tap_psPolynomialEval1D \ 33 tap_psPolynomialEval2D \ 34 tap_psPolynomialEval3D \ 35 tap_psPolynomialEval4D \ 36 tap_psPolynomialUtils_Derivatives \ 16 37 tap_psSparse \ 38 tap_psStats00 \ 39 tap_psStats01 \ 40 tap_psStats02 \ 41 tap_psStats03 \ 42 tap_psStats05 \ 43 tap_psStats06 \ 44 tap_psStats07 \ 45 tap_psStats08 \ 46 tap_psStats09 \ 17 47 tap_psStatsTiming \ 18 tap_psStats_Sample_01 \ 19 tap_psPolynomialUtils_Derivatives 48 tap_psStats_Sample_01 20 49 21 50 if BUILD_TESTS … … 29 58 30 59 test: check 60 $(top_srcdir)/test/test.pl -
trunk/psLib/test/math/tap_psPolyFit1D.c
r10820 r10848 272 272 } 273 273 274 psPolynomial1D *rc = NULL;274 bool rc = false; 275 275 if (flags & TS00_CLIP_FIT) { 276 276 rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, f, fErr, x); … … 279 279 } 280 280 281 if ( rc == NULL) {281 if (!rc) { 282 282 if (expectedRC == true) { 283 283 diag("TEST ERROR: the 1D polynomial fitting function returned NULL.\n"); -
trunk/psLib/test/math/tap_psPolyFit2D.c
r10820 r10848 279 279 } 280 280 281 psPolynomial2D *rc = NULL;281 bool rc = false; 282 282 if (flags & TS00_CLIP_FIT) { 283 283 rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y); … … 286 286 } 287 287 288 if ( rc == NULL) {288 if (!rc) { 289 289 if (expectedRC == true) { 290 290 diag("TEST ERROR: the 2D polynomial fitting function returned NULL.\n"); -
trunk/psLib/test/math/tap_psPolyFit3D.c
r10820 r10848 324 324 } 325 325 326 psPolynomial3D *rc = NULL;326 bool rc = false; 327 327 if (flags & TS00_CLIP_FIT) { 328 328 rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z); … … 331 331 } 332 332 333 if ( rc == NULL) {333 if (!rc) { 334 334 if (expectedRC == true) { 335 335 diag("TEST ERROR: the 3D polynomial fitting function returned NULL.\n"); -
trunk/psLib/test/math/tap_psPolyFit4D.c
r10820 r10848 377 377 } 378 378 379 psPolynomial4D *rc = NULL;379 bool rc = false; 380 380 if (flags & TS00_CLIP_FIT) { 381 381 rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t); … … 384 384 } 385 385 386 if ( rc == NULL) {386 if (!rc) { 387 387 if (expectedRC == true) { 388 388 diag("TEST ERROR: the 4D polynomial fitting function returned NULL.\n"); -
trunk/psLib/test/math/tap_psPolynomialEval2D.c
r10820 r10848 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $7 * @date $Date: 2006-12-2 1 20:05:12 $6 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2006-12-29 04:38:42 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 148 148 psMemId id = psMemGetId(); 149 149 psPolynomial2D* polyOrd = psPolynomial2DAlloc(99, TERMS-1, TERMS-1); 150 ok(polyOrd != NULL, "Ordinary polynomial allocation successful");151 skip_start(polyOrd == NULL, 2, "Skipping tests because psPolynomial2DAlloc() failed");150 ok(polyOrd == NULL, "Ordinary polynomial allocation successful"); 151 skip_start(polyOrd == NULL, 1, "Skipping tests because psPolynomial2DAlloc() failed"); 152 152 153 153 // Attempt to evaluation invalid polynomial type -
trunk/psLib/test/math/tap_psPolynomialEval3D.c
r10820 r10848 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $7 * @date $Date: 2006-12-2 1 20:05:12 $6 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2006-12-29 04:38:42 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 207 207 psMemId id = psMemGetId(); 208 208 psPolynomial3D* polyOrd = psPolynomial3DAlloc(99, TERMS-1, TERMS-1, TERMS-1); 209 ok(polyOrd != NULL, "Ordinary polynomial allocation successful");210 skip_start(polyOrd == NULL, 2, "Skipping tests because psPolynomial3DAlloc() failed");209 ok(polyOrd == NULL, "Ordinary polynomial allocation successful"); 210 skip_start(polyOrd == NULL, 1, "Skipping tests because psPolynomial3DAlloc() failed"); 211 211 212 212 // Attempt to evaluation invalid polynomial type -
trunk/psLib/test/math/tap_psPolynomialEval4D.c
r10820 r10848 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $7 * @date $Date: 2006-12-2 1 20:05:12 $6 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2006-12-29 04:38:42 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 448 448 psMemId id = psMemGetId(); 449 449 psPolynomial4D* polyOrd = psPolynomial4DAlloc(99, TERMS-1, TERMS-1, TERMS-1, TERMS-1); 450 ok(polyOrd != NULL, "Ordinary polynomial allocation successful");451 skip_start(polyOrd == NULL, 2, "Skipping tests because psPolynomial4DAlloc() failed");450 ok(polyOrd == NULL, "Ordinary polynomial allocation successful"); 451 skip_start(polyOrd == NULL, 1, "Skipping tests because psPolynomial4DAlloc() failed"); 452 452 453 453 // Attempt to evaluation invalid polynomial type -
trunk/psLib/test/math/tap_psPolynomialUtils_Derivatives.c
r10605 r10848 8 8 int main (void) 9 9 { 10 plan_tests( 72);11 12 diag("psPolynomial2D Derivative tests");10 plan_tests(54); 11 12 note("psPolynomial2D Derivative tests"); 13 13 14 14 // test psPolynomial2D_dX (no supplied output) … … 16 16 psMemId id = psMemGetId(); 17 17 18 diag("test psPolynomial2D_dX (no supplied output)");18 note ("test psPolynomial2D_dX (no supplied output)"); 19 19 20 20 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); … … 64 64 psMemId id = psMemGetId(); 65 65 66 diag("test psPolynomial2D_dX (supplied output)");66 note ("test psPolynomial2D_dX (supplied output)"); 67 67 68 68 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); … … 113 113 psMemId id = psMemGetId(); 114 114 115 diag("test psPolynomial2D_dX (supplied output)");115 note ("test psPolynomial2D_dX (supplied output)"); 116 116 117 117 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); … … 134 134 poly->mask[2][2] = 1; 135 135 136 poly = psPolynomial2D_dX (poly, poly); 137 138 ok(poly->nX == 1, "new x order is %d", poly->nX); 139 ok(poly->nY == 2, "new y order is %d", poly->nY); 140 141 ok_float(poly->coeff[0][0], +2.0, "x^0 y^0 coeff is %f", poly->coeff[0][0]); 142 ok_float(poly->coeff[1][0], -6.0, "x^1 y^0 coeff is %f", poly->coeff[1][0]); 143 ok_float(poly->coeff[0][1], +4.0, "x^0 y^1 coeff is %f", poly->coeff[0][1]); 144 145 ok(!poly->mask[0][0], "x^0 y^0 coeff is unmasked"); 146 ok(!poly->mask[1][0], "x^1 y^0 coeff is unmasked"); 147 ok(!poly->mask[0][1], "x^0 y^1 coeff is unmasked"); 148 149 ok(poly->mask[1][1], "x^1 y^1 coeff is masked"); 150 ok(poly->mask[1][2], "x^1 y^2 coeff is masked"); 151 152 psFree (poly); 153 136 psPolynomial2D *result = psPolynomial2D_dX (poly, poly); 137 ok (result == NULL, "psPolynomial2D_dX failed as expected: cannot assign output to input"); 138 139 psFree (poly); 154 140 skip_end(); 155 141 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); … … 160 146 psMemId id = psMemGetId(); 161 147 162 diag("test psPolynomial2D_dY (no supplied output)");148 note ("test psPolynomial2D_dY (no supplied output)"); 163 149 164 150 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); … … 208 194 psMemId id = psMemGetId(); 209 195 210 diag("test psPolynomial2D_dY (supplied output)");196 note ("test psPolynomial2D_dY (supplied output)"); 211 197 212 198 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); … … 257 243 psMemId id = psMemGetId(); 258 244 259 diag("test psPolynomial2D_dY (supplied output)");245 note ("test psPolynomial2D_dY (supplied output)"); 260 246 261 247 psPolynomial2D *poly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2); … … 278 264 poly->mask[2][2] = 1; 279 265 280 poly = psPolynomial2D_dY (poly, poly); 281 282 ok(poly->nX == 2, "new x order is %d", poly->nX); 283 ok(poly->nY == 1, "new y order is %d", poly->nY); 284 285 ok_float(poly->coeff[0][0], +3.0, "x^0 y^0 coeff is %f", poly->coeff[0][0]); 286 ok_float(poly->coeff[1][0], +4.0, "x^1 y^0 coeff is %f", poly->coeff[1][0]); 287 ok_float(poly->coeff[0][1], -4.0, "x^0 y^1 coeff is %f", poly->coeff[0][1]); 288 289 ok(!poly->mask[0][0], "x^0 y^0 coeff is unmasked"); 290 ok(!poly->mask[1][0], "x^1 y^0 coeff is unmasked"); 291 ok(!poly->mask[0][1], "x^0 y^1 coeff is unmasked"); 292 293 ok(poly->mask[1][1], "x^1 y^1 coeff is masked"); 294 ok(poly->mask[1][2], "x^1 y^2 coeff is masked"); 266 psPolynomial2D *result = psPolynomial2D_dY (poly, poly); 267 ok (result == NULL, "psPolynomial2D_dY failed as expected: cannot assign output to input"); 295 268 296 269 psFree (poly); -
trunk/psLib/test/math/tap_psStats00.c
r10831 r10848 1 @file tst_psStats00.c 2 * 3 * @brief Contains tests for psVectorStats with sample mean calculations 4 * 5 * We extensively test the code with data type PS_TYPE_F32. If these pass, we 6 * do 7 a much simpler test with data type PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_F64. 8 * 9 * @author GLG, MHPCC 10 * 11 * @version $Revision: 12 1.8 $ $Name: 13 $ 14 * @date $Date: 15 2006/07/28 00: 16 44: 17 05 $ 18 * 19 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii 20 */ 21 #include <stdio.h> 22 #include <string.h> 23 #include <pslib.h> 24 #include "tap.h" 25 #include "pstap.h" 26 27 #define N 15 28 29 static psF32 samplesF32[N] = 30 { 31 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0, 32 11.01, -12.02, 13.03, 14.04, -15.05 33 }; 1 /** @file tst_psStats00.c 2 * 3 * @brief Contains tests for psVectorStats with sample mean calculations 4 * 5 6 * We extensively test the code with data type PS_TYPE_F32. If these pass, we do a much 7 * simpler test with data type PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_F64. 8 * 9 * @author GLG, MHPCC 10 * 11 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-12-29 04:38:42 $ 13 * 14 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii 15 */ 16 17 #include <stdio.h> 18 #include <string.h> 19 #include <pslib.h> 20 #include "tap.h" 21 #include "pstap.h" 22 23 #define N 15 24 25 static psF32 samplesF32[N] = 26 { 27 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0, 28 11.01, -12.02, 13.03, 14.04, -15.05 29 }; 34 30 static psS8 samplesS8[N] = 35 31 { … … 92 88 { 93 89 psMemId id = psMemGetId(); 94 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 90 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 91 ok(result, "psVectorStats suceeded"); 95 92 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 96 93 ok_float_tol(myStats->sampleMean, expectedMeanNoMaskF32, 1e-4, … … 102 99 { 103 100 psMemId id = psMemGetId(); 104 myStats = psVectorStats(myStats, myVector, myErrors, NULL, 0); 101 bool result = psVectorStats(myStats, myVector, myErrors, NULL, 0); 102 ok(result, "psVectorStats suceeded"); 105 103 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 106 104 ok_float_tol(myStats->sampleMean, expectedWeightMeanNoMaskF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedWeightMeanNoMaskF32); … … 114 112 myStats->min = -10.0; 115 113 myStats->max = 8.0; 116 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 114 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 115 ok(result, "psVectorStats suceeded"); 117 116 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 118 117 ok_float_tol(myStats->sampleMean, expectedMeanRangeNoMaskF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanRangeNoMaskF32); … … 125 124 psMemId id = psMemGetId(); 126 125 myStats->options = PS_STAT_SAMPLE_MEAN | PS_STAT_USE_RANGE; 127 myStats = psVectorStats(myStats, myVector, myErrors, NULL, 0); 126 bool result = psVectorStats(myStats, myVector, myErrors, NULL, 0); 127 ok(result, "psVectorStats suceeded"); 128 128 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 129 129 ok_float_tol(myStats->sampleMean, expectedWeightMeanNoMaskRangeF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedWeightMeanNoMaskRangeF32); … … 135 135 psMemId id = psMemGetId(); 136 136 myStats->options = PS_STAT_SAMPLE_MEAN; 137 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 137 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 138 ok(result, "psVectorStats suceeded"); 138 139 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 139 140 ok_float_tol(myStats->sampleMean, expectedMeanWithMaskF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanWithMaskF32); … … 144 145 { 145 146 psMemId id = psMemGetId(); 146 myStats = psVectorStats(myStats, myVector, myErrors, maskVector, 1); 147 bool result = psVectorStats(myStats, myVector, myErrors, maskVector, 1); 148 ok(result, "psVectorStats suceeded"); 147 149 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 148 150 ok_float_tol(myStats->sampleMean, expectedWeightMeanWithMaskF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedWeightMeanWithMaskF32); … … 154 156 psMemId id = psMemGetId(); 155 157 myStats->options = PS_STAT_SAMPLE_MEAN | PS_STAT_USE_RANGE; 156 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 158 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 159 ok(result, "psVectorStats suceeded"); 157 160 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 158 161 ok_float_tol(myStats->sampleMean, expectedMeanRangeWithMaskF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanRangeWithMaskF32); … … 163 166 { 164 167 psMemId id = psMemGetId(); 165 myStats = psVectorStats(myStats, myVector, myErrors, maskVector, 1); 168 bool result = psVectorStats(myStats, myVector, myErrors, maskVector, 1); 169 ok(result, "psVectorStats suceeded"); 166 170 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 167 171 ok_float_tol(myStats->sampleMean, expectedWeightMeanWithMaskRangeF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedWeightMeanWithMaskRangeF32); … … 178 182 } 179 183 } 180 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 2); 184 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 2); 185 ok(result, "psVectorStats suceeded"); 181 186 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 182 187 ok_float_tol(myStats->sampleMean, expectedMeanWithMaskF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanWithMaskF32); … … 193 198 } 194 199 } 195 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 4); 200 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 4); 201 ok(result, "psVectorStats suceeded"); 196 202 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 197 203 ok_float_tol(myStats->sampleMean, expectedMeanNoMaskF32, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanNoMaskF32); … … 206 212 maskVector->data.U8[i] = 1; 207 213 } 208 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 214 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 215 ok(result, "psVectorStats suceeded"); 209 216 ok(isnan(myStats->sampleMean), "psVectorStats() returned NAN"); 210 217 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); … … 214 221 { 215 222 psMemId id = psMemGetId(); 216 ok(psVectorStats(myStats, NULL, NULL, NULL, 0) == NULL, "psVectorStats() returned NULL with NULL inputs"); 217 ok(psVectorStats(NULL, myVector, NULL, NULL, 0) == NULL, "psVectorStats() returned NULL with NULL inputs"); 218 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 219 } 220 221 222 223 224 225 226 227 228 229 223 ok(!psVectorStats(myStats, NULL, NULL, NULL, 0), "psVectorStats() returned false with NULL inputs"); 224 ok(!psVectorStats(NULL, myVector, NULL, NULL, 0), "psVectorStats() returned false with NULL inputs"); 225 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 226 } 230 227 231 228 psFree(myStats); … … 247 244 } 248 245 249 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 246 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 247 ok(result, "psVectorStats suceeded"); 250 248 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 251 249 ok_float_tol(myStats->sampleMean, expectedMeanNoMaskS8, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanNoMaskS8); … … 267 265 } 268 266 269 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 267 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 268 ok(result, "psVectorStats suceeded"); 270 269 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 271 270 ok_float_tol(myStats->sampleMean, expectedMeanNoMaskU16, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanNoMaskU16); … … 286 285 } 287 286 288 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 287 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 288 ok(result, "psVectorStats suceeded"); 289 289 ok(!isnan(myStats->sampleMean), "psVectorStats() returned non-NAN"); 290 290 ok_float_tol(myStats->sampleMean, expectedMeanNoMaskF64, 1e-4, "The mean was %f, should be %f", myStats->sampleMean, expectedMeanNoMaskF64); -
trunk/psLib/test/math/tap_psStats01.c
r10831 r10848 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-12-2 6 20:33:55$10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-12-29 04:38:42 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 60 60 { 61 61 psMemId id = psMemGetId(); 62 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 62 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 63 ok(result, "psVectorStats suceeded"); 63 64 ok(!isnan(myStats->max), "psVectorStats() returned non-NAN"); 64 65 ok_float_tol(myStats->max, expectedMaxNoMaskF32, 1e-4, … … 70 71 { 71 72 psMemId id = psMemGetId(); 72 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 73 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 74 ok(result, "psVectorStats suceeded"); 73 75 ok(!isnan(myStats->max), "psVectorStats() returned non-NAN"); 74 76 ok_float_tol(myStats->max, expectedMaxWithMaskF32, 1e-4, … … 83 85 myStats->max = 10.2; 84 86 myStats->min = 0.0; 85 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 87 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 88 ok(result, "psVectorStats suceeded"); 86 89 ok(!isnan(myStats->max), "psVectorStats() returned non-NAN"); 87 90 ok_float_tol(myStats->max, expectedMaxRangeNoMaskF32, 1e-4, … … 95 98 myStats->max = 14.0; 96 99 myStats->min = 0.0; 97 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 100 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 101 ok(result, "psVectorStats suceeded"); 98 102 ok(!isnan(myStats->max), "psVectorStats() returned non-NAN"); 99 103 ok_float_tol(myStats->max, expectedMaxRangeWithMaskF32, 1e-4, … … 107 111 myStats->max = 100.00; 108 112 myStats->min = 90.00; 109 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 113 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 114 ok(!result, "psVectorStats failed as expected"); 110 115 ok(isnan(myStats->max), "psVectorStats() returned NAN"); 111 116 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); … … 128 133 } 129 134 130 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 135 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 136 ok(result, "psVectorStats suceeded"); 131 137 ok(!isnan(myStats->max), "psVectorStats() returned non-NAN"); 132 138 ok_float_tol(myStats->max, expectedMaxNoMaskS8, 1e-4, … … 148 154 } 149 155 150 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 156 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 157 ok(result, "psVectorStats suceeded"); 151 158 ok(!isnan(myStats->max), "psVectorStats() returned non-NAN"); 152 159 ok_float_tol(myStats->max, expectedMaxNoMaskU16, 1e-4, … … 168 175 } 169 176 170 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 177 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 178 ok(result, "psVectorStats suceeded"); 171 179 ok(!isnan(myStats->max), "psVectorStats() returned non-NAN"); 172 180 ok_float_tol(myStats->max, expectedMaxNoMaskF64, 1e-4, -
trunk/psLib/test/math/tap_psStats02.c
r10831 r10848 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-12-2 6 20:33:55$13 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-12-29 04:38:42 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 64 64 { 65 65 psMemId id = psMemGetId(); 66 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 66 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 67 ok(result, "psVectorStats suceeded"); 67 68 ok(!isnan(myStats->min), "psVectorStats() returned non-NAN"); 68 69 ok_float_tol(myStats->min, expectedMinNoMaskF32, 1e-4, … … 76 77 { 77 78 psMemId id = psMemGetId(); 78 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 79 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 80 ok(result, "psVectorStats suceeded"); 79 81 ok(!isnan(myStats->min), "psVectorStats() returned non-NAN"); 80 82 ok_float_tol(myStats->min, expectedMinWithMaskF32, 1e-4, … … 89 91 myStats->max = 10.2; 90 92 myStats->min = 0.0; 91 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 93 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 94 ok(result, "psVectorStats suceeded"); 92 95 ok(!isnan(myStats->min), "psVectorStats() returned non-NAN"); 93 96 ok_float_tol(myStats->min, expectedMinRangeNoMaskF32, 1e-4, … … 101 104 myStats->max = 10.1; 102 105 myStats->min = -15.00; 103 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 106 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 107 ok(result, "psVectorStats succeeded"); 104 108 ok(!isnan(myStats->min), "psVectorStats() returned non-NAN"); 105 109 ok_float_tol(myStats->min, expectedMinRangeWithMaskF32, 1e-4, … … 113 117 myStats->max = 100.00; 114 118 myStats->min = 90.00; 115 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 119 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 120 ok(!result, "psVectorStats failed as expected"); 116 121 ok(isnan(myStats->min), "psVectorStats() returned NAN"); 117 122 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); … … 134 139 } 135 140 136 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 141 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 142 ok(result, "psVectorStats succeeded"); 137 143 ok(!isnan(myStats->min), "psVectorStats() returned non-NAN"); 138 144 ok_float_tol(myStats->min, expectedMinNoMaskS8, 1e-4, … … 154 160 } 155 161 156 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 162 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 163 ok(result, "psVectorStats succeeded"); 157 164 ok(!isnan(myStats->min), "psVectorStats() returned non-NAN"); 158 165 ok_float_tol(myStats->min, expectedMinNoMaskU16, 1e-4, … … 174 181 } 175 182 176 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 183 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 184 ok(result, "psVectorStats succeeded"); 177 185 ok(!isnan(myStats->min), "psVectorStats() returned non-NAN"); 178 186 ok_float_tol(myStats->min, expectedMinNoMaskF64, 1e-4, -
trunk/psLib/test/math/tap_psStats03.c
r10831 r10848 41 41 { 42 42 psMemId id = psMemGetId(); 43 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 43 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 44 ok(result, "psVectorStats succeeded"); 44 45 ok(!isnan(myStats->sampleMedian), "psVectorStats() returned non-NAN"); 45 46 ok_float_tol(myStats->sampleMedian, realMedianNoMask, 1e-4, … … 51 52 { 52 53 psMemId id = psMemGetId(); 53 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 54 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 55 ok(result, "psVectorStats succeeded"); 54 56 ok(!isnan(myStats->sampleMedian), "psVectorStats() returned non-NAN"); 55 57 ok_float_tol(myStats->sampleMedian, realMedianWithMask, 1e-4, -
trunk/psLib/test/math/tap_psStats06.c
r10831 r10848 42 42 { 43 43 psMemId id = psMemGetId(); 44 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 44 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 45 ok(result, "psVectorStats succeeded"); 45 46 ok(!isnan(myStats->sampleStdev), "psVectorStats() returned non-NAN"); 46 47 ok_float_tol(myStats->sampleStdev, realStdevNoMask, 1e-4, … … 52 53 { 53 54 psMemId id = psMemGetId(); 54 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 55 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 56 ok(result, "psVectorStats succeeded"); 55 57 ok(!isnan(myStats->sampleStdev), "psVectorStats() returned non-NAN"); 56 58 ok_float_tol(myStats->sampleStdev, realStdevWithMask, 1e-4, -
trunk/psLib/test/math/tap_psStats07.c
r10831 r10848 314 314 if (expectedRC == true) { 315 315 psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV | PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_QUARTILE); 316 psStats *rc = psVectorStats(myStats, in, NULL, NULL, maskValue);317 if (rc == NULL) {316 bool rc = psVectorStats(myStats, in, NULL, NULL, maskValue); 317 if (rc == false) { 318 318 diag("TEST ERROR: the psVectorStats() function returned NULL.\n"); 319 319 testStatus = false; … … 406 406 PS_STAT_FITTED_MEAN | 407 407 PS_STAT_FITTED_STDEV); 408 psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);409 410 if (rc == NULL) {408 bool rc = psVectorStats(myStats, in, errors, mask, maskValue); 409 410 if (rc == false) { 411 411 if (expectedRC == true) { 412 412 diag("TEST ERROR: the psVectorStats() function returned NULL.\n"); -
trunk/psLib/test/math/tap_psStats08.c
r10831 r10848 42 42 { 43 43 psMemId id = psMemGetId(); 44 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 44 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 45 ok(result, "psVectorStats succeeded"); 45 46 ok(!isnan(myStats->sampleLQ), "psVectorStats() returned non-NAN"); 46 47 ok_float_tol(myStats->sampleLQ, realLQNoMask, 1e-4, … … 52 53 { 53 54 psMemId id = psMemGetId(); 54 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 55 bool result = psVectorStats(myStats, myVector, NULL, NULL, 0); 56 ok(result, "psVectorStats succeeded"); 55 57 ok(!isnan(myStats->sampleUQ), "psVectorStats() returned non-NAN"); 56 58 ok_float_tol(myStats->sampleUQ, realUQNoMask, 1e-4, … … 62 64 { 63 65 psMemId id = psMemGetId(); 64 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 66 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 67 ok(result, "psVectorStats succeeded"); 65 68 ok(!isnan(myStats->sampleLQ), "psVectorStats() returned non-NAN"); 66 69 ok_float_tol(myStats->sampleLQ, realLQWithMask, 1e-4, … … 72 75 { 73 76 psMemId id = psMemGetId(); 74 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 77 bool result = psVectorStats(myStats, myVector, NULL, maskVector, 1); 78 ok(result, "psVectorStats succeeded"); 75 79 ok(!isnan(myStats->sampleUQ), "psVectorStats() returned non-NAN"); 76 80 ok_float_tol(myStats->sampleUQ, realUQNoMask, 1e-4, -
trunk/psLib/test/math/tap_psStats09.c
r10831 r10848 280 280 if (expectedRC == true) { 281 281 psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 282 psStats *rc = psVectorStats(myStats, in, errors, outliers, 1);283 if (rc == NULL) {282 bool rc = psVectorStats(myStats, in, errors, outliers, 1); 283 if (rc == false) { 284 284 diag("TEST ERROR: the psVectorStats() function returned NULL.\n"); 285 285 testStatus = false; … … 298 298 myStats->clipSigma = 5.0; 299 299 myStats->clipIter = 2; 300 psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);301 if (rc == NULL) {300 bool rc = psVectorStats(myStats, in, errors, mask, maskValue); 301 if (rc == false) { 302 302 if (expectedRC == true) { 303 303 diag("TEST ERROR: the psVectorStats() function returned NULL.\n");
Note:
See TracChangeset
for help on using the changeset viewer.
