Changeset 1963
- Timestamp:
- Oct 5, 2004, 12:47:21 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 10 edited
-
dataManip/psConstants.h (modified) (6 diffs)
-
dataManip/psMinimize.c (modified) (15 diffs)
-
dataManip/psMinimize.h (modified) (2 diffs)
-
dataManip/psStats.c (modified) (5 diffs)
-
dataManip/psStats.h (modified) (2 diffs)
-
math/psConstants.h (modified) (6 diffs)
-
math/psMinimize.c (modified) (15 diffs)
-
math/psMinimize.h (modified) (2 diffs)
-
math/psStats.c (modified) (5 diffs)
-
math/psStats.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psConstants.h
r1953 r1963 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-05 01:43:58$8 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-05 22:47:21 $ 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 CONVERT_VECTOR_F64_TO_F32(OLD, NEW_PTR32, NEW_STATIC32) \ 21 if (OLD->type.type == PS_TYPE_F32) { \ 22 NEW_PTR32 = (psVector *) OLD; \ 23 } else if (OLD->type.type == PS_TYPE_F64) { \ 24 NEW_STATIC32 = psVectorRecycle(NEW_STATIC32, OLD->n, PS_TYPE_F32); \ 25 p_psMemSetPersistent(NEW_STATIC32, true); \ 26 p_psMemSetPersistent(NEW_STATIC32->data.V, true); \ 27 for (i=0; i < OLD->n ; i++) { \ 28 NEW_STATIC32->data.F32[i] = (float) OLD->data.F64[i]; \ 29 } \ 30 NEW_PTR32 = NEW_STATIC32; \ 31 } \ 32 33 #define CONVERT_VECTOR_F32_TO_F64(OLD, NEW_PTR64, NEW_STATIC64) \ 34 if (OLD->type.type == PS_TYPE_F64) { \ 35 NEW_PTR64 = (psVector *) OLD; \ 36 } else if (OLD->type.type == PS_TYPE_F32) { \ 37 NEW_STATIC64 = psVectorRecycle(NEW_STATIC64, OLD->n, PS_TYPE_F64); \ 38 p_psMemSetPersistent(NEW_STATIC64, true); \ 39 p_psMemSetPersistent(NEW_STATIC64->data.V, true); \ 40 for (i=0; i < OLD->n ; i++) { \ 41 NEW_STATIC64->data.F64[i] = (double) OLD->data.F32[i]; \ 42 } \ 43 NEW_PTR64 = NEW_STATIC64; \ 44 } \ 45 46 #define VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(VEC) \ 47 if ((VEC->type.type != PS_TYPE_F32) && (VEC->type.type != PS_TYPE_F64)) { \ 48 psAbort(__func__, "Bad type for VEC (%d)", VEC->type.type); \ 49 return(NULL); \ 50 } \ 51 52 #define GEN_PERSIST_YERR_VEC_F32(VEC, N) \ 53 VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \ 54 p_psMemSetPersistent(VEC, true); \ 55 p_psMemSetPersistent(VEC->data.V, true); \ 56 for (int i=0;i<N;i++) { \ 57 VEC->data.F32[i] = 1.0; \ 58 } \ 59 60 #define GEN_PERSIST_YERR_VEC_F64(VEC, N) \ 61 VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \ 62 p_psMemSetPersistent(VEC, true); \ 63 p_psMemSetPersistent(VEC->data.V, true); \ 64 for (int i=0;i<N;i++) { \ 65 VEC->data.F64[i] = 1.0; \ 66 } \ 67 68 #define GEN_PERSIST_X_INDEX_VEC_F32(VEC, N) \ 69 VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \ 70 p_psMemSetPersistent(VEC, true); \ 71 p_psMemSetPersistent(VEC->data.V, true); \ 72 for (int i=0;i<N;i++) { \ 73 VEC->data.F32[i] = (float) i; \ 74 } \ 75 76 #define GEN_PERSIST_X_INDEX_VEC_F64(VEC, N) \ 77 VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \ 78 p_psMemSetPersistent(VEC, true); \ 79 p_psMemSetPersistent(VEC->data.V, true); \ 80 for (int i=0;i<N;i++) { \ 81 VEC->data.F64[i] = (float) i; \ 82 } \ 83 20 84 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \ 21 85 static psVector *NAME = NULL; \ … … 23 87 p_psMemSetPersistent(NAME, true); \ 24 88 p_psMemSetPersistent(NAME->data.V, true); \ 25 26 27 28 89 29 90 /** Preprocessor macro to generate error on an incorrect type */ … … 51 112 } 52 113 114 /** Preprocessor macro to generate error on a NULL vector */ 115 #define PS_CHECK_NULL_VECTOR_RETURN_NULL(NAME) \ 116 if (NAME == NULL || NAME->data.V == NULL) { \ 117 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 118 return(NULL); \ 119 } \ 120 53 121 /** Preprocessor macro to generate error on a NULL poniter */ 54 122 #define PS_CHECK_NULL_PTR(NAME) \ 55 123 if (NAME == NULL) { \ 56 124 psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \ 125 } 126 127 /** Preprocessor macro to generate error on a NULL poniter */ 128 #define PS_CHECK_NULL_PTR_RETURN_NULL(NAME) \ 129 if (NAME == NULL) { \ 130 psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \ 131 return(NULL); \ 57 132 } 58 133 … … 75 150 } 76 151 152 /** Preprocessor macro to generate error for zero length vector */ 153 #define PS_CHECK_EMPTY_VECTOR_RETURN_NULL(NAME) \ 154 if (NAME->n < 1) { \ 155 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 156 return(NULL); \ 157 } \ 158 77 159 /** Preprocessor macro to generate error on differing size vectors */ 78 160 #define PS_CHECK_VECTOR_SIZE_EQUAL(VEC1, VEC2) \ 79 161 if (VEC1->n != VEC2->n) { \ 80 162 psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \ 163 } 164 165 /** Preprocessor macro to generate error on differing size vectors */ 166 #define PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(VEC1, VEC2) \ 167 if (VEC1->n != VEC2->n) { \ 168 psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \ 169 return(NULL); \ 81 170 } 82 171 … … 112 201 } 113 202 203 #define PS_CHECK_NULL_1DPOLY_RETURN_NULL(NAME) \ 204 if (NAME == NULL || NAME->coeff == NULL) { \ 205 psError(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME); \ 206 return(NULL); \ 207 } \ 208 114 209 #define PS_PRINT_VECTOR(NAME) \ 115 210 for (int my_i=0;my_i<NAME->n;my_i++) { \ -
trunk/psLib/src/dataManip/psMinimize.c
r1953 r1963 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.5 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-05 01:43:58$11 * @version $Revision: 1.53 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-05 22:47:21 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 56 56 57 57 XXX: change name 58 XXX: Use a static vector. 58 59 *****************************************************************************/ 59 60 void p_psBuildSums1D(double x, … … 63 64 int i = 0; 64 65 double xSum = 0.0; 66 65 67 if (sums == NULL) { 66 68 sums = psVectorAlloc(polyOrder, PS_TYPE_F64); 69 } 70 71 if (polyOrder > sums->n) { 72 sums = psVectorRealloc(sums, polyOrder); 67 73 } 68 74 … … 77 83 VectorNormalizeGen(): this routine returns a psVector with "x" elements. The 78 84 values of the vector will be scaled uniformly between -1.0 and 1.0. 85 86 XXX: use a static vector. 79 87 *****************************************************************************/ 80 88 psVector* VectorNormalizeGen(int x) … … 100 108 101 109 XXX: This algorithm is derived from the Numerical Recipes. 110 XXX: use recyvled vectors for internal data. 102 111 *****************************************************************************/ 103 112 float *CalculateSecondDerivs(const psVector* restrict x, ///< Ordinates (or NULL to just use the indices) … … 119 128 float qn; 120 129 121 if (x == NULL) {122 X = (float *) psAlloc(n * sizeof(float));123 for(i=0;i<n;i++) {124 X[i] = (float) i;125 }126 mustFreeX = true;127 }128 129 130 // XXX: The second derivatives at the endpoints, undefined in the SDR, 130 131 // are set in psConstants.h: LEFT_SPLINE_DERIV, RIGHT_SPLINE_DERIV. … … 167 168 return(derivs2); 168 169 } 169 170 170 171 171 /****************************************************************************** … … 212 212 } 213 213 214 215 214 /*****************************************************************************/ 216 215 /* FUNCTION IMPLEMENTATION - PUBLIC */ … … 258 257 int i; 259 258 float slope; 260 261 if (mySpline == NULL) { 262 //XXX psErrorMsg() 263 } 264 if (y == NULL) { 265 //XXX psErrorMsg() 266 } 259 psVector *x32 = NULL; 260 psVector *y32 = NULL; 261 psVector *yErr32 = NULL; 262 static psVector *x32Static = NULL; 263 static psVector *y32Static = NULL; 264 static psVector *yErr32Static = NULL; 265 266 PS_CHECK_NULL_PTR_RETURN_NULL(mySpline); 267 PS_CHECK_NULL_PTR_RETURN_NULL(y); 268 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y); 269 CONVERT_VECTOR_F64_TO_F32(y, y32, y32Static); 270 271 // If yErr==NULL, set all errors equal. 272 if (yErr == NULL) { 273 GEN_PERSIST_YERR_VEC_F32(yErr32Static, y->n); 274 yErr32 = yErr32Static; 275 } else { 276 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr); 277 CONVERT_VECTOR_F64_TO_F32(yErr, yErr32, yErr32Static); 278 } 279 280 // If x==NULL, create an x32 vector with x values set to (0:n). 281 if (x == NULL) { 282 GEN_PERSIST_X_INDEX_VEC_F32(x32Static, y->n); 283 x32 = x32Static; 284 } else { 285 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x); 286 CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static); 287 } 288 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x, y); 289 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr, y); 267 290 268 291 if (y->n != (1 + mySpline->n)) { 269 psLogMsg(__func__, PS_LOG_WARN, 270 "data size / spline size mismatch (%d %d)\n", 271 y->n, mySpline->n); 272 // XXX: psErrorMsg() 292 psError(__func__, "data size / spline size mismatch (%d %d)\n", 293 y->n, mySpline->n); 294 return(NULL); 273 295 } 274 296 … … 295 317 // Check if these are cubic splines (n==4). If not, psError. 296 318 if (4 != (mySpline->spline[0])->n) { 297 psLogMsg(__func__, PS_LOG_WARN, 298 "Don't know how to generate %d-order splines.", 299 (mySpline->spline[0])->n-1); 300 // XXX: psErrorMsg() 319 psError(__func__, "Don't know how to generate %d-order splines.", 320 (mySpline->spline[0])->n-1); 301 321 return(NULL); 302 322 } … … 315 335 H = x->data.F32[i+1] - x->data.F32[i]; 316 336 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 317 " Xdata (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);337 "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H); 318 338 // 319 339 // ******** Calculate 0-order term ******** … … 630 650 } 631 651 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 638 639 652 /****************************************************************************** 640 653 p_psVectorFitPolynomial1DCheb(): This routine will fit a Chebyshev … … 854 867 int i; 855 868 psPolynomial1D *tmpPoly; 856 PS_CHECK_NULL_1DPOLY_ ACTION(myPoly, 0);857 PS_CHECK_NULL_VECTOR_ ACTION(y, 0);858 PS_CHECK_EMPTY_VECTOR_ ACTION(y, 0);869 PS_CHECK_NULL_1DPOLY_RETURN_NULL(myPoly); 870 PS_CHECK_NULL_VECTOR_RETURN_NULL(y); 871 PS_CHECK_EMPTY_VECTOR_RETURN_NULL(y); 859 872 psVector *x64 = NULL; 860 873 psVector *y64 = NULL; … … 864 877 static psVector *yErr64Static = NULL; 865 878 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 879 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y); 880 CONVERT_VECTOR_F32_TO_F64(y, y64, y64Static); 878 881 879 882 // If yErr==NULL, set all errors equal. 880 883 if (yErr == NULL) { 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 } 884 GEN_PERSIST_YERR_VEC_F64(yErr64Static, y->n); 888 885 yErr64 = yErr64Static; 889 886 } else { 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 903 // this is a Chebyshev polynomial, we must scale to (-1:1). 904 // XXX: Verify that this is the correct action. 887 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr); 888 CONVERT_VECTOR_F32_TO_F64(yErr, yErr64, yErr64Static); 889 } 890 891 // If x==NULL, create an x64 vector with x values set to (0:n). 905 892 if (x == NULL) { 906 x64Static = psVectorRecycle(x64Static, y->n, PS_TYPE_F64); 907 p_psMemSetPersistent(x64Static, true); 908 p_psMemSetPersistent(x64Static->data.V, true); 893 GEN_PERSIST_X_INDEX_VEC_F64(x64Static, y->n); 894 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 895 p_psNormalizeVector(x64Static); 896 } 909 897 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));922 }923 }924 898 } else { 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); 899 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x); 900 CONVERT_VECTOR_F32_TO_F64(x, x64, x64Static); 901 } 902 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x64, y64); 903 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr64, y64); 940 904 941 905 // Call the appropriate vector fitting routine. 942 906 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 943 tmpPoly =p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);907 p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64); 944 908 } else if (myPoly->type == PS_POLYNOMIAL_ORD) { 945 909 tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64); … … 948 912 return(NULL); 949 913 } 950 951 // Free any allocated memory.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 */963 914 964 915 return(myPoly); -
trunk/psLib/src/dataManip/psMinimize.h
r1953 r1963 8 8 * @author George Gusciora, MHPCC 9 9 * 10 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-10-05 01:43:58$10 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-10-05 22:47:21 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 #include "psMatrix.h" 29 29 #include "psFunctions.h" 30 #include "psStats.h" 30 31 #include "psTrace.h" 31 32 #include "psLogMsg.h" -
trunk/psLib/src/dataManip/psStats.c
r1928 r1963 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.6 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004- 09-29 19:52:53$11 * @version $Revision: 1.64 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-05 22:47:21 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 836 836 837 837 /***************************************************************************** 838 p_psNormalizeVector (myData): this is a private function which normalizes the838 p_psNormalizeVectorF32(myData): this is a private function which normalizes the 839 839 elements of a vector to a range between 0.0 and 1.0. 840 840 *****************************************************************************/ 841 void p_psNormalizeVector (psVector* myData)841 void p_psNormalizeVectorF32(psVector* myData) 842 842 { 843 843 float min = (float)HUGE; … … 867 867 p_psNormalizeVectorF64(myData): this is a private function which normalizes the 868 868 elements of a vector to a range between -1.0 and 1.0. 869 870 XXX: incorporate this into above871 872 869 XXX: 0-1 or -1:1? 873 870 *****************************************************************************/ 874 871 void p_psNormalizeVectorF64(psVector* myData) 875 872 { 876 float min = ( float)HUGE;877 float max = ( float)-HUGE;878 floatrange = 0.0;873 float min = (double)HUGE; 874 float max = (double)-HUGE; 875 double range = 0.0; 879 876 int i = 0; 880 877 … … 892 889 myData->data.F64[i] = -1.0 + 2.0 * 893 890 ((myData->data.F64[i] - min) / range); 891 } 892 893 // for (i = 0; i < myData->n; i++) { 894 // myData->data.F64[i] = (myData->data.F64[i] - 0.5 * (min + max)) / 895 // (0.5 * (max - min)); 896 // } 897 } 898 899 void p_psNormalizeVector(psVector* myData) 900 { 901 if (myData->type.type == PS_TYPE_F32) { 902 p_psNormalizeVectorF32(myData); 903 } else if (myData->type.type == PS_TYPE_F64) { 904 p_psNormalizeVectorF64(myData); 905 } else { 906 psError(__func__, "Unalowable data type.\n"); 894 907 } 895 908 } … … 1191 1204 // The following was necessary to fit a gaussian to the data, since 1192 1205 // gaussian functions produce data between 0.0 and 1.0. 1193 // p_psNormalizeVector (robustHistogramVector);1206 // p_psNormalizeVectorF32(robustHistogramVector); 1194 1207 1195 1208 /************************************************************************** -
trunk/psLib/src/dataManip/psStats.h
r1907 r1963 10 10 * @author George Gusciora, MHPCC 11 11 * 12 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $13 * @date $Date: 2004- 09-27 23:41:42$12 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-10-05 22:47:21 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 176 176 177 177 void p_psNormalizeVector(psVector* myData); 178 void p_psNormalizeVectorF64(psVector* myData);179 180 178 181 179 /// @} -
trunk/psLib/src/math/psConstants.h
r1953 r1963 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-05 01:43:58$8 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-05 22:47:21 $ 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 CONVERT_VECTOR_F64_TO_F32(OLD, NEW_PTR32, NEW_STATIC32) \ 21 if (OLD->type.type == PS_TYPE_F32) { \ 22 NEW_PTR32 = (psVector *) OLD; \ 23 } else if (OLD->type.type == PS_TYPE_F64) { \ 24 NEW_STATIC32 = psVectorRecycle(NEW_STATIC32, OLD->n, PS_TYPE_F32); \ 25 p_psMemSetPersistent(NEW_STATIC32, true); \ 26 p_psMemSetPersistent(NEW_STATIC32->data.V, true); \ 27 for (i=0; i < OLD->n ; i++) { \ 28 NEW_STATIC32->data.F32[i] = (float) OLD->data.F64[i]; \ 29 } \ 30 NEW_PTR32 = NEW_STATIC32; \ 31 } \ 32 33 #define CONVERT_VECTOR_F32_TO_F64(OLD, NEW_PTR64, NEW_STATIC64) \ 34 if (OLD->type.type == PS_TYPE_F64) { \ 35 NEW_PTR64 = (psVector *) OLD; \ 36 } else if (OLD->type.type == PS_TYPE_F32) { \ 37 NEW_STATIC64 = psVectorRecycle(NEW_STATIC64, OLD->n, PS_TYPE_F64); \ 38 p_psMemSetPersistent(NEW_STATIC64, true); \ 39 p_psMemSetPersistent(NEW_STATIC64->data.V, true); \ 40 for (i=0; i < OLD->n ; i++) { \ 41 NEW_STATIC64->data.F64[i] = (double) OLD->data.F32[i]; \ 42 } \ 43 NEW_PTR64 = NEW_STATIC64; \ 44 } \ 45 46 #define VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(VEC) \ 47 if ((VEC->type.type != PS_TYPE_F32) && (VEC->type.type != PS_TYPE_F64)) { \ 48 psAbort(__func__, "Bad type for VEC (%d)", VEC->type.type); \ 49 return(NULL); \ 50 } \ 51 52 #define GEN_PERSIST_YERR_VEC_F32(VEC, N) \ 53 VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \ 54 p_psMemSetPersistent(VEC, true); \ 55 p_psMemSetPersistent(VEC->data.V, true); \ 56 for (int i=0;i<N;i++) { \ 57 VEC->data.F32[i] = 1.0; \ 58 } \ 59 60 #define GEN_PERSIST_YERR_VEC_F64(VEC, N) \ 61 VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \ 62 p_psMemSetPersistent(VEC, true); \ 63 p_psMemSetPersistent(VEC->data.V, true); \ 64 for (int i=0;i<N;i++) { \ 65 VEC->data.F64[i] = 1.0; \ 66 } \ 67 68 #define GEN_PERSIST_X_INDEX_VEC_F32(VEC, N) \ 69 VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \ 70 p_psMemSetPersistent(VEC, true); \ 71 p_psMemSetPersistent(VEC->data.V, true); \ 72 for (int i=0;i<N;i++) { \ 73 VEC->data.F32[i] = (float) i; \ 74 } \ 75 76 #define GEN_PERSIST_X_INDEX_VEC_F64(VEC, N) \ 77 VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \ 78 p_psMemSetPersistent(VEC, true); \ 79 p_psMemSetPersistent(VEC->data.V, true); \ 80 for (int i=0;i<N;i++) { \ 81 VEC->data.F64[i] = (float) i; \ 82 } \ 83 20 84 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \ 21 85 static psVector *NAME = NULL; \ … … 23 87 p_psMemSetPersistent(NAME, true); \ 24 88 p_psMemSetPersistent(NAME->data.V, true); \ 25 26 27 28 89 29 90 /** Preprocessor macro to generate error on an incorrect type */ … … 51 112 } 52 113 114 /** Preprocessor macro to generate error on a NULL vector */ 115 #define PS_CHECK_NULL_VECTOR_RETURN_NULL(NAME) \ 116 if (NAME == NULL || NAME->data.V == NULL) { \ 117 psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \ 118 return(NULL); \ 119 } \ 120 53 121 /** Preprocessor macro to generate error on a NULL poniter */ 54 122 #define PS_CHECK_NULL_PTR(NAME) \ 55 123 if (NAME == NULL) { \ 56 124 psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \ 125 } 126 127 /** Preprocessor macro to generate error on a NULL poniter */ 128 #define PS_CHECK_NULL_PTR_RETURN_NULL(NAME) \ 129 if (NAME == NULL) { \ 130 psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \ 131 return(NULL); \ 57 132 } 58 133 … … 75 150 } 76 151 152 /** Preprocessor macro to generate error for zero length vector */ 153 #define PS_CHECK_EMPTY_VECTOR_RETURN_NULL(NAME) \ 154 if (NAME->n < 1) { \ 155 psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \ 156 return(NULL); \ 157 } \ 158 77 159 /** Preprocessor macro to generate error on differing size vectors */ 78 160 #define PS_CHECK_VECTOR_SIZE_EQUAL(VEC1, VEC2) \ 79 161 if (VEC1->n != VEC2->n) { \ 80 162 psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \ 163 } 164 165 /** Preprocessor macro to generate error on differing size vectors */ 166 #define PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(VEC1, VEC2) \ 167 if (VEC1->n != VEC2->n) { \ 168 psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \ 169 return(NULL); \ 81 170 } 82 171 … … 112 201 } 113 202 203 #define PS_CHECK_NULL_1DPOLY_RETURN_NULL(NAME) \ 204 if (NAME == NULL || NAME->coeff == NULL) { \ 205 psError(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME); \ 206 return(NULL); \ 207 } \ 208 114 209 #define PS_PRINT_VECTOR(NAME) \ 115 210 for (int my_i=0;my_i<NAME->n;my_i++) { \ -
trunk/psLib/src/math/psMinimize.c
r1953 r1963 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.5 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-05 01:43:58$11 * @version $Revision: 1.53 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-05 22:47:21 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 56 56 57 57 XXX: change name 58 XXX: Use a static vector. 58 59 *****************************************************************************/ 59 60 void p_psBuildSums1D(double x, … … 63 64 int i = 0; 64 65 double xSum = 0.0; 66 65 67 if (sums == NULL) { 66 68 sums = psVectorAlloc(polyOrder, PS_TYPE_F64); 69 } 70 71 if (polyOrder > sums->n) { 72 sums = psVectorRealloc(sums, polyOrder); 67 73 } 68 74 … … 77 83 VectorNormalizeGen(): this routine returns a psVector with "x" elements. The 78 84 values of the vector will be scaled uniformly between -1.0 and 1.0. 85 86 XXX: use a static vector. 79 87 *****************************************************************************/ 80 88 psVector* VectorNormalizeGen(int x) … … 100 108 101 109 XXX: This algorithm is derived from the Numerical Recipes. 110 XXX: use recyvled vectors for internal data. 102 111 *****************************************************************************/ 103 112 float *CalculateSecondDerivs(const psVector* restrict x, ///< Ordinates (or NULL to just use the indices) … … 119 128 float qn; 120 129 121 if (x == NULL) {122 X = (float *) psAlloc(n * sizeof(float));123 for(i=0;i<n;i++) {124 X[i] = (float) i;125 }126 mustFreeX = true;127 }128 129 130 // XXX: The second derivatives at the endpoints, undefined in the SDR, 130 131 // are set in psConstants.h: LEFT_SPLINE_DERIV, RIGHT_SPLINE_DERIV. … … 167 168 return(derivs2); 168 169 } 169 170 170 171 171 /****************************************************************************** … … 212 212 } 213 213 214 215 214 /*****************************************************************************/ 216 215 /* FUNCTION IMPLEMENTATION - PUBLIC */ … … 258 257 int i; 259 258 float slope; 260 261 if (mySpline == NULL) { 262 //XXX psErrorMsg() 263 } 264 if (y == NULL) { 265 //XXX psErrorMsg() 266 } 259 psVector *x32 = NULL; 260 psVector *y32 = NULL; 261 psVector *yErr32 = NULL; 262 static psVector *x32Static = NULL; 263 static psVector *y32Static = NULL; 264 static psVector *yErr32Static = NULL; 265 266 PS_CHECK_NULL_PTR_RETURN_NULL(mySpline); 267 PS_CHECK_NULL_PTR_RETURN_NULL(y); 268 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y); 269 CONVERT_VECTOR_F64_TO_F32(y, y32, y32Static); 270 271 // If yErr==NULL, set all errors equal. 272 if (yErr == NULL) { 273 GEN_PERSIST_YERR_VEC_F32(yErr32Static, y->n); 274 yErr32 = yErr32Static; 275 } else { 276 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr); 277 CONVERT_VECTOR_F64_TO_F32(yErr, yErr32, yErr32Static); 278 } 279 280 // If x==NULL, create an x32 vector with x values set to (0:n). 281 if (x == NULL) { 282 GEN_PERSIST_X_INDEX_VEC_F32(x32Static, y->n); 283 x32 = x32Static; 284 } else { 285 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x); 286 CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static); 287 } 288 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x, y); 289 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr, y); 267 290 268 291 if (y->n != (1 + mySpline->n)) { 269 psLogMsg(__func__, PS_LOG_WARN, 270 "data size / spline size mismatch (%d %d)\n", 271 y->n, mySpline->n); 272 // XXX: psErrorMsg() 292 psError(__func__, "data size / spline size mismatch (%d %d)\n", 293 y->n, mySpline->n); 294 return(NULL); 273 295 } 274 296 … … 295 317 // Check if these are cubic splines (n==4). If not, psError. 296 318 if (4 != (mySpline->spline[0])->n) { 297 psLogMsg(__func__, PS_LOG_WARN, 298 "Don't know how to generate %d-order splines.", 299 (mySpline->spline[0])->n-1); 300 // XXX: psErrorMsg() 319 psError(__func__, "Don't know how to generate %d-order splines.", 320 (mySpline->spline[0])->n-1); 301 321 return(NULL); 302 322 } … … 315 335 H = x->data.F32[i+1] - x->data.F32[i]; 316 336 psTrace(".psLib.dataManip.psVectorFitSpline1D", 4, 317 " Xdata (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);337 "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H); 318 338 // 319 339 // ******** Calculate 0-order term ******** … … 630 650 } 631 651 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 638 639 652 /****************************************************************************** 640 653 p_psVectorFitPolynomial1DCheb(): This routine will fit a Chebyshev … … 854 867 int i; 855 868 psPolynomial1D *tmpPoly; 856 PS_CHECK_NULL_1DPOLY_ ACTION(myPoly, 0);857 PS_CHECK_NULL_VECTOR_ ACTION(y, 0);858 PS_CHECK_EMPTY_VECTOR_ ACTION(y, 0);869 PS_CHECK_NULL_1DPOLY_RETURN_NULL(myPoly); 870 PS_CHECK_NULL_VECTOR_RETURN_NULL(y); 871 PS_CHECK_EMPTY_VECTOR_RETURN_NULL(y); 859 872 psVector *x64 = NULL; 860 873 psVector *y64 = NULL; … … 864 877 static psVector *yErr64Static = NULL; 865 878 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 879 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y); 880 CONVERT_VECTOR_F32_TO_F64(y, y64, y64Static); 878 881 879 882 // If yErr==NULL, set all errors equal. 880 883 if (yErr == NULL) { 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 } 884 GEN_PERSIST_YERR_VEC_F64(yErr64Static, y->n); 888 885 yErr64 = yErr64Static; 889 886 } else { 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 903 // this is a Chebyshev polynomial, we must scale to (-1:1). 904 // XXX: Verify that this is the correct action. 887 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr); 888 CONVERT_VECTOR_F32_TO_F64(yErr, yErr64, yErr64Static); 889 } 890 891 // If x==NULL, create an x64 vector with x values set to (0:n). 905 892 if (x == NULL) { 906 x64Static = psVectorRecycle(x64Static, y->n, PS_TYPE_F64); 907 p_psMemSetPersistent(x64Static, true); 908 p_psMemSetPersistent(x64Static->data.V, true); 893 GEN_PERSIST_X_INDEX_VEC_F64(x64Static, y->n); 894 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 895 p_psNormalizeVector(x64Static); 896 } 909 897 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));922 }923 }924 898 } else { 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); 899 VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x); 900 CONVERT_VECTOR_F32_TO_F64(x, x64, x64Static); 901 } 902 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x64, y64); 903 PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr64, y64); 940 904 941 905 // Call the appropriate vector fitting routine. 942 906 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 943 tmpPoly =p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);907 p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64); 944 908 } else if (myPoly->type == PS_POLYNOMIAL_ORD) { 945 909 tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64); … … 948 912 return(NULL); 949 913 } 950 951 // Free any allocated memory.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 */963 914 964 915 return(myPoly); -
trunk/psLib/src/math/psMinimize.h
r1953 r1963 8 8 * @author George Gusciora, MHPCC 9 9 * 10 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-10-05 01:43:58$10 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-10-05 22:47:21 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 #include "psMatrix.h" 29 29 #include "psFunctions.h" 30 #include "psStats.h" 30 31 #include "psTrace.h" 31 32 #include "psLogMsg.h" -
trunk/psLib/src/math/psStats.c
r1928 r1963 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.6 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004- 09-29 19:52:53$11 * @version $Revision: 1.64 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-05 22:47:21 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 836 836 837 837 /***************************************************************************** 838 p_psNormalizeVector (myData): this is a private function which normalizes the838 p_psNormalizeVectorF32(myData): this is a private function which normalizes the 839 839 elements of a vector to a range between 0.0 and 1.0. 840 840 *****************************************************************************/ 841 void p_psNormalizeVector (psVector* myData)841 void p_psNormalizeVectorF32(psVector* myData) 842 842 { 843 843 float min = (float)HUGE; … … 867 867 p_psNormalizeVectorF64(myData): this is a private function which normalizes the 868 868 elements of a vector to a range between -1.0 and 1.0. 869 870 XXX: incorporate this into above871 872 869 XXX: 0-1 or -1:1? 873 870 *****************************************************************************/ 874 871 void p_psNormalizeVectorF64(psVector* myData) 875 872 { 876 float min = ( float)HUGE;877 float max = ( float)-HUGE;878 floatrange = 0.0;873 float min = (double)HUGE; 874 float max = (double)-HUGE; 875 double range = 0.0; 879 876 int i = 0; 880 877 … … 892 889 myData->data.F64[i] = -1.0 + 2.0 * 893 890 ((myData->data.F64[i] - min) / range); 891 } 892 893 // for (i = 0; i < myData->n; i++) { 894 // myData->data.F64[i] = (myData->data.F64[i] - 0.5 * (min + max)) / 895 // (0.5 * (max - min)); 896 // } 897 } 898 899 void p_psNormalizeVector(psVector* myData) 900 { 901 if (myData->type.type == PS_TYPE_F32) { 902 p_psNormalizeVectorF32(myData); 903 } else if (myData->type.type == PS_TYPE_F64) { 904 p_psNormalizeVectorF64(myData); 905 } else { 906 psError(__func__, "Unalowable data type.\n"); 894 907 } 895 908 } … … 1191 1204 // The following was necessary to fit a gaussian to the data, since 1192 1205 // gaussian functions produce data between 0.0 and 1.0. 1193 // p_psNormalizeVector (robustHistogramVector);1206 // p_psNormalizeVectorF32(robustHistogramVector); 1194 1207 1195 1208 /************************************************************************** -
trunk/psLib/src/math/psStats.h
r1907 r1963 10 10 * @author George Gusciora, MHPCC 11 11 * 12 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $13 * @date $Date: 2004- 09-27 23:41:42$12 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-10-05 22:47:21 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 176 176 177 177 void p_psNormalizeVector(psVector* myData); 178 void p_psNormalizeVectorF64(psVector* myData);179 180 178 181 179 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
