Changeset 1953
- Timestamp:
- Oct 4, 2004, 3:43:58 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 11 edited
-
collections/psVector.h (modified) (2 diffs)
-
dataManip/psConstants.h (modified) (11 diffs)
-
dataManip/psFunctions.c (modified) (5 diffs)
-
dataManip/psMinimize.c (modified) (13 diffs)
-
dataManip/psMinimize.h (modified) (3 diffs)
-
math/psConstants.h (modified) (11 diffs)
-
math/psMinimize.c (modified) (13 diffs)
-
math/psMinimize.h (modified) (3 diffs)
-
math/psPolynomial.c (modified) (5 diffs)
-
math/psSpline.c (modified) (5 diffs)
-
mathtypes/psVector.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psVector.h
r1920 r1953 1 2 1 /** @file psVector.h 3 2 * … … 12 11 * @author Ross Harman, MHPCC 13 12 * 14 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $15 * @date $Date: 2004- 09-28 23:26:48$13 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-05 01:43:57 $ 16 15 * 17 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/dataManip/psConstants.h
r1945 r1953 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-0 3 23:35:47$8 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-05 01:43:58 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #define RIGHT_SPLINE_DERIV 0.0 19 19 20 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \ 21 static psVector *NAME = NULL; \ 22 NAME = psVectorRecycle(NAME, SIZE, TYPE); \ 23 p_psMemSetPersistent(NAME, true); \ 24 p_psMemSetPersistent(NAME->data.V, true); \ 25 26 27 28 20 29 /** Preprocessor macro to generate error on an incorrect type */ 21 30 #define PS_CHECK_VECTOR_TYPE(NAME, TYPE) \ 22 31 if (NAME->type.type != TYPE) { \ 23 psError(__func__," Invalidoperation: %s has incorrect type.", #NAME); \32 psError(__func__,"Unallowable operation: %s has incorrect type.", #NAME); \ 24 33 } 25 34 … … 27 36 #define PS_CHECK_NULL_VECTOR(NAME) \ 28 37 if (NAME == NULL || NAME->data.V == NULL) { \ 29 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \38 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 30 39 } 31 40 … … 34 43 if (NAME == NULL || NAME->data.V == NULL) { \ 35 44 if (ACTION == 0) { \ 36 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \45 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 37 46 return(NULL); \ 38 47 } \ 39 48 if (ACTION == 1) { \ 40 psAbort(__func__, " Invalidoperation: %s or its data is NULL.", #NAME); \49 psAbort(__func__, "Unallowable operation: %s or its data is NULL.", #NAME); \ 41 50 } \ 42 51 } … … 45 54 #define PS_CHECK_NULL_PTR(NAME) \ 46 55 if (NAME == NULL) { \ 47 psError(__func__," Invalidoperation: %s is NULL.", #NAME); \56 psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \ 48 57 } 49 58 … … 51 60 #define PS_CHECK_EMPTY_VECTOR(NAME) \ 52 61 if (NAME->n < 1) { \ 53 psError(__func__," Invalidoperation: %s has zero n value.", #NAME); \62 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 54 63 } 55 64 … … 58 67 if (NAME->n < 1) { \ 59 68 if (ACTION == 0) { \ 60 psError(__func__," Invalidoperation: %s has zero n value.", #NAME); \69 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 61 70 return(NULL); \ 62 71 } \ 63 72 if (ACTION == 1) { \ 64 psAbort(__func__," Invalidoperation: %s has zero n value.", #NAME); \73 psAbort(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 65 74 } \ 66 75 } … … 75 84 #define PS_CHECK_NULL_IMAGE(NAME) \ 76 85 if (NAME == NULL || NAME->data.V == NULL) { \ 77 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \86 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 78 87 } 79 88 … … 81 90 #define PS_CHECK_EMPTY_IMAGE(NAME) \ 82 91 if (NAME->numCols < 1 || NAME->numRows < 1) { \ 83 psError(__func__," Invalidoperation: %s has zero rows or columns (%dx%d).", #NAME, \92 psError(__func__,"Unallowable operation: %s has zero rows or columns (%dx%d).", #NAME, \ 84 93 NAME->numCols, NAME->numRows); \ 85 94 } … … 88 97 #define PS_CHECK_NULL_1DPOLY(NAME) \ 89 98 if (NAME == NULL || NAME->coeff == NULL) { \ 90 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \99 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 91 100 } 92 101 … … 95 104 if (NAME == NULL || NAME->coeff == NULL) { \ 96 105 if (ACTION == 0) { \ 97 psError(__func__," Invalidoperation: %s or its coeffs is NULL.", #NAME); \106 psError(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME); \ 98 107 return(NULL); \ 99 108 } \ 100 109 if (ACTION == 1) { \ 101 psAbort(__func__," Invalidoperation: %s or its coeffs is NULL.", #NAME); \110 psAbort(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME); \ 102 111 } \ 103 112 } -
trunk/psLib/src/dataManip/psFunctions.c
r1947 r1953 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.4 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-0 4 00:40:23$9 * @version $Revision: 1.46 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-05 01:43:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1988 1988 1989 1989 XXX: nobody asked for us to generate this routine. 1990 1991 XXX: add another psScalar argument for the result. 1992 1993 XXX: The VectorCopy routines seg fault when I declare range32 as static. 1990 1994 *****************************************************************************/ 1991 1995 psScalar *p_psVectorInterpolate(psVector *domain, … … 1994 1998 psScalar *x) 1995 1999 { 2000 psVector *range32 = NULL; 2001 psVector *domain32 = NULL; 1996 2002 psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4, 1997 2003 "---- p_psVectorInterpolate() begin ----\n"); … … 2000 2006 (domain->type.type != x->type.type)) { 2001 2007 // XXX psError 2002 printf(" domain->type.type != range->type.type != x->type.type\n");2008 printf("p_psVectorInterpolate(): domain->type.type != range->type.type != x->type.type\n"); 2003 2009 printf("%d %d %d\n", domain->type.type, range->type.type, x->type.type); 2010 exit(1); 2004 2011 } 2005 2012 if (domain->n != range->n) { 2006 2013 // XXX psError 2007 2014 printf("domain->n != range->n\n"); 2015 exit(1); 2008 2016 } 2009 2017 if (order > (domain->n - 1)) { 2010 2018 // XXX psError: not enough data points for order-order interpolation. 2011 2019 printf("not enough data points for order-order interpolation.\n"); 2020 exit(1); 2012 2021 } 2013 2022 … … 2020 2029 order, 2021 2030 x->data.F32), PS_TYPE_F32)); 2031 } else if (x->type.type == PS_TYPE_F64) { 2032 // XXX: use recycled vectors here. 2033 range32 = psVectorCopy(range32, range, PS_TYPE_F32); 2034 domain32 = psVectorCopy(domain32, domain, PS_TYPE_F32); 2035 2036 psScalar *tmpScalar = psScalarAlloc((double) 2037 p_ps1DInterpolateF32(domain32->data.F32, 2038 range32->data.F32, 2039 domain32->n, 2040 order, 2041 (float) x->data.F64), PS_TYPE_F64); 2042 psFree(range32); 2043 psFree(domain32); 2044 2045 psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4, 2046 "---- p_psVectorInterpolate() end ----\n"); 2047 // XXX: Convert data type to F64? 2048 return(tmpScalar); 2049 2022 2050 } else { 2023 2051 // XXX psError: type not supported -
trunk/psLib/src/dataManip/psMinimize.c
r1945 r1953 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.5 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-0 3 23:35:47$11 * @version $Revision: 1.52 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-05 01:43:58 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 /* INCLUDE FILES */ 25 25 /*****************************************************************************/ 26 #include <stdlib.h>27 #include <stdio.h>28 #include <string.h>29 #include <stdarg.h>30 #include <float.h>31 #include <math.h>32 33 #include <gsl/gsl_multifit_nlin.h>34 #include <gsl/gsl_multimin.h>35 #include <gsl/gsl_rng.h>36 #include <gsl/gsl_randist.h>37 #include <gsl/gsl_vector.h>38 #include <gsl/gsl_blas.h>39 40 #include "psMemory.h"41 #include "psVector.h"42 #include "psImage.h"43 #include "psTrace.h"44 #include "psLogMsg.h"45 #include "psError.h"46 #include "psAbort.h"47 #include "psFunctions.h"48 26 #include "psMinimize.h" 49 #include "psMatrix.h"50 #include "psConstants.h"51 52 27 /*****************************************************************************/ 53 28 /* DEFINE STATEMENTS */ … … 655 630 } 656 631 632 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \ 633 static psVector *NAME = NULL; \ 634 NAME = psVectorRecycle(NAME, SIZE, TYPE); \ 635 p_psMemSetPersistent(NAME, true); \ 636 p_psMemSetPersistent(NAME->data.V, true); \ 637 657 638 658 639 /****************************************************************************** … … 661 642 coefficients of that polynomial. 662 643 663 XXX: yErr is currently ignored.664 665 XXX: must add type F32 (currently F64 only). 666 667 XXX:Use private name?668 *****************************************************************************/644 XXX: 645 yErr is currently ignored. 646 647 XXX: 648 Use private name? 649 *****************************************************************************/ 669 650 psPolynomial1D *p_psVectorFitPolynomial1DCheby(psPolynomial1D* myPoly, 670 651 const psVector* restrict x, … … 675 656 int k; 676 657 int n = x->n; 677 psVector *f = psVectorAlloc(n, PS_TYPE_F64);678 658 double fac; 679 659 double sum; 680 // XXX: Use static memory here. 681 psScalar *tmpScalar = psScalarAlloc(0.0, PS_TYPE_F32); 660 GEN_STATIC_RECYCLED_VECTOR(f, n, PS_TYPE_F64); 682 661 psScalar *fScalar; 662 psScalar tmpScalar; 663 tmpScalar.type.type = PS_TYPE_F64; 683 664 684 665 // XXX: These assignments appear too simple to warrant code and … … 690 671 double bpa = 0.5 * (max+min); // 0 691 672 692 // XXX: Eliminate this later by generating a F64 version of the693 // LaGrange interpolation routines.694 PS_VECTOR_F64_TO_F32(x, x32);695 PS_VECTOR_F64_TO_F32(y, y32);696 697 673 // In this loop, we first calculate the values of X for which the 698 674 // Chebyshev polynomials are zero (see NR, section 5.4). Then we … … 707 683 double Y = cos(M_PI * (0.5 + ((float) i)) / ((float) n)); 708 684 double X = (Y + bma + bpa) - 1.0; 709 tmpScalar ->data.F32 = (float)X;685 tmpScalar.data.F64 = X; 710 686 711 687 // We interpolate against are tabluated x,y vectors to determine the 712 688 // function value at X. 713 fScalar = p_psVectorInterpolate((psVector *) x32, (psVector *) y32, 714 3, tmpScalar); 715 716 f->data.F64[i] = (double) fScalar->data.F32; 689 fScalar = p_psVectorInterpolate((psVector *) x, 690 (psVector *) y, 691 3, 692 &tmpScalar); 693 694 f->data.F64[i] = fScalar->data.F64; 717 695 psFree(fScalar); 718 696 … … 724 702 // We have the values for f() at the zero points, we now calculate the 725 703 // coefficients of the Chebyshev polynomial: NR 5.8.7. 704 726 705 fac = 2.0/((float) n); 727 728 706 // XXX: is this loop bound correct? 729 707 for (j=0;j<myPoly->n;j++) { … … 737 715 } 738 716 739 // XXX: Must free memory.740 psFree(f);741 psFree(x32);742 psFree(y32);743 psFree(tmpScalar);744 745 717 return(myPoly); 746 718 } … … 750 722 polynomial of degree myPoly to the data points (x, y) and return the 751 723 coefficients of that polynomial. 752 753 XXX: must add type F32 (currently F64 only).754 724 755 725 XXX: Use private name? … … 875 845 polynomial. 876 846 877 XXX: must add type F32 (currently F64 only).847 XXX: type F32 is done via vector conversion only. 878 848 *****************************************************************************/ 879 849 psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly, … … 882 852 const psVector* restrict yErr) 883 853 { 884 bool mustFreeMyYErr = false;885 bool mustFreemyX = false;886 854 int i; 887 855 psPolynomial1D *tmpPoly; 888 psVector *myX = NULL;889 psVector *myYErr = NULL;890 891 856 PS_CHECK_NULL_1DPOLY_ACTION(myPoly, 0); 892 857 PS_CHECK_NULL_VECTOR_ACTION(y, 0); 893 858 PS_CHECK_EMPTY_VECTOR_ACTION(y, 0); 859 psVector *x64 = NULL; 860 psVector *y64 = NULL; 861 psVector *yErr64 = NULL; 862 static psVector *x64Static = NULL; 863 static psVector *y64Static = NULL; 864 static psVector *yErr64Static = NULL; 865 866 if (y->type.type == PS_TYPE_F64) { 867 y64 = (psVector *) y; 868 } else if (y->type.type == PS_TYPE_F32) { 869 y64Static = psVectorRecycle(y64Static, y->n, PS_TYPE_F64); 870 p_psMemSetPersistent(y64Static, true); 871 p_psMemSetPersistent(y64Static->data.V, true); 872 y64 = y64Static; 873 } else { 874 // XXX: psError() bad type. 875 psAbort(__func__, "Bad type for y64 (%d)", y->type.type); 876 } 877 894 878 895 879 // If yErr==NULL, set all errors equal. 896 880 if (yErr == NULL) { 897 myYErr = psVectorAlloc(y->n, y->type.type); 898 mustFreeMyYErr = true; 899 900 if (y->type.type == PS_TYPE_F32) { 901 for (i=0;i<myYErr->n;i++) { 902 myYErr->data.F32[i] = 1.0; 903 } 904 } else if (y->type.type == PS_TYPE_F64) { 905 for (i=0;i<myYErr->n;i++) { 906 myYErr->data.F64[i] = 1.0; 907 } 908 } 881 yErr64Static = psVectorRecycle(yErr64Static, y->n, PS_TYPE_F64); 882 p_psMemSetPersistent(yErr64Static, true); 883 p_psMemSetPersistent(yErr64Static->data.V, true); 884 885 for (i=0;i<yErr64Static->n;i++) { 886 yErr64Static->data.F64[i] = 1.0; 887 } 888 yErr64 = yErr64Static; 909 889 } else { 910 myYErr = (psVector *) yErr; 911 } 912 913 // If x==NULL, create an myX vector with x values set to (0:n), and if 890 if (yErr->type.type == PS_TYPE_F64) { 891 yErr64 = (psVector *) yErr; 892 } else if (yErr->type.type == PS_TYPE_F32) { 893 yErr64Static = psVectorRecycle(yErr64Static, yErr->n, PS_TYPE_F64); 894 p_psMemSetPersistent(yErr64Static, true); 895 p_psMemSetPersistent(yErr64Static->data.V, true); 896 } else { 897 // XXX: psError() bad type. 898 psAbort(__func__, "Bad type for yErr64"); 899 } 900 } 901 902 // If x==NULL, create an x64 vector with x values set to (0:n), and if 914 903 // this is a Chebyshev polynomial, we must scale to (-1:1). 915 916 904 // XXX: Verify that this is the correct action. 917 905 if (x == NULL) { 918 myX = psVectorAlloc(y->n, y->type.type); 919 mustFreemyX = true; 920 921 if (y->type.type == PS_TYPE_F32) { 922 if (myPoly->type == PS_POLYNOMIAL_ORD) { 923 for (i=0;i<myX->n;i++) { 924 myX->data.F32[i] = (float) i; 925 } 926 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 927 float min = 0.0; 928 float max = (float) (y->n - 1); 929 930 for (i=0;i<myX->n;i++) { 931 myX->data.F32[i] = (((float) i) - 0.5 * (min + max)) / 932 (0.5 * (max - min)); 933 } 934 } 935 } else if (y->type.type == PS_TYPE_F64) { 936 if (myPoly->type == PS_POLYNOMIAL_ORD) { 937 for (i=0;i<myX->n;i++) { 938 myX->data.F64[i] = (float) i; 939 } 940 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 941 double min = 0.0; 942 double max = (double) (y->n - 1); 943 944 for (i=0;i<myX->n;i++) { 945 myX->data.F64[i] = (((float) i) - 0.5 * (min + max)) / 946 (0.5 * (max - min)); 947 } 906 x64Static = psVectorRecycle(x64Static, y->n, PS_TYPE_F64); 907 p_psMemSetPersistent(x64Static, true); 908 p_psMemSetPersistent(x64Static->data.V, true); 909 x64 = x64Static; 910 911 if (myPoly->type == PS_POLYNOMIAL_ORD) { 912 for (i=0;i<x64->n;i++) { 913 x64->data.F64[i] = (float) i; 914 } 915 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 916 double min = 0.0; 917 double max = (double) (y->n - 1); 918 919 for (i=0;i<x64->n;i++) { 920 x64->data.F64[i] = (((double) i) - 0.5 * (min + max)) / 921 (0.5 * (max - min)); 948 922 } 949 923 } 950 924 } else { 951 myX = (psVector *) x; 952 } 953 954 PS_CHECK_VECTOR_SIZE_EQUAL(y, myX); 955 PS_CHECK_VECTOR_SIZE_EQUAL(y, myYErr); 925 if (x->type.type == PS_TYPE_F64) { 926 x64 = (psVector *) x; 927 } else if (x->type.type == PS_TYPE_F32) { 928 x64Static = psVectorRecycle(x64Static, x->n, PS_TYPE_F64); 929 p_psMemSetPersistent(x64Static, true); 930 p_psMemSetPersistent(x64Static->data.V, true); 931 x64 = x64Static; 932 } else { 933 // XXX: psError() bad type. 934 psAbort(__func__, "Bad type for x64"); 935 } 936 } 937 938 PS_CHECK_VECTOR_SIZE_EQUAL(y64, x64); 939 PS_CHECK_VECTOR_SIZE_EQUAL(y64, yErr64); 956 940 957 941 // Call the appropriate vector fitting routine. 958 942 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 959 tmpPoly = p_psVectorFitPolynomial1DCheby(myPoly, myX, y, myYErr);943 tmpPoly = p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64); 960 944 } else if (myPoly->type == PS_POLYNOMIAL_ORD) { 961 tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, myX, y, myYErr);945 tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64); 962 946 } else { 963 947 // XXX: psErrorMsg() … … 966 950 967 951 // Free any allocated memory. 968 if (mustFreeMyYErr == true) { 969 psFree(myYErr); 970 } 971 if (mustFreemyX == true) { 972 psFree(myX); 973 } 952 /* 953 if ((yErr == NULL) || (yErr->type.type != PS_TYPE_F64)) { 954 psFree(yErr64); 955 } 956 if ((x == NULL) || (x->type.type != PS_TYPE_F64)) { 957 psFree(x64); 958 } 959 if ((y == NULL) || (y->type.type != PS_TYPE_F64)) { 960 psFree(y64); 961 } 962 */ 974 963 975 964 return(myPoly); -
trunk/psLib/src/dataManip/psMinimize.h
r1846 r1953 8 8 * @author George Gusciora, MHPCC 9 9 * 10 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $11 * @date $Date: 2004- 09-22 01:30:21$10 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-10-05 01:43:58 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #define PS_MINIMIZE_H 19 19 20 #include <stdio.h> 21 #include <float.h> 22 #include <math.h> 23 24 #include "psMemory.h" 25 #include "psVector.h" 26 #include "psArray.h" 27 #include "psImage.h" 28 #include "psMatrix.h" 20 29 #include "psFunctions.h" 21 #include "psArray.h" 22 #include "psVector.h" 23 #include "psMatrix.h" 30 #include "psTrace.h" 31 #include "psLogMsg.h" 32 #include "psError.h" 33 #include "psAbort.h" 34 #include "psConstants.h" 35 24 36 25 37 /** \file psMinimize.h … … 44 56 float tol); 45 57 46 /** Derive a polynomial fit by chi^2 minimisation (analytically)58 /** Derive a polynomial fit. 47 59 * 48 60 * psVectorFitPolynomial1d returns the polynomial that best fits the -
trunk/psLib/src/math/psConstants.h
r1945 r1953 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-0 3 23:35:47$8 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-05 01:43:58 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #define RIGHT_SPLINE_DERIV 0.0 19 19 20 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \ 21 static psVector *NAME = NULL; \ 22 NAME = psVectorRecycle(NAME, SIZE, TYPE); \ 23 p_psMemSetPersistent(NAME, true); \ 24 p_psMemSetPersistent(NAME->data.V, true); \ 25 26 27 28 20 29 /** Preprocessor macro to generate error on an incorrect type */ 21 30 #define PS_CHECK_VECTOR_TYPE(NAME, TYPE) \ 22 31 if (NAME->type.type != TYPE) { \ 23 psError(__func__," Invalidoperation: %s has incorrect type.", #NAME); \32 psError(__func__,"Unallowable operation: %s has incorrect type.", #NAME); \ 24 33 } 25 34 … … 27 36 #define PS_CHECK_NULL_VECTOR(NAME) \ 28 37 if (NAME == NULL || NAME->data.V == NULL) { \ 29 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \38 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 30 39 } 31 40 … … 34 43 if (NAME == NULL || NAME->data.V == NULL) { \ 35 44 if (ACTION == 0) { \ 36 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \45 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 37 46 return(NULL); \ 38 47 } \ 39 48 if (ACTION == 1) { \ 40 psAbort(__func__, " Invalidoperation: %s or its data is NULL.", #NAME); \49 psAbort(__func__, "Unallowable operation: %s or its data is NULL.", #NAME); \ 41 50 } \ 42 51 } … … 45 54 #define PS_CHECK_NULL_PTR(NAME) \ 46 55 if (NAME == NULL) { \ 47 psError(__func__," Invalidoperation: %s is NULL.", #NAME); \56 psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \ 48 57 } 49 58 … … 51 60 #define PS_CHECK_EMPTY_VECTOR(NAME) \ 52 61 if (NAME->n < 1) { \ 53 psError(__func__," Invalidoperation: %s has zero n value.", #NAME); \62 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 54 63 } 55 64 … … 58 67 if (NAME->n < 1) { \ 59 68 if (ACTION == 0) { \ 60 psError(__func__," Invalidoperation: %s has zero n value.", #NAME); \69 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 61 70 return(NULL); \ 62 71 } \ 63 72 if (ACTION == 1) { \ 64 psAbort(__func__," Invalidoperation: %s has zero n value.", #NAME); \73 psAbort(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 65 74 } \ 66 75 } … … 75 84 #define PS_CHECK_NULL_IMAGE(NAME) \ 76 85 if (NAME == NULL || NAME->data.V == NULL) { \ 77 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \86 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 78 87 } 79 88 … … 81 90 #define PS_CHECK_EMPTY_IMAGE(NAME) \ 82 91 if (NAME->numCols < 1 || NAME->numRows < 1) { \ 83 psError(__func__," Invalidoperation: %s has zero rows or columns (%dx%d).", #NAME, \92 psError(__func__,"Unallowable operation: %s has zero rows or columns (%dx%d).", #NAME, \ 84 93 NAME->numCols, NAME->numRows); \ 85 94 } … … 88 97 #define PS_CHECK_NULL_1DPOLY(NAME) \ 89 98 if (NAME == NULL || NAME->coeff == NULL) { \ 90 psError(__func__," Invalidoperation: %s or its data is NULL.", #NAME); \99 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 91 100 } 92 101 … … 95 104 if (NAME == NULL || NAME->coeff == NULL) { \ 96 105 if (ACTION == 0) { \ 97 psError(__func__," Invalidoperation: %s or its coeffs is NULL.", #NAME); \106 psError(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME); \ 98 107 return(NULL); \ 99 108 } \ 100 109 if (ACTION == 1) { \ 101 psAbort(__func__," Invalidoperation: %s or its coeffs is NULL.", #NAME); \110 psAbort(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME); \ 102 111 } \ 103 112 } -
trunk/psLib/src/math/psMinimize.c
r1945 r1953 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.5 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-0 3 23:35:47$11 * @version $Revision: 1.52 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-05 01:43:58 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 /* INCLUDE FILES */ 25 25 /*****************************************************************************/ 26 #include <stdlib.h>27 #include <stdio.h>28 #include <string.h>29 #include <stdarg.h>30 #include <float.h>31 #include <math.h>32 33 #include <gsl/gsl_multifit_nlin.h>34 #include <gsl/gsl_multimin.h>35 #include <gsl/gsl_rng.h>36 #include <gsl/gsl_randist.h>37 #include <gsl/gsl_vector.h>38 #include <gsl/gsl_blas.h>39 40 #include "psMemory.h"41 #include "psVector.h"42 #include "psImage.h"43 #include "psTrace.h"44 #include "psLogMsg.h"45 #include "psError.h"46 #include "psAbort.h"47 #include "psFunctions.h"48 26 #include "psMinimize.h" 49 #include "psMatrix.h"50 #include "psConstants.h"51 52 27 /*****************************************************************************/ 53 28 /* DEFINE STATEMENTS */ … … 655 630 } 656 631 632 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \ 633 static psVector *NAME = NULL; \ 634 NAME = psVectorRecycle(NAME, SIZE, TYPE); \ 635 p_psMemSetPersistent(NAME, true); \ 636 p_psMemSetPersistent(NAME->data.V, true); \ 637 657 638 658 639 /****************************************************************************** … … 661 642 coefficients of that polynomial. 662 643 663 XXX: yErr is currently ignored.664 665 XXX: must add type F32 (currently F64 only). 666 667 XXX:Use private name?668 *****************************************************************************/644 XXX: 645 yErr is currently ignored. 646 647 XXX: 648 Use private name? 649 *****************************************************************************/ 669 650 psPolynomial1D *p_psVectorFitPolynomial1DCheby(psPolynomial1D* myPoly, 670 651 const psVector* restrict x, … … 675 656 int k; 676 657 int n = x->n; 677 psVector *f = psVectorAlloc(n, PS_TYPE_F64);678 658 double fac; 679 659 double sum; 680 // XXX: Use static memory here. 681 psScalar *tmpScalar = psScalarAlloc(0.0, PS_TYPE_F32); 660 GEN_STATIC_RECYCLED_VECTOR(f, n, PS_TYPE_F64); 682 661 psScalar *fScalar; 662 psScalar tmpScalar; 663 tmpScalar.type.type = PS_TYPE_F64; 683 664 684 665 // XXX: These assignments appear too simple to warrant code and … … 690 671 double bpa = 0.5 * (max+min); // 0 691 672 692 // XXX: Eliminate this later by generating a F64 version of the693 // LaGrange interpolation routines.694 PS_VECTOR_F64_TO_F32(x, x32);695 PS_VECTOR_F64_TO_F32(y, y32);696 697 673 // In this loop, we first calculate the values of X for which the 698 674 // Chebyshev polynomials are zero (see NR, section 5.4). Then we … … 707 683 double Y = cos(M_PI * (0.5 + ((float) i)) / ((float) n)); 708 684 double X = (Y + bma + bpa) - 1.0; 709 tmpScalar ->data.F32 = (float)X;685 tmpScalar.data.F64 = X; 710 686 711 687 // We interpolate against are tabluated x,y vectors to determine the 712 688 // function value at X. 713 fScalar = p_psVectorInterpolate((psVector *) x32, (psVector *) y32, 714 3, tmpScalar); 715 716 f->data.F64[i] = (double) fScalar->data.F32; 689 fScalar = p_psVectorInterpolate((psVector *) x, 690 (psVector *) y, 691 3, 692 &tmpScalar); 693 694 f->data.F64[i] = fScalar->data.F64; 717 695 psFree(fScalar); 718 696 … … 724 702 // We have the values for f() at the zero points, we now calculate the 725 703 // coefficients of the Chebyshev polynomial: NR 5.8.7. 704 726 705 fac = 2.0/((float) n); 727 728 706 // XXX: is this loop bound correct? 729 707 for (j=0;j<myPoly->n;j++) { … … 737 715 } 738 716 739 // XXX: Must free memory.740 psFree(f);741 psFree(x32);742 psFree(y32);743 psFree(tmpScalar);744 745 717 return(myPoly); 746 718 } … … 750 722 polynomial of degree myPoly to the data points (x, y) and return the 751 723 coefficients of that polynomial. 752 753 XXX: must add type F32 (currently F64 only).754 724 755 725 XXX: Use private name? … … 875 845 polynomial. 876 846 877 XXX: must add type F32 (currently F64 only).847 XXX: type F32 is done via vector conversion only. 878 848 *****************************************************************************/ 879 849 psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly, … … 882 852 const psVector* restrict yErr) 883 853 { 884 bool mustFreeMyYErr = false;885 bool mustFreemyX = false;886 854 int i; 887 855 psPolynomial1D *tmpPoly; 888 psVector *myX = NULL;889 psVector *myYErr = NULL;890 891 856 PS_CHECK_NULL_1DPOLY_ACTION(myPoly, 0); 892 857 PS_CHECK_NULL_VECTOR_ACTION(y, 0); 893 858 PS_CHECK_EMPTY_VECTOR_ACTION(y, 0); 859 psVector *x64 = NULL; 860 psVector *y64 = NULL; 861 psVector *yErr64 = NULL; 862 static psVector *x64Static = NULL; 863 static psVector *y64Static = NULL; 864 static psVector *yErr64Static = NULL; 865 866 if (y->type.type == PS_TYPE_F64) { 867 y64 = (psVector *) y; 868 } else if (y->type.type == PS_TYPE_F32) { 869 y64Static = psVectorRecycle(y64Static, y->n, PS_TYPE_F64); 870 p_psMemSetPersistent(y64Static, true); 871 p_psMemSetPersistent(y64Static->data.V, true); 872 y64 = y64Static; 873 } else { 874 // XXX: psError() bad type. 875 psAbort(__func__, "Bad type for y64 (%d)", y->type.type); 876 } 877 894 878 895 879 // If yErr==NULL, set all errors equal. 896 880 if (yErr == NULL) { 897 myYErr = psVectorAlloc(y->n, y->type.type); 898 mustFreeMyYErr = true; 899 900 if (y->type.type == PS_TYPE_F32) { 901 for (i=0;i<myYErr->n;i++) { 902 myYErr->data.F32[i] = 1.0; 903 } 904 } else if (y->type.type == PS_TYPE_F64) { 905 for (i=0;i<myYErr->n;i++) { 906 myYErr->data.F64[i] = 1.0; 907 } 908 } 881 yErr64Static = psVectorRecycle(yErr64Static, y->n, PS_TYPE_F64); 882 p_psMemSetPersistent(yErr64Static, true); 883 p_psMemSetPersistent(yErr64Static->data.V, true); 884 885 for (i=0;i<yErr64Static->n;i++) { 886 yErr64Static->data.F64[i] = 1.0; 887 } 888 yErr64 = yErr64Static; 909 889 } else { 910 myYErr = (psVector *) yErr; 911 } 912 913 // If x==NULL, create an myX vector with x values set to (0:n), and if 890 if (yErr->type.type == PS_TYPE_F64) { 891 yErr64 = (psVector *) yErr; 892 } else if (yErr->type.type == PS_TYPE_F32) { 893 yErr64Static = psVectorRecycle(yErr64Static, yErr->n, PS_TYPE_F64); 894 p_psMemSetPersistent(yErr64Static, true); 895 p_psMemSetPersistent(yErr64Static->data.V, true); 896 } else { 897 // XXX: psError() bad type. 898 psAbort(__func__, "Bad type for yErr64"); 899 } 900 } 901 902 // If x==NULL, create an x64 vector with x values set to (0:n), and if 914 903 // this is a Chebyshev polynomial, we must scale to (-1:1). 915 916 904 // XXX: Verify that this is the correct action. 917 905 if (x == NULL) { 918 myX = psVectorAlloc(y->n, y->type.type); 919 mustFreemyX = true; 920 921 if (y->type.type == PS_TYPE_F32) { 922 if (myPoly->type == PS_POLYNOMIAL_ORD) { 923 for (i=0;i<myX->n;i++) { 924 myX->data.F32[i] = (float) i; 925 } 926 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 927 float min = 0.0; 928 float max = (float) (y->n - 1); 929 930 for (i=0;i<myX->n;i++) { 931 myX->data.F32[i] = (((float) i) - 0.5 * (min + max)) / 932 (0.5 * (max - min)); 933 } 934 } 935 } else if (y->type.type == PS_TYPE_F64) { 936 if (myPoly->type == PS_POLYNOMIAL_ORD) { 937 for (i=0;i<myX->n;i++) { 938 myX->data.F64[i] = (float) i; 939 } 940 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 941 double min = 0.0; 942 double max = (double) (y->n - 1); 943 944 for (i=0;i<myX->n;i++) { 945 myX->data.F64[i] = (((float) i) - 0.5 * (min + max)) / 946 (0.5 * (max - min)); 947 } 906 x64Static = psVectorRecycle(x64Static, y->n, PS_TYPE_F64); 907 p_psMemSetPersistent(x64Static, true); 908 p_psMemSetPersistent(x64Static->data.V, true); 909 x64 = x64Static; 910 911 if (myPoly->type == PS_POLYNOMIAL_ORD) { 912 for (i=0;i<x64->n;i++) { 913 x64->data.F64[i] = (float) i; 914 } 915 } else if (myPoly->type == PS_POLYNOMIAL_CHEB) { 916 double min = 0.0; 917 double max = (double) (y->n - 1); 918 919 for (i=0;i<x64->n;i++) { 920 x64->data.F64[i] = (((double) i) - 0.5 * (min + max)) / 921 (0.5 * (max - min)); 948 922 } 949 923 } 950 924 } else { 951 myX = (psVector *) x; 952 } 953 954 PS_CHECK_VECTOR_SIZE_EQUAL(y, myX); 955 PS_CHECK_VECTOR_SIZE_EQUAL(y, myYErr); 925 if (x->type.type == PS_TYPE_F64) { 926 x64 = (psVector *) x; 927 } else if (x->type.type == PS_TYPE_F32) { 928 x64Static = psVectorRecycle(x64Static, x->n, PS_TYPE_F64); 929 p_psMemSetPersistent(x64Static, true); 930 p_psMemSetPersistent(x64Static->data.V, true); 931 x64 = x64Static; 932 } else { 933 // XXX: psError() bad type. 934 psAbort(__func__, "Bad type for x64"); 935 } 936 } 937 938 PS_CHECK_VECTOR_SIZE_EQUAL(y64, x64); 939 PS_CHECK_VECTOR_SIZE_EQUAL(y64, yErr64); 956 940 957 941 // Call the appropriate vector fitting routine. 958 942 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 959 tmpPoly = p_psVectorFitPolynomial1DCheby(myPoly, myX, y, myYErr);943 tmpPoly = p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64); 960 944 } else if (myPoly->type == PS_POLYNOMIAL_ORD) { 961 tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, myX, y, myYErr);945 tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64); 962 946 } else { 963 947 // XXX: psErrorMsg() … … 966 950 967 951 // Free any allocated memory. 968 if (mustFreeMyYErr == true) { 969 psFree(myYErr); 970 } 971 if (mustFreemyX == true) { 972 psFree(myX); 973 } 952 /* 953 if ((yErr == NULL) || (yErr->type.type != PS_TYPE_F64)) { 954 psFree(yErr64); 955 } 956 if ((x == NULL) || (x->type.type != PS_TYPE_F64)) { 957 psFree(x64); 958 } 959 if ((y == NULL) || (y->type.type != PS_TYPE_F64)) { 960 psFree(y64); 961 } 962 */ 974 963 975 964 return(myPoly); -
trunk/psLib/src/math/psMinimize.h
r1846 r1953 8 8 * @author George Gusciora, MHPCC 9 9 * 10 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $11 * @date $Date: 2004- 09-22 01:30:21$10 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-10-05 01:43:58 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #define PS_MINIMIZE_H 19 19 20 #include <stdio.h> 21 #include <float.h> 22 #include <math.h> 23 24 #include "psMemory.h" 25 #include "psVector.h" 26 #include "psArray.h" 27 #include "psImage.h" 28 #include "psMatrix.h" 20 29 #include "psFunctions.h" 21 #include "psArray.h" 22 #include "psVector.h" 23 #include "psMatrix.h" 30 #include "psTrace.h" 31 #include "psLogMsg.h" 32 #include "psError.h" 33 #include "psAbort.h" 34 #include "psConstants.h" 35 24 36 25 37 /** \file psMinimize.h … … 44 56 float tol); 45 57 46 /** Derive a polynomial fit by chi^2 minimisation (analytically)58 /** Derive a polynomial fit. 47 59 * 48 60 * psVectorFitPolynomial1d returns the polynomial that best fits the -
trunk/psLib/src/math/psPolynomial.c
r1947 r1953 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.4 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-0 4 00:40:23$9 * @version $Revision: 1.46 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-05 01:43:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1988 1988 1989 1989 XXX: nobody asked for us to generate this routine. 1990 1991 XXX: add another psScalar argument for the result. 1992 1993 XXX: The VectorCopy routines seg fault when I declare range32 as static. 1990 1994 *****************************************************************************/ 1991 1995 psScalar *p_psVectorInterpolate(psVector *domain, … … 1994 1998 psScalar *x) 1995 1999 { 2000 psVector *range32 = NULL; 2001 psVector *domain32 = NULL; 1996 2002 psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4, 1997 2003 "---- p_psVectorInterpolate() begin ----\n"); … … 2000 2006 (domain->type.type != x->type.type)) { 2001 2007 // XXX psError 2002 printf(" domain->type.type != range->type.type != x->type.type\n");2008 printf("p_psVectorInterpolate(): domain->type.type != range->type.type != x->type.type\n"); 2003 2009 printf("%d %d %d\n", domain->type.type, range->type.type, x->type.type); 2010 exit(1); 2004 2011 } 2005 2012 if (domain->n != range->n) { 2006 2013 // XXX psError 2007 2014 printf("domain->n != range->n\n"); 2015 exit(1); 2008 2016 } 2009 2017 if (order > (domain->n - 1)) { 2010 2018 // XXX psError: not enough data points for order-order interpolation. 2011 2019 printf("not enough data points for order-order interpolation.\n"); 2020 exit(1); 2012 2021 } 2013 2022 … … 2020 2029 order, 2021 2030 x->data.F32), PS_TYPE_F32)); 2031 } else if (x->type.type == PS_TYPE_F64) { 2032 // XXX: use recycled vectors here. 2033 range32 = psVectorCopy(range32, range, PS_TYPE_F32); 2034 domain32 = psVectorCopy(domain32, domain, PS_TYPE_F32); 2035 2036 psScalar *tmpScalar = psScalarAlloc((double) 2037 p_ps1DInterpolateF32(domain32->data.F32, 2038 range32->data.F32, 2039 domain32->n, 2040 order, 2041 (float) x->data.F64), PS_TYPE_F64); 2042 psFree(range32); 2043 psFree(domain32); 2044 2045 psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4, 2046 "---- p_psVectorInterpolate() end ----\n"); 2047 // XXX: Convert data type to F64? 2048 return(tmpScalar); 2049 2022 2050 } else { 2023 2051 // XXX psError: type not supported -
trunk/psLib/src/math/psSpline.c
r1947 r1953 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.4 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10-0 4 00:40:23$9 * @version $Revision: 1.46 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-05 01:43:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1988 1988 1989 1989 XXX: nobody asked for us to generate this routine. 1990 1991 XXX: add another psScalar argument for the result. 1992 1993 XXX: The VectorCopy routines seg fault when I declare range32 as static. 1990 1994 *****************************************************************************/ 1991 1995 psScalar *p_psVectorInterpolate(psVector *domain, … … 1994 1998 psScalar *x) 1995 1999 { 2000 psVector *range32 = NULL; 2001 psVector *domain32 = NULL; 1996 2002 psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4, 1997 2003 "---- p_psVectorInterpolate() begin ----\n"); … … 2000 2006 (domain->type.type != x->type.type)) { 2001 2007 // XXX psError 2002 printf(" domain->type.type != range->type.type != x->type.type\n");2008 printf("p_psVectorInterpolate(): domain->type.type != range->type.type != x->type.type\n"); 2003 2009 printf("%d %d %d\n", domain->type.type, range->type.type, x->type.type); 2010 exit(1); 2004 2011 } 2005 2012 if (domain->n != range->n) { 2006 2013 // XXX psError 2007 2014 printf("domain->n != range->n\n"); 2015 exit(1); 2008 2016 } 2009 2017 if (order > (domain->n - 1)) { 2010 2018 // XXX psError: not enough data points for order-order interpolation. 2011 2019 printf("not enough data points for order-order interpolation.\n"); 2020 exit(1); 2012 2021 } 2013 2022 … … 2020 2029 order, 2021 2030 x->data.F32), PS_TYPE_F32)); 2031 } else if (x->type.type == PS_TYPE_F64) { 2032 // XXX: use recycled vectors here. 2033 range32 = psVectorCopy(range32, range, PS_TYPE_F32); 2034 domain32 = psVectorCopy(domain32, domain, PS_TYPE_F32); 2035 2036 psScalar *tmpScalar = psScalarAlloc((double) 2037 p_ps1DInterpolateF32(domain32->data.F32, 2038 range32->data.F32, 2039 domain32->n, 2040 order, 2041 (float) x->data.F64), PS_TYPE_F64); 2042 psFree(range32); 2043 psFree(domain32); 2044 2045 psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4, 2046 "---- p_psVectorInterpolate() end ----\n"); 2047 // XXX: Convert data type to F64? 2048 return(tmpScalar); 2049 2022 2050 } else { 2023 2051 // XXX psError: type not supported -
trunk/psLib/src/mathtypes/psVector.h
r1920 r1953 1 2 1 /** @file psVector.h 3 2 * … … 12 11 * @author Ross Harman, MHPCC 13 12 * 14 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $15 * @date $Date: 2004- 09-28 23:26:48$13 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-05 01:43:57 $ 16 15 * 17 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
Note:
See TracChangeset
for help on using the changeset viewer.
