Changeset 6186
- Timestamp:
- Jan 23, 2006, 12:25:31 PM (20 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 9 edited
-
astro/psCoord.c (modified) (2 diffs)
-
imageops/psImageStats.c (modified) (3 diffs)
-
math/psConstants.h (modified) (4 diffs)
-
math/psMinimizePolyFit.c (modified) (96 diffs)
-
math/psMinimizePowell.c (modified) (4 diffs)
-
math/psPolynomial.c (modified) (17 diffs)
-
math/psPolynomial.h (modified) (6 diffs)
-
math/psSpline.c (modified) (4 diffs)
-
math/psStats.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psCoord.c
r5841 r6186 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1. 99$ $Name: not supported by cvs2svn $13 * @date $Date: 200 5-12-24 00:33:13$12 * @version $Revision: 1.100 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-01-23 22:25:31 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 925 925 return(p_psPlaneTransformLinearInvert((psPlaneTransform *) in)); 926 926 } 927 PS_ INT_COMPARE(1, nSamples, NULL);927 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(nSamples, 1, NULL); 928 928 929 929 // Ensure that the input transformation is symmetrical. -
trunk/psLib/src/imageops/psImageStats.c
r5841 r6186 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.8 6$ $Name: not supported by cvs2svn $12 * @date $Date: 200 5-12-24 00:33:17$11 * @version $Revision: 1.87 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-01-23 22:25:31 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 212 212 213 213 return (scalingFactors); 214 }215 216 // XXX: Use a static array of Chebyshev polynomials.217 psPolynomial1D **p_psCreateChebyshevPolys(psS32 maxChebyPoly)218 {219 PS_ASSERT_INT_POSITIVE(maxChebyPoly, NULL);220 psPolynomial1D **chebPolys = NULL;221 psS32 i = 0;222 psS32 j = 0;223 224 chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));225 for (i = 0; i < maxChebyPoly; i++) {226 // XXX: verify this, poly nOrder/nTerms change.227 chebPolys[i] = psPolynomial1DAlloc(i, PS_POLYNOMIAL_ORD);228 }229 230 // Create the Chebyshev polynomials.231 // Polynomial i has i-th order.232 chebPolys[0]->coeff[0] = 1;233 chebPolys[1]->coeff[1] = 1;234 for (i = 2; i < maxChebyPoly; i++) {235 for (j = 0; j < (1 + chebPolys[i - 1]->nX); j++) {236 chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];237 }238 for (j = 0; j < (1 + chebPolys[i - 2]->nX); j++) {239 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];240 }241 }242 243 return (chebPolys);244 214 } 245 215 … … 302 272 // Determine how many Chebyshev polynomials 303 273 // are needed, then create them. 304 // XXX: record eor verify the poly order/nterm change274 // XXX: record or verify the poly order/nterm change 305 275 maxChebyPoly = coeffs->nX; 306 276 if (coeffs->nY > coeffs->nX) { -
trunk/psLib/src/math/psConstants.h
r5588 r6186 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.8 1$ $Name: not supported by cvs2svn $9 * @date $Date: 200 5-11-23 23:54:43$8 * @version $Revision: 1.82 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-01-23 22:25:31 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 14 14 * called with complex expressions. 15 15 * 16 * XXX: All functions which use the PS_ CHECKmacros must be scrutinized so16 * XXX: All functions which use the PS_ASSERT macros must be scrutinized so 17 17 * that we ensure that an argument which is expected to be output is 18 18 * psFree'ed before reurning NULL. … … 21 21 * throw a psError if the CONDITION is true. However, some throw the error 22 22 * if the CONDITION is false. This should be consistant. 23 *24 * XXX: rename all these with form PS_ASSERT_CONDITION().25 23 * 26 24 */ … … 156 154 } 157 155 158 // Produce an error if (NAME1 > NAME2)159 // XXX: Get rid of this, use above macros.160 #define PS_INT_COMPARE(NAME1, NAME2, RVAL) \161 if ((NAME1) > (NAME2)) { \162 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \163 "Error: (%s > %s) (%d %d).", \164 #NAME1, #NAME2, NAME1, NAME2); \165 return(RVAL); \166 }167 168 // Produce an error if ((NAME1 > NAME2)169 // XXX: Get rid of this, use above macros.170 #define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \171 if ((NAME1) > (NAME2)) { \172 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \173 "Error: (%s > %s) (%f %f)", \174 #NAME1, #NAME2, NAME1, NAME2); \175 return(RVAL); \176 }177 178 156 #define PS_ASSERT_FLOAT_NON_EQUAL(NAME1, NAME2, RVAL) \ 179 157 if (fabs((NAME2) - (NAME1)) < FLT_EPSILON) { \ -
trunk/psLib/src/math/psMinimizePolyFit.c
r6185 r6186 10 10 * @author EAM, IfA 11 11 * 12 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-01-23 2 0:44:29$12 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-01-23 22:25:31 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 16 16 * 17 * XXX: must follow coding name standards on local functions.18 * XXX: put local functions in front.19 17 * XXX: For clip-fit functions, what should we do if the mask is NULL? 20 * XXX: Generate macros for21 * PS_ASSERT_VECTOR_TYPES_MATCH()22 * PS_ASSERT_VECTOR_SIZES_MATCH()23 * They should have better error messages.24 18 * 25 19 */ … … 42 36 /*****************************************************************************/ 43 37 38 #define PS_VECTOR_GEN_CHEBY_INDEX(VEC, SIZE, TYPE) \ 39 VEC = psVectorAlloc(SIZE, TYPE); \ 40 if (TYPE == PS_TYPE_F64) { \ 41 for (psS32 i = 0 ; i < SIZE ; i++) { \ 42 VEC->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \ 43 }\ 44 } else if (TYPE == PS_TYPE_F32){ \ 45 for (psS32 i = 0 ; i < SIZE ; i++) { \ 46 VEC->data.F32[i] = ((2.0 / ((psF32) (SIZE - 1))) * ((psF32) i)) - 1.0; \ 47 }\ 48 }\ 49 44 50 /*****************************************************************************/ 45 51 /* TYPE DEFINITIONS */ … … 58 64 /*****************************************************************************/ 59 65 60 /******************************************************************************61 ******************************************************************************62 Analytical 1-D fitting routines.63 ******************************************************************************64 *****************************************************************************/65 // XXX: Make this a general type conversion macro, or function66 #define PS_VECTOR_GEN_F64_FROM_F32(VECF64, VECF32) \67 VECF64 = psVectorAlloc(VECF32->n, PS_TYPE_F64); \68 for (psS32 i = 0 ; i < VECF32->n ; i++) { \69 VECF64->data.F64[i] = (psF64) VECF32->data.F32[i]; \70 } \71 72 // XXX: Consolidate these73 #define PS_VECTOR_GEN_CHEBY_INDEX(VECF64, SIZE) \74 VECF64 = psVectorAlloc(SIZE, PS_TYPE_F64); \75 for (psS32 i = 0 ; i < SIZE ; i++) { \76 VECF64->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \77 }\78 79 #define PS_VECTOR_GEN_CHEBY_INDEX_F64(VECF64, SIZE) \80 VECF64 = psVectorAlloc(SIZE, PS_TYPE_F64); \81 for (psS32 i = 0 ; i < SIZE ; i++) { \82 VECF64->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \83 }\84 85 #define PS_VECTOR_GEN_CHEBY_INDEX_F32(VECF32, SIZE) \86 VECF32 = psVectorAlloc(SIZE, PS_TYPE_F32); \87 for (psS32 i = 0 ; i < SIZE ; i++) { \88 VECF32->data.F32[i] = ((2.0 / ((psF32) (SIZE - 1))) * ((psF32) i)) - 1.0; \89 }\90 66 /****************************************************************************** 91 67 BuildSums1D(sums, x, polyOrder, sums): this routine calculates the powers of … … 113 89 114 90 xSum = 1.0; 115 for ( inti = 0; i < nSum; i++) {91 for (psS32 i = 0; i < nSum; i++) { 116 92 sums->data.F64[i] = xSum; 117 93 xSum *= x; … … 148 124 149 125 xSum = 1.0; 150 for ( inti = 0; i < nXsum; i++) {126 for (psS32 i = 0; i < nXsum; i++) { 151 127 ySum = xSum; 152 for ( intj = 0; j < nYsum; j++) {128 for (psS32 j = 0; j < nYsum; j++) { 153 129 sums->data.F64[i][j] = ySum; 154 130 ySum *= y; 155 131 } 156 132 xSum *= x; 157 }158 159 if (0) {160 printf("--------------------- BuildSums2D(%.2f %.2f) ---------------------\n", x, y);161 for (int i = 0; i < nXsum; i++) {162 for (int j = 0; j < nYsum; j++) {163 printf("(%.2f) ", sums->data.F64[i][j]);164 }165 printf("\n");166 }167 133 } 168 134 … … 196 162 if (sums == NULL) { 197 163 sums = (psF64 ***) psAlloc (nXsum*sizeof(psF64)); 198 for ( inti = 0; i < nXsum; i++) {164 for (psS32 i = 0; i < nXsum; i++) { 199 165 sums[i] = (psF64 **) psAlloc (nYsum*sizeof(psF64)); 200 for ( intj = 0; j < nYsum; j++) {166 for (psS32 j = 0; j < nYsum; j++) { 201 167 sums[i][j] = (psF64 *) psAlloc (nZsum*sizeof(psF64)); 202 168 } … … 207 173 if (1) { 208 174 zSum = 1.0; 209 for ( intk = 0; k < nZsum; k++) {175 for (psS32 k = 0; k < nZsum; k++) { 210 176 ySum = zSum; 211 for ( intj = 0; j < nYsum; j++) {177 for (psS32 j = 0; j < nYsum; j++) { 212 178 xSum = ySum; 213 for ( inti = 0; i < nXsum; i++) {179 for (psS32 i = 0; i < nXsum; i++) { 214 180 sums[i][j][k] = xSum; 215 181 xSum *= x; … … 221 187 } else { 222 188 xSum = 1.0; 223 for ( inti = 0; i < nXsum; i++) {189 for (psS32 i = 0; i < nXsum; i++) { 224 190 ySum = xSum; 225 for ( intj = 0; j < nYsum; j++) {191 for (psS32 j = 0; j < nYsum; j++) { 226 192 zSum = ySum; 227 for ( intk = 0; k < nZsum; k++) {193 for (psS32 k = 0; k < nZsum; k++) { 228 194 sums[i][j][k] = zSum; 229 195 zSum *= z; … … 240 206 /****************************************************************************** 241 207 BuildSums4D(sums, x, y, z, t, nXterm, nYterm, nZterm, nTterm). equiv to 242 BuildSums2D(). The result is returned as a double****208 BuildSums2D(). The result is returned as a psF64 **** 243 209 *****************************************************************************/ 244 210 static psF64 ****BuildSums4D( … … 268 234 if (sums == NULL) { 269 235 sums = (psF64 ****) psAlloc (nXsum*sizeof(psF64)); 270 for ( inti = 0; i < nXsum; i++) {236 for (psS32 i = 0; i < nXsum; i++) { 271 237 sums[i] = (psF64 ***) psAlloc (nYsum*sizeof(psF64)); 272 for ( intj = 0; j < nYsum; j++) {238 for (psS32 j = 0; j < nYsum; j++) { 273 239 sums[i][j] = (psF64 **) psAlloc (nZsum*sizeof(psF64)); 274 for ( intk = 0; k < nZsum; k++) {240 for (psS32 k = 0; k < nZsum; k++) { 275 241 sums[i][j][k] = (psF64 *) psAlloc (nTsum*sizeof(psF64)); 276 242 } … … 281 247 282 248 tSum = 1.0; 283 for ( intm = 0; m < nTsum; m++) {249 for (psS32 m = 0; m < nTsum; m++) { 284 250 zSum = tSum; 285 for ( intk = 0; k < nZsum; k++) {251 for (psS32 k = 0; k < nZsum; k++) { 286 252 ySum = zSum; 287 for ( intj = 0; j < nYsum; j++) {253 for (psS32 j = 0; j < nYsum; j++) { 288 254 xSum = ySum; 289 for ( inti = 0; i < nXsum; i++) {255 for (psS32 i = 0; i < nXsum; i++) { 290 256 sums[i][j][k][m] = xSum; 291 257 xSum *= x; … … 299 265 return (sums); 300 266 } 267 268 /****************************************************************************** 269 ****************************************************************************** 270 Analytical 1-D fitting routines. 271 ****************************************************************************** 272 *****************************************************************************/ 273 301 274 302 275 /****************************************************************************** … … 356 329 NUM_DATA = x->n; 357 330 } 358 // XX:psTrace printf("vectorFitPolynomial1DChebySlow(): NUM_DATA is %d\n", NUM_DATA);359 360 psPolynomial1D **chebPolys = createChebyshevPolys(NUM_POLY);331 // psTrace printf("vectorFitPolynomial1DChebySlow(): NUM_DATA is %d\n", NUM_DATA); 332 333 psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(NUM_POLY); 361 334 if (0) { 362 335 for (psS32 j = 0; j < NUM_POLY; j++) { … … 416 389 } 417 390 418 // GaussJordan version419 391 if (0) { 420 // does the solution in place 421 // XXX: Check error codes! 422 psGaussJordan (A, B); 423 424 // the first nTerm entries in B correspond directly to the desired 425 // polynomial coefficients. this is only true for the 1D case 426 for (psS32 k = 0; k < NUM_POLY; k++) { 427 myPoly->coeff[k] = B->data.F64[k]; 392 // GaussJordan version 393 if (false == psGaussJordan(A, B)) { 394 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n"); 395 psFree(myPoly); 396 myPoly = NULL; 397 } else { 398 // the first nTerm entries in B correspond directly to the desired 399 // polynomial coefficients. this is only true for the 1D case 400 for (psS32 k = 0; k < NUM_POLY; k++) { 401 myPoly->coeff[k] = B->data.F64[k]; 402 } 428 403 } 429 404 } else { … … 433 408 psVector* coeffs = NULL; 434 409 410 // XXX: Check return codes. 435 411 ALUD = psImageAlloc(NUM_POLY, NUM_POLY, PS_TYPE_F64); 436 412 ALUD = psMatrixLUD(ALUD, &outPerm, A); … … 468 444 the [-1:1] interval. 469 445 470 XXX: mask, maskValue, yErr are currently ignored.446 NOTE: mask, maskValue, yErr are ignored with this function. 471 447 *****************************************************************************/ 472 448 static psPolynomial1D *vectorFitPolynomial1DChebyFast( … … 501 477 tmpScalar.type.type = PS_TYPE_F64; 502 478 503 // XXX:These assignments appear too simple to warrant code and479 // These assignments appear too simple to warrant code and 504 480 // variable declarations. I retain them here to maintain coherence 505 481 // with the NR code. … … 538 514 fScalar = p_psVectorInterpolate((psVector *) x, (psVector *) y, 539 515 3, &tmpScalar); 516 if (fScalar == NULL) { 517 psError(PS_ERR_UNKNOWN, false, "Could not perform vector interpolation. Returning NULL.\n"); 518 psFree(myPoly) 519 return(NULL); 520 } 521 540 522 f->data.F64[i] = fScalar->data.F64; 541 523 psFree(fScalar); 542 524 } 543 525 544 psTrace(".psLib.dataManip.vectorFitPolynomial1DCheby", 6, 545 "(x, X, y, f(X)) is (%f, %f, %f, %f)\n", 526 psTrace(__func__, 6, "(x, X, y, f(X)) is (%f, %f, %f, %f)\n", 546 527 x->data.F64[i], X, y->data.F64[i], f->data.F64[i]); 547 528 } … … 551 532 552 533 fac = 2.0/((psF32) n); 553 // XXX: is this loop bound correct?554 534 for (j=0;j<myPoly->nX+1;j++) { 555 535 sum = 0.0; … … 573 553 PS_TYPE_F64. 574 554 *****************************************************************************/ 575 psPolynomial1D* VectorFitPolynomial1DOrd(555 static psPolynomial1D* VectorFitPolynomial1DOrd( 576 556 psPolynomial1D* myPoly, 577 557 const psVector *mask, … … 581 561 const psVector *x) 582 562 { 583 psTrace(__func__, 4, "---- VectorFitPolynomial1DOrd() begin ----\n"); 584 // XXX: these ASSERTS are redundant. 563 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 585 564 PS_ASSERT_POLY_NON_NULL(myPoly, NULL); 586 565 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL); … … 600 579 } 601 580 602 psImage* A = NULL;603 psVector* B = NULL;581 psImage* A = NULL; 582 psVector* B = NULL; 604 583 psVector* xSums = NULL; 605 584 psS32 nTerm; … … 607 586 psF64 wt; 608 587 609 if (psTraceGetLevel (__func__) >= 6) {588 if (psTraceGetLevel(__func__) >= 6) { 610 589 psTrace(__func__, 6, "VectorFitPolynomial1D()\n"); 611 590 for (psS32 i = 0; i < f->n; i++) { … … 627 606 nOrder = nTerm - 1; 628 607 629 A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 630 B = psVectorAlloc(nTerm, PS_TYPE_F64); 631 632 // 608 A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 609 B = psVectorAlloc(nTerm, PS_TYPE_F64); 633 610 // Initialize data structures. 634 // XXX: Use psLib function. 635 // 636 PS_VECTOR_SET_F64(B, 0.0); 637 PS_IMAGE_SET_F64(A, 0.0); 611 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 612 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 613 psFree(myPoly); 614 psFree(A); 615 psFree(B); 616 psTrace(__func__, 4, "---- %s() End ----\n", __func__); 617 return(NULL); 618 } 638 619 639 620 // xSums look like: 1, x, x^2, ... x^(2n+1) … … 641 622 // XXX EAM : use temp pointers eg vB = B->data.F64 to save redirects 642 623 // XXX EAM : this function is only valid for data vectors of F64 643 for ( intk = 0; k < f->n; k++) {624 for (psS32 k = 0; k < f->n; k++) { 644 625 if ((mask != NULL) && (mask->data.U8[k] && maskValue)) { 645 626 continue; … … 657 638 wt = (fErr->data.F64[k] == 0) ? 0.0 : 1.0 / PS_SQR(fErr->data.F64[k]); 658 639 } 659 for ( inti = 0; i < nTerm; i++) {640 for (psS32 i = 0; i < nTerm; i++) { 660 641 B->data.F64[i] += f->data.F64[k] * xSums->data.F64[i] * wt; 661 642 } … … 663 644 // we could skip half of the array and assign at the end 664 645 // we must handle masked orders 665 for ( inti = 0; i < nTerm; i++) {666 for ( intj = 0; j < nTerm; j++) {646 for (psS32 i = 0; i < nTerm; i++) { 647 for (psS32 j = 0; j < nTerm; j++) { 667 648 A->data.F64[i][j] += xSums->data.F64[i + j] * wt; 668 649 } … … 670 651 } 671 652 672 // GaussJordan version673 653 if (0) { 674 // does the solution in place 675 // XXX: Check error codes! 676 psGaussJordan (A, B); 677 678 // the first nTerm entries in B correspond directly to the desired 679 // polynomial coefficients. this is only true for the 1D case 680 for (int k = 0; k < nTerm; k++) { 681 myPoly->coeff[k] = B->data.F64[k]; 682 } 654 // GaussJordan version 655 if (false == psGaussJordan(A, B)) { 656 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n"); 657 psFree(myPoly); 658 myPoly = NULL; 659 } else { 660 // the first nTerm entries in B correspond directly to the desired 661 // polynomial coefficients. this is only true for the 1D case 662 for (psS32 k = 0; k < nTerm; k++) { 663 myPoly->coeff[k] = B->data.F64[k]; 664 } 665 } 666 683 667 } else { 684 668 // LUD version of the fit … … 687 671 psVector* coeffs = NULL; 688 672 673 // XXX: Check return codes. 689 674 ALUD = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 690 675 ALUD = psMatrixLUD(ALUD, &outPerm, A); 691 676 coeffs = psMatrixLUSolve(coeffs, ALUD, B, outPerm); 692 for ( intk = 0; k < nTerm; k++) {677 for (psS32 k = 0; k < nTerm; k++) { 693 678 myPoly->coeff[k] = coeffs->data.F64[k]; 694 679 } … … 703 688 psFree(xSums); 704 689 705 psTrace(__func__, 4, "---- VectorFitPolynomial1DOrd() End ----\n");690 psTrace(__func__, 4, "---- %s() End ----\n", __func__); 706 691 return (myPoly); 707 692 } … … 713 698 Types F32 and F64 are supported, however, type F32 is done via vector 714 699 conversion only. 715 716 XXX: Put the asserts at the beginning. Why is this not failing tests?717 700 *****************************************************************************/ 718 701 psPolynomial1D *psVectorFitPolynomial1D( … … 748 731 749 732 if (f->type.type != PS_TYPE_F64) { 750 PS_VECTOR_GEN_F64_FROM_F32(f64, f);733 f64 = psVectorCopy(NULL, f, PS_TYPE_F64); 751 734 } else { 752 735 f64 = (psVector *) f; … … 755 738 if (x != NULL) { 756 739 if (x->type.type != PS_TYPE_F64) { 757 PS_VECTOR_GEN_F64_FROM_F32(x64, x);740 x64 = psVectorCopy(NULL, x, PS_TYPE_F64); 758 741 } else { 759 742 x64 = (psVector *) x; … … 763 746 if (fErr != NULL) { 764 747 if (fErr->type.type != PS_TYPE_F64) { 765 PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);748 fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64); 766 749 } else { 767 750 fErr64 = (psVector *) fErr; … … 784 767 if (x == NULL) { 785 768 // If x==NULL, create an x64 vector with x values set to (-1:1). 786 PS_VECTOR_GEN_CHEBY_INDEX(x64, f64->n );769 PS_VECTOR_GEN_CHEBY_INDEX(x64, f64->n, PS_TYPE_F64); 787 770 } 788 771 … … 850 833 } else if (poly->type == PS_POLYNOMIAL_CHEB) { 851 834 if (f->type.type == PS_TYPE_F32) { 852 PS_VECTOR_GEN_CHEBY_INDEX _F32(x, f->n);835 PS_VECTOR_GEN_CHEBY_INDEX(x, f->n, PS_TYPE_F32); 853 836 } else if (f->type.type == PS_TYPE_F64) { 854 PS_VECTOR_GEN_CHEBY_INDEX _F64(x, f->n);837 PS_VECTOR_GEN_CHEBY_INDEX(x, f->n, PS_TYPE_F64); 855 838 } 856 839 } else { 857 printf("XXX: error, bad poly type.\n"); 840 psError(PS_ERR_UNKNOWN, false, "Error, bad poly type.\n"); 841 return(NULL); 858 842 } 859 843 } … … 885 869 886 870 // 887 for ( intN = 0; N < stats->clipIter; N++) {871 for (psS32 N = 0; N < stats->clipIter; N++) { 888 872 psTrace(__func__, 6, "Loop iteration %d. Calling psVectorFitPolynomial1D()\n"); 889 intNkeep = 0;873 psS32 Nkeep = 0; 890 874 if (psTraceGetLevel(__func__) >= 6) { 891 875 if (mask != NULL) { … … 897 881 poly = psVectorFitPolynomial1D(poly, mask, maskValue, f, fErr, x); 898 882 if (poly == NULL) { 899 printf("XXX: psVectorFitPolynomial1D() returned NULL: Generate error, free data.\n"); 883 psError(PS_ERR_UNKNOWN, true, "Could not fit polynomial. Returning NULL.\n"); 884 if (xIn == NULL) { 885 psFree(x); 886 } 900 887 return(NULL); 901 888 } 902 889 903 // XXX: Check error codes904 890 fit = psPolynomial1DEvalVector(poly, x); 891 if (fit == NULL) { 892 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning NULL.\n"); 893 psFree(resid) 894 return(NULL); 895 } 905 896 for (psS32 i = 0 ; i < f->n ; i++) { 906 897 if (f->type.type == PS_TYPE_F64) { … … 930 921 // we are masking out any point which is out of range 931 922 // recovery is not allowed with this scheme 932 for ( inti = 0; i < resid->n; i++) {923 for (psS32 i = 0; i < resid->n; i++) { 933 924 if ((mask != NULL) && (mask->data.U8[i] & maskValue)) { 934 925 continue; … … 954 945 955 946 // 956 // XXX:We should probably exit this loop if no new elements were masked947 // We should probably exit this loop if no new elements were masked 957 948 // since the polynomial fit won't change. 958 949 // … … 984 975 pairs. All non-NULL vectors must be of type PS_TYPE_F64. 985 976 986 // XXX: What about the maskValue?987 977 *****************************************************************************/ 988 psPolynomial2D* VectorFitPolynomial2DOrd(978 static psPolynomial2D* VectorFitPolynomial2DOrd( 989 979 psPolynomial2D* myPoly, 990 980 const psVector* mask, … … 995 985 const psVector *y) 996 986 { 997 psTrace(__func__, 4, "---- VectorFitPolynomial2DOrd() begin ----\n"); 998 // These ASSERTS are redundant. 987 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 999 988 PS_ASSERT_POLY_NON_NULL(myPoly, NULL); 1000 989 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL); … … 1025 1014 psS32 nTerm; 1026 1015 1027 // XXX:Watch for changes to the psPolys: nTerm != nOrder.1028 1016 psS32 nXterm = 1 + myPoly->nX; 1029 1017 psS32 nYterm = 1 + myPoly->nY; … … 1032 1020 A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 1033 1021 B = psVectorAlloc(nTerm, PS_TYPE_F64); 1034 1035 //1036 1022 // Initialize data structures. 1037 // XXX: Use psLib function. 1038 // 1039 PS_VECTOR_SET_F64(B, 0.0); 1040 PS_IMAGE_SET_F64(A, 0.0); 1023 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 1024 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 1025 psFree(myPoly); 1026 psFree(A); 1027 psFree(B); 1028 psTrace(__func__, 4, "---- %s() End ----\n", __func__); 1029 return(NULL); 1030 } 1041 1031 1042 1032 // Sums look like: 1, x, x^2, ... x^(2n+1), y, xy, x^2y, ... x^(2n+1) 1043 1033 1044 1034 // Build the B and A data structs. 1045 for ( intk = 0; k < x->n; k++) {1035 for (psS32 k = 0; k < x->n; k++) { 1046 1036 if ((mask != NULL) && (mask->data.U8[k] & maskValue)) { 1047 1037 continue; … … 1059 1049 // we could skip half of the array and assign at the end 1060 1050 // we must handle masked orders 1061 for ( intn = 0; n < nXterm; n++) {1062 for ( intm = 0; m < nYterm; m++) {1051 for (psS32 n = 0; n < nXterm; n++) { 1052 for (psS32 m = 0; m < nYterm; m++) { 1063 1053 B->data.F64[n+m*nXterm] += f->data.F64[k] * Sums->data.F64[n][m] * wt; 1064 1054 } 1065 1055 } 1066 1056 1067 for ( inti = 0; i < nXterm; i++) {1068 for ( intj = 0; j < nYterm; j++) {1069 for ( intn = 0; n < nXterm; n++) {1070 for ( intm = 0; m < nYterm; m++) {1057 for (psS32 i = 0; i < nXterm; i++) { 1058 for (psS32 j = 0; j < nYterm; j++) { 1059 for (psS32 n = 0; n < nXterm; n++) { 1060 for (psS32 m = 0; m < nYterm; m++) { 1071 1061 A->data.F64[i+j*nXterm][n+m*nXterm] += Sums->data.F64[i+n][j+m] * wt; 1072 1062 } … … 1076 1066 } 1077 1067 1078 // does the solution in place 1079 // XXX: Check error codes! 1080 psGaussJordan (A, B); 1081 1082 // select the appropriate solution entries 1083 for (int n = 0; n < nXterm; n++) { 1084 for (int m = 0; m < nYterm; m++) { 1085 myPoly->coeff[n][m] = B->data.F64[n+m*nXterm]; 1068 if (false == psGaussJordan(A, B)) { 1069 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n"); 1070 psFree(myPoly); 1071 myPoly = NULL; 1072 } else { 1073 // select the appropriate solution entries 1074 for (psS32 n = 0; n < nXterm; n++) { 1075 for (psS32 m = 0; m < nYterm; m++) { 1076 myPoly->coeff[n][m] = B->data.F64[n+m*nXterm]; 1077 } 1086 1078 } 1087 1079 } … … 1091 1083 psFree(Sums); 1092 1084 1093 psTrace(__func__, 4, "---- VectorFitPolynomial2DOrd() end ----\n");1085 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 1094 1086 return (myPoly); 1095 1087 } … … 1139 1131 // 1140 1132 if (f->type.type != PS_TYPE_F64) { 1141 PS_VECTOR_GEN_F64_FROM_F32(f64, f);1133 f64 = psVectorCopy(NULL, f, PS_TYPE_F64); 1142 1134 } else { 1143 1135 f64 = (psVector *) f; … … 1145 1137 1146 1138 if (x->type.type != PS_TYPE_F64) { 1147 PS_VECTOR_GEN_F64_FROM_F32(x64, x);1139 x64 = psVectorCopy(NULL, x, PS_TYPE_F64); 1148 1140 } else { 1149 1141 x64 = (psVector *) x; … … 1151 1143 1152 1144 if (y->type.type != PS_TYPE_F64) { 1153 PS_VECTOR_GEN_F64_FROM_F32(y64, y);1145 y64 = psVectorCopy(NULL, y, PS_TYPE_F64); 1154 1146 } else { 1155 1147 y64 = (psVector *) y; … … 1161 1153 if (fErr != NULL) { 1162 1154 if (fErr->type.type != PS_TYPE_F64) { 1163 PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);1155 fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64); 1164 1156 } else { 1165 1157 fErr64 = (psVector *) fErr; … … 1272 1264 1273 1265 // clipping range defined by min and max and/or clipSigma 1274 floatminClipSigma;1275 floatmaxClipSigma;1266 psF32 minClipSigma; 1267 psF32 maxClipSigma; 1276 1268 if (isfinite(stats->max)) { 1277 1269 maxClipSigma = fabs(stats->max); … … 1294 1286 psTrace(__func__, 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma); 1295 1287 1296 for ( intN = 0; N < stats->clipIter; N++) {1288 for (psS32 N = 0; N < stats->clipIter; N++) { 1297 1289 psTrace(__func__, 6, "Loop iteration %d. Calling psVectorFitPolynomial1D()\n"); 1298 intNkeep = 0;1290 psS32 Nkeep = 0; 1299 1291 if (psTraceGetLevel(__func__) >= 6) { 1300 1292 if (mask != NULL) { … … 1306 1298 1307 1299 poly = psVectorFitPolynomial2D(poly, mask, maskValue, f, fErr, x, y); 1308 // XXX: Check error codes 1300 if (poly == NULL) { 1301 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data. Returning NULL.\n"); 1302 psFree(resid) 1303 return(NULL); 1304 } 1305 1309 1306 psVector *fit = psPolynomial2DEvalVector(poly, x, y); 1307 if (fit == NULL) { 1308 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning NULL.\n"); 1309 psFree(resid) 1310 return(NULL); 1311 } 1310 1312 1311 1313 for (psS32 i = 0 ; i < f->n ; i++) { … … 1328 1330 } 1329 1331 1330 // XXX: Check error codes1331 1332 stats = psVectorStats(stats, resid, NULL, mask, maskValue); 1333 if (stats == NULL) { 1334 psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector. Returning NULL.\n"); 1335 psFree(resid) 1336 psFree(fit) 1337 return(NULL); 1338 } 1332 1339 psTrace(__func__, 6, "Median is %f\n", stats->sampleMedian); 1333 1340 psTrace(__func__, 6, "Stdev is %f\n", stats->sampleStdev); 1334 floatminClipValue = -minClipSigma*stats->sampleStdev;1335 floatmaxClipValue = +maxClipSigma*stats->sampleStdev;1341 psF32 minClipValue = -minClipSigma*stats->sampleStdev; 1342 psF32 maxClipValue = +maxClipSigma*stats->sampleStdev; 1336 1343 1337 1344 // set mask if pts are not valid 1338 1345 // we are masking out any point which is out of range 1339 1346 // recovery is not allowed with this scheme 1340 for ( inti = 0; i < resid->n; i++) {1347 for (psS32 i = 0; i < resid->n; i++) { 1341 1348 if ((mask != NULL) && (mask->data.U8[i] & maskValue)) { 1342 1349 continue; … … 1388 1395 y, z)-(f) pairs. All non-NULL vectors must be of type PS_TYPE_F64. 1389 1396 1390 XXX: This routine needs to be written. Currently, this is simply a shell. We1391 can assume that all vectors have been converted to F64, that (f, x, y, z) are1392 non-null and F64. fErr may be NULL, but will be F64 is not.1393 1397 *****************************************************************************/ 1394 psPolynomial3D* VectorFitPolynomial3DOrd(1398 static psPolynomial3D* VectorFitPolynomial3DOrd( 1395 1399 psPolynomial3D* myPoly, 1396 1400 const psVector* mask, … … 1402 1406 const psVector *z) 1403 1407 { 1404 psTrace(__func__, 4, "---- VectorFitPolynomial3DOrd() begin ----\n"); 1405 // These ASSERTS are redundant. 1408 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 1406 1409 PS_ASSERT_POLY_NON_NULL(myPoly, NULL); 1407 1410 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL); … … 1435 1438 psS32 nTerm; 1436 1439 1437 // XXX:Watch for changes to the psPolys: nTerm != nOrder.1438 1440 psS32 nXterm = 1 + myPoly->nX; 1439 1441 psS32 nYterm = 1 + myPoly->nY; … … 1443 1445 A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 1444 1446 B = psVectorAlloc(nTerm, PS_TYPE_F64); 1445 1446 1447 // Initialize data structures. 1447 psVectorInit (B, 0.0); 1448 psImageInit (A, 0.0); 1448 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 1449 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 1450 psFree(myPoly); 1451 psFree(A); 1452 psFree(B); 1453 psTrace(__func__, 4, "---- %s() End ----\n", __func__); 1454 return(NULL); 1455 } 1449 1456 1450 1457 // Sums look like: 1, x, x^2, ... x^(2n+1), y, xy, x^2y, ... x^(2n+1)*y, ... 1451 1458 1452 1459 // Build the B and A data structs. 1453 for ( intk = 0; k < x->n; k++) {1460 for (psS32 k = 0; k < x->n; k++) { 1454 1461 if ((mask != NULL) && (mask->data.U8[k] & maskValue)) { 1455 1462 continue; … … 1467 1474 // we could skip half of the array and assign at the end 1468 1475 // we must handle masked orders 1469 for ( intix = 0; ix < nXterm; ix++) {1470 for ( intiy = 0; iy < nYterm; iy++) {1471 for ( intiz = 0; iz < nZterm; iz++) {1476 for (psS32 ix = 0; ix < nXterm; ix++) { 1477 for (psS32 iy = 0; iy < nYterm; iy++) { 1478 for (psS32 iz = 0; iz < nZterm; iz++) { 1472 1479 if (myPoly->mask[ix][iy][iz]) { 1473 1480 continue; 1474 1481 } else { 1475 intnx = ix + iy*nXterm + iz*nXterm*nYterm;1482 psS32 nx = ix + iy*nXterm + iz*nXterm*nYterm; 1476 1483 B->data.F64[nx] += f->data.F64[k] * Sums[ix][iy][iz] * wt; 1477 1484 } … … 1480 1487 } 1481 1488 1482 for ( intix = 0; ix < nXterm; ix++) {1483 for ( intiy = 0; iy < nYterm; iy++) {1484 for ( intiz = 0; iz < nZterm; iz++) {1489 for (psS32 ix = 0; ix < nXterm; ix++) { 1490 for (psS32 iy = 0; iy < nYterm; iy++) { 1491 for (psS32 iz = 0; iz < nZterm; iz++) { 1485 1492 if (myPoly->mask[ix][iy][iz]) 1486 1493 continue; 1487 intnx = ix+iy*nXterm+iz*nXterm*nYterm;1488 for ( intjx = 0; jx < nXterm; jx++) {1489 for ( intjy = 0; jy < nYterm; jy++) {1490 for ( intjz = 0; jz < nZterm; jz++) {1494 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm; 1495 for (psS32 jx = 0; jx < nXterm; jx++) { 1496 for (psS32 jy = 0; jy < nYterm; jy++) { 1497 for (psS32 jz = 0; jz < nZterm; jz++) { 1491 1498 if (myPoly->mask[jx][jy][jz]) 1492 1499 continue; 1493 intny = jx+jy*nXterm+jz*nXterm*nYterm;1500 psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm; 1494 1501 A->data.F64[nx][ny] += Sums[ix+jx][iy+jy][iz+jz] * wt; 1495 1502 } … … 1501 1508 } 1502 1509 1503 for ( intix = 0; ix < nXterm; ix++) {1504 for ( intiy = 0; iy < nYterm; iy++) {1505 for ( intiz = 0; iz < nZterm; iz++) {1510 for (psS32 ix = 0; ix < nXterm; ix++) { 1511 for (psS32 iy = 0; iy < nYterm; iy++) { 1512 for (psS32 iz = 0; iz < nZterm; iz++) { 1506 1513 if (!myPoly->mask[ix][iy][iz]) 1507 1514 continue; 1508 intnx = ix+iy*nXterm+iz*nXterm*nYterm;1515 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm; 1509 1516 B->data.F64[nx] = 0; 1510 for ( intjx = 0; jx < nXterm; jx++) {1511 for ( intjy = 0; jy < nYterm; jy++) {1512 for ( intjz = 0; jz < nZterm; jz++) {1513 intny = jx+jy*nXterm+jz*nXterm*nYterm;1517 for (psS32 jx = 0; jx < nXterm; jx++) { 1518 for (psS32 jy = 0; jy < nYterm; jy++) { 1519 for (psS32 jz = 0; jz < nZterm; jz++) { 1520 psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm; 1514 1521 A->data.F64[nx][ny] = (nx == ny) ? 1 : 0; 1515 1522 } … … 1523 1530 // does the solution in place 1524 1531 // The matrices were overflowing, so I switched to LUD. 1525 if (false == psGaussJordan (A, B)) {1532 if (false == psGaussJordan(A, B)) { 1526 1533 psFree(A); 1527 1534 psFree(B); 1528 1535 1529 for ( intix = 0; ix < 2*nXterm; ix++) {1530 for ( intiy = 0; iy < 2*nYterm; iy++) {1536 for (psS32 ix = 0; ix < 2*nXterm; ix++) { 1537 for (psS32 iy = 0; iy < 2*nYterm; iy++) { 1531 1538 psFree(Sums[ix][iy]); 1532 1539 } … … 1538 1545 } 1539 1546 // select the appropriate solution entries 1540 for ( intix = 0; ix < nXterm; ix++) {1541 for ( intiy = 0; iy < nYterm; iy++) {1542 for ( intiz = 0; iz < nZterm; iz++) {1543 intnx = ix+iy*nXterm+iz*nXterm*nYterm;1547 for (psS32 ix = 0; ix < nXterm; ix++) { 1548 for (psS32 iy = 0; iy < nYterm; iy++) { 1549 for (psS32 iz = 0; iz < nZterm; iz++) { 1550 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm; 1544 1551 myPoly->coeff[ix][iy][iz] = B->data.F64[nx]; 1545 1552 myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]); … … 1553 1560 psVector* coeffs = NULL; 1554 1561 1562 // XXX: Check return codes. 1555 1563 ALUD = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 1556 1564 ALUD = psMatrixLUD(ALUD, &outPerm, A); … … 1558 1566 1559 1567 // select the appropriate solution entries 1560 for ( intix = 0; ix < nXterm; ix++) {1561 for ( intiy = 0; iy < nYterm; iy++) {1562 for ( intiz = 0; iz < nZterm; iz++) {1563 intnx = ix+iy*nXterm+iz*nXterm*nYterm;1568 for (psS32 ix = 0; ix < nXterm; ix++) { 1569 for (psS32 iy = 0; iy < nYterm; iy++) { 1570 for (psS32 iz = 0; iz < nZterm; iz++) { 1571 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm; 1564 1572 myPoly->coeff[ix][iy][iz] = coeffs->data.F64[nx]; 1565 1573 myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]); … … 1575 1583 psFree(B); 1576 1584 1577 for ( intix = 0; ix < 2*nXterm; ix++) {1578 for ( intiy = 0; iy < 2*nYterm; iy++) {1585 for (psS32 ix = 0; ix < 2*nXterm; ix++) { 1586 for (psS32 iy = 0; iy < 2*nYterm; iy++) { 1579 1587 psFree(Sums[ix][iy]); 1580 1588 } … … 1583 1591 psFree(Sums); 1584 1592 1585 psTrace(__func__, 4, "---- VectorFitPolynomial3DOrd() end ----\n");1593 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 1586 1594 return (myPoly); 1587 1595 } … … 1621 1629 PS_ASSERT_VECTOR_NON_NULL(x, NULL); 1622 1630 PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL); 1623 // PS_ASSERT_VECTOR_TYPE(x, f->type.type, NULL);1624 1631 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 1625 1632 PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL); 1626 // PS_ASSERT_VECTOR_TYPE(y, f->type.type, NULL);1627 1633 PS_ASSERT_VECTOR_NON_NULL(z, NULL); 1628 1634 PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL); 1629 // PS_ASSERT_VECTOR_TYPE(z, f->type.type, NULL);1630 1635 if (fErr != NULL) { 1631 1636 PS_ASSERT_VECTORS_SIZE_EQUAL(f, fErr, NULL); … … 1637 1642 // 1638 1643 if (f->type.type != PS_TYPE_F64) { 1639 PS_VECTOR_GEN_F64_FROM_F32(f64, f);1644 f64 = psVectorCopy(NULL, f, PS_TYPE_F64); 1640 1645 } else { 1641 1646 f64 = (psVector *) f; 1642 1647 } 1643 1648 if (x->type.type != PS_TYPE_F64) { 1644 PS_VECTOR_GEN_F64_FROM_F32(x64, x);1649 x64 = psVectorCopy(NULL, x, PS_TYPE_F64); 1645 1650 } else { 1646 1651 x64 = (psVector *) x; 1647 1652 } 1648 1653 if (y->type.type != PS_TYPE_F64) { 1649 PS_VECTOR_GEN_F64_FROM_F32(y64, y);1654 y64 = psVectorCopy(NULL, y, PS_TYPE_F64); 1650 1655 } else { 1651 1656 y64 = (psVector *) y; … … 1653 1658 1654 1659 if (z->type.type != PS_TYPE_F64) { 1655 PS_VECTOR_GEN_F64_FROM_F32(z64, z);1660 z64 = psVectorCopy(NULL, z, PS_TYPE_F64); 1656 1661 } else { 1657 1662 z64 = (psVector *) z; … … 1660 1665 if (fErr != NULL) { 1661 1666 if (fErr->type.type != PS_TYPE_F64) { 1662 PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);1667 fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64); 1663 1668 } else { 1664 1669 fErr64 = (psVector *) fErr; … … 1788 1793 1789 1794 // clipping range defined by min and max and/or clipSigma 1790 floatminClipSigma;1791 floatmaxClipSigma;1795 psF32 minClipSigma; 1796 psF32 maxClipSigma; 1792 1797 if (isfinite(stats->max)) { 1793 1798 maxClipSigma = fabs(stats->max); … … 1811 1816 psTrace(__func__, 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma); 1812 1817 1813 for ( intN = 0; N < stats->clipIter; N++) {1818 for (psS32 N = 0; N < stats->clipIter; N++) { 1814 1819 psTrace(__func__, 6, "Loop iteration %d. Calling psVectorFitPolynomial1D()\n"); 1815 intNkeep = 0;1820 psS32 Nkeep = 0; 1816 1821 if (psTraceGetLevel(__func__) >= 6) { 1817 1822 if (mask != NULL) { … … 1823 1828 1824 1829 poly = psVectorFitPolynomial3D(poly, mask, maskValue, f, fErr, x, y, z); 1825 // XXX: Check error codes 1830 if (poly == NULL) { 1831 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data. Returning NULL.\n"); 1832 psFree(resid) 1833 psFree(fit) 1834 return(NULL); 1835 } 1826 1836 fit = psPolynomial3DEvalVector(poly, x, y, z); 1837 if (fit == NULL) { 1838 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning NULL.\n"); 1839 psFree(resid) 1840 return(NULL); 1841 } 1827 1842 for (psS32 i = 0 ; i < f->n ; i++) { 1828 1843 if (f->type.type == PS_TYPE_F64) { … … 1844 1859 } 1845 1860 1846 // XXX: Check error codes1847 1861 stats = psVectorStats(stats, resid, NULL, mask, maskValue); 1862 if (stats == NULL) { 1863 psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector. Returning NULL.\n"); 1864 psFree(resid) 1865 psFree(fit) 1866 return(NULL); 1867 } 1868 1848 1869 psTrace(__func__, 6, "Median is %f\n", stats->sampleMedian); 1849 1870 psTrace(__func__, 6, "Stdev is %f\n", stats->sampleStdev); 1850 floatminClipValue = -minClipSigma*stats->sampleStdev;1851 floatmaxClipValue = +maxClipSigma*stats->sampleStdev;1871 psF32 minClipValue = -minClipSigma*stats->sampleStdev; 1872 psF32 maxClipValue = +maxClipSigma*stats->sampleStdev; 1852 1873 1853 1874 // set mask if pts are not valid 1854 1875 // we are masking out any point which is out of range 1855 1876 // recovery is not allowed with this scheme 1856 for ( inti = 0; i < resid->n; i++) {1877 for (psS32 i = 0; i < resid->n; i++) { 1857 1878 if ((mask != NULL) && (mask->data.U8[i] & maskValue)) { 1858 1879 continue; … … 1902 1923 y, z, t)-(f) pairs. All non-NULL vectors must be of type PS_TYPE_F64. 1903 1924 1904 XXX: This routine needs to be written. Currently, this is simply a shell. We1905 can assume that all vectors have been converted to F64, that (f, x, y, z) are1906 non-null and F64. fErr may be NULL, but will be F64 is not.1907 1925 *****************************************************************************/ 1908 psPolynomial4D* VectorFitPolynomial4DOrd(1926 static psPolynomial4D* VectorFitPolynomial4DOrd( 1909 1927 psPolynomial4D* myPoly, 1910 1928 const psVector* mask, … … 1918 1936 { 1919 1937 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 1920 // These ASSERTS are redundant.1921 1938 PS_ASSERT_POLY_NON_NULL(myPoly, NULL); 1922 1939 PS_ASSERT_INT_NONNEGATIVE(myPoly->nX, NULL); … … 1954 1971 psS32 nTerm; 1955 1972 1956 // XXX:Watch for changes to the psPolys: nTerm != nOrder.1957 1973 psS32 nXterm = 1 + myPoly->nX; 1958 1974 psS32 nYterm = 1 + myPoly->nY; … … 1963 1979 A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 1964 1980 B = psVectorAlloc(nTerm, PS_TYPE_F64); 1965 1966 1981 // Initialize data structures. 1967 psVectorInit (B, 0.0); 1968 psImageInit (A, 0.0); 1982 if (!psImageInit(A, 0.0) || !psVectorInit(B, 0.0)) { 1983 psError(PS_ERR_UNKNOWN, false, "Could initialize data structures A, B. Returning NULL.\n"); 1984 psFree(myPoly); 1985 psFree(A); 1986 psFree(B); 1987 psTrace(__func__, 4, "---- %s() End ----\n", __func__); 1988 return(NULL); 1989 } 1969 1990 1970 1991 // Sums look like: 1, x, x^2, ... x^(2n+1), y, xy, x^2y, ... x^(2n+1)*y, ... 1971 1992 1972 1993 // Build the B and A data structs. 1973 for ( intk = 0; k < x->n; k++) {1994 for (psS32 k = 0; k < x->n; k++) { 1974 1995 if ((mask != NULL) && (mask->data.U8[k] & maskValue)) { 1975 1996 continue; … … 1987 2008 // we could skip half of the array and assign at the end 1988 2009 // we must handle masked orders 1989 for ( intix = 0; ix < nXterm; ix++) {1990 for ( intiy = 0; iy < nYterm; iy++) {1991 for ( intiz = 0; iz < nZterm; iz++) {1992 for ( intit = 0; it < nTterm; it++) {2010 for (psS32 ix = 0; ix < nXterm; ix++) { 2011 for (psS32 iy = 0; iy < nYterm; iy++) { 2012 for (psS32 iz = 0; iz < nZterm; iz++) { 2013 for (psS32 it = 0; it < nTterm; it++) { 1993 2014 if (myPoly->mask[ix][iy][iz][it]) 1994 2015 continue; 1995 intnx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;2016 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm; 1996 2017 B->data.F64[nx] += f->data.F64[k] * Sums[ix][iy][iz][it] * wt; 1997 2018 } … … 2000 2021 } 2001 2022 2002 for ( intix = 0; ix < nXterm; ix++) {2003 for ( intiy = 0; iy < nYterm; iy++) {2004 for ( intiz = 0; iz < nZterm; iz++) {2005 for ( intit = 0; it < nTterm; it++) {2023 for (psS32 ix = 0; ix < nXterm; ix++) { 2024 for (psS32 iy = 0; iy < nYterm; iy++) { 2025 for (psS32 iz = 0; iz < nZterm; iz++) { 2026 for (psS32 it = 0; it < nTterm; it++) { 2006 2027 if (myPoly->mask[ix][iy][iz][it]) 2007 2028 continue; 2008 intnx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;2009 for ( intjx = 0; jx < nXterm; jx++) {2010 for ( intjy = 0; jy < nYterm; jy++) {2011 for ( intjz = 0; jz < nZterm; jz++) {2012 for ( intjt = 0; jt < nTterm; jt++) {2029 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm; 2030 for (psS32 jx = 0; jx < nXterm; jx++) { 2031 for (psS32 jy = 0; jy < nYterm; jy++) { 2032 for (psS32 jz = 0; jz < nZterm; jz++) { 2033 for (psS32 jt = 0; jt < nTterm; jt++) { 2013 2034 if (myPoly->mask[jx][jy][jz][jt]) 2014 2035 continue; 2015 intny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm;2036 psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm; 2016 2037 A->data.F64[nx][ny]+= Sums[ix+jx][iy+jy][iz+jz][it+jt] * wt; 2017 2038 } … … 2025 2046 } 2026 2047 2027 for ( intix = 0; ix < nXterm; ix++) {2028 for ( intiy = 0; iy < nYterm; iy++) {2029 for ( intiz = 0; iz < nZterm; iz++) {2030 for ( intit = 0; it < nTterm; it++) {2048 for (psS32 ix = 0; ix < nXterm; ix++) { 2049 for (psS32 iy = 0; iy < nYterm; iy++) { 2050 for (psS32 iz = 0; iz < nZterm; iz++) { 2051 for (psS32 it = 0; it < nTterm; it++) { 2031 2052 if (!myPoly->mask[ix][iy][iz][it]) 2032 2053 continue; 2033 intnx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;2054 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm; 2034 2055 B->data.F64[nx] = 0; 2035 for ( intjx = 0; jx < nXterm; jx++) {2036 for ( intjy = 0; jy < nYterm; jy++) {2037 for ( intjz = 0; jz < nZterm; jz++) {2038 for ( intjt = 0; jt < nTterm; jt++) {2039 intny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm;2056 for (psS32 jx = 0; jx < nXterm; jx++) { 2057 for (psS32 jy = 0; jy < nYterm; jy++) { 2058 for (psS32 jz = 0; jz < nZterm; jz++) { 2059 for (psS32 jt = 0; jt < nTterm; jt++) { 2060 psS32 ny = jx+jy*nXterm+jz*nXterm*nYterm+jt*nXterm*nYterm*nZterm; 2040 2061 A->data.F64[nx][ny] = (nx == ny) ? 1 : 0; 2041 2062 } … … 2051 2072 if (0) { 2052 2073 // does the solution in place 2053 // XXX:The GaussJordan version was overflowing, so I'm using LUD.2074 // The GaussJordan version was overflowing, so I'm using LUD. 2054 2075 if (false == psGaussJordan(A, B)) { 2055 2076 psFree(A); 2056 2077 psFree(B); 2057 for ( intix = 0; ix < 2*nXterm; ix++) {2058 for ( intiy = 0; iy < 2*nYterm; iy++) {2059 for ( intiz = 0; iz < 2*nZterm; iz++) {2078 for (psS32 ix = 0; ix < 2*nXterm; ix++) { 2079 for (psS32 iy = 0; iy < 2*nYterm; iy++) { 2080 for (psS32 iz = 0; iz < 2*nZterm; iz++) { 2060 2081 psFree(Sums[ix][iy][iz]); 2061 2082 } … … 2070 2091 2071 2092 // select the appropriate solution entries 2072 for ( intix = 0; ix < nXterm; ix++) {2073 for ( intiy = 0; iy < nYterm; iy++) {2074 for ( intiz = 0; iz < nZterm; iz++) {2075 for ( intit = 0; it < nTterm; it++) {2076 intnx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;2093 for (psS32 ix = 0; ix < nXterm; ix++) { 2094 for (psS32 iy = 0; iy < nYterm; iy++) { 2095 for (psS32 iz = 0; iz < nZterm; iz++) { 2096 for (psS32 it = 0; it < nTterm; it++) { 2097 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm; 2077 2098 myPoly->coeff[ix][iy][iz][it] = B->data.F64[nx]; 2078 2099 myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]); … … 2087 2108 psVector* coeffs = NULL; 2088 2109 2110 // XXX: Check return codes. 2089 2111 ALUD = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); 2090 2112 ALUD = psMatrixLUD(ALUD, &outPerm, A); … … 2092 2114 2093 2115 // select the appropriate solution entries 2094 for ( intix = 0; ix < nXterm; ix++) {2095 for ( intiy = 0; iy < nYterm; iy++) {2096 for ( intiz = 0; iz < nZterm; iz++) {2097 for ( intit = 0; it < nTterm; it++) {2098 intnx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;2116 for (psS32 ix = 0; ix < nXterm; ix++) { 2117 for (psS32 iy = 0; iy < nYterm; iy++) { 2118 for (psS32 iz = 0; iz < nZterm; iz++) { 2119 for (psS32 it = 0; it < nTterm; it++) { 2120 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm; 2099 2121 myPoly->coeff[ix][iy][iz][it] = coeffs->data.F64[nx]; 2100 2122 myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]); … … 2113 2135 psFree(B); 2114 2136 2115 for ( intix = 0; ix < 2*nXterm; ix++) {2116 for ( intiy = 0; iy < 2*nYterm; iy++) {2117 for ( intiz = 0; iz < 2*nZterm; iz++) {2137 for (psS32 ix = 0; ix < 2*nXterm; ix++) { 2138 for (psS32 iy = 0; iy < 2*nYterm; iy++) { 2139 for (psS32 iz = 0; iz < 2*nZterm; iz++) { 2118 2140 psFree(Sums[ix][iy][iz]); 2119 2141 } … … 2180 2202 // 2181 2203 if (f->type.type != PS_TYPE_F64) { 2182 PS_VECTOR_GEN_F64_FROM_F32(f64, f);2204 f64 = psVectorCopy(NULL, f, PS_TYPE_F64); 2183 2205 } else { 2184 2206 f64 = (psVector *) f; 2185 2207 } 2186 2208 if (x->type.type != PS_TYPE_F64) { 2187 PS_VECTOR_GEN_F64_FROM_F32(x64, x);2209 x64 = psVectorCopy(NULL, x, PS_TYPE_F64); 2188 2210 } else { 2189 2211 x64 = (psVector *) x; 2190 2212 } 2191 2213 if (y->type.type != PS_TYPE_F64) { 2192 PS_VECTOR_GEN_F64_FROM_F32(y64, y);2214 y64 = psVectorCopy(NULL, y, PS_TYPE_F64); 2193 2215 } else { 2194 2216 y64 = (psVector *) y; 2195 2217 } 2196 2218 if (z->type.type != PS_TYPE_F64) { 2197 PS_VECTOR_GEN_F64_FROM_F32(z64, z);2219 z64 = psVectorCopy(NULL, z, PS_TYPE_F64); 2198 2220 } else { 2199 2221 z64 = (psVector *) z; 2200 2222 } 2201 2223 if (t->type.type != PS_TYPE_F64) { 2202 PS_VECTOR_GEN_F64_FROM_F32(t64, t);2224 t64 = psVectorCopy(NULL, t, PS_TYPE_F64); 2203 2225 } else { 2204 2226 t64 = (psVector *) t; … … 2209 2231 if (fErr != NULL) { 2210 2232 if (fErr->type.type != PS_TYPE_F64) { 2211 PS_VECTOR_GEN_F64_FROM_F32(fErr64, fErr);2233 fErr64 = psVectorCopy(NULL, fErr, PS_TYPE_F64); 2212 2234 } else { 2213 2235 fErr64 = (psVector *) fErr; … … 2310 2332 2311 2333 2312 // XXX: Add F64 support.2313 2334 psPolynomial4D *psVectorClipFitPolynomial4D( 2314 2335 psPolynomial4D *poly, … … 2356 2377 2357 2378 // clipping range defined by min and max and/or clipSigma 2358 floatminClipSigma;2359 floatmaxClipSigma;2379 psF32 minClipSigma; 2380 psF32 maxClipSigma; 2360 2381 if (isfinite(stats->max)) { 2361 2382 maxClipSigma = fabs(stats->max); … … 2379 2400 psTrace(__func__, 4, "(minClipSigma, maxClipSigma) is (%.2f, %.2f)\n", minClipSigma, maxClipSigma); 2380 2401 2381 for ( intN = 0; N < stats->clipIter; N++) {2402 for (psS32 N = 0; N < stats->clipIter; N++) { 2382 2403 psTrace(__func__, 6, "Loop iteration %d. Calling psVectorFitPolynomial1D()\n"); 2383 intNkeep = 0;2404 psS32 Nkeep = 0; 2384 2405 if (psTraceGetLevel(__func__) >= 6) { 2385 2406 if (mask != NULL) { … … 2391 2412 2392 2413 poly = psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t); 2393 // XXX: Check error codes 2414 if (poly == NULL) { 2415 psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data. Returning NULL.\n"); 2416 psFree(resid) 2417 psFree(fit) 2418 return(NULL); 2419 } 2420 2394 2421 fit = psPolynomial4DEvalVector (poly, x, y, z, t); 2395 // XXX: This is coded differently for 1D, 2D. Consolidate. 2422 if (fit == NULL) { 2423 psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector(). Returning NULL.\n"); 2424 psFree(resid) 2425 return(NULL); 2426 } 2396 2427 for (psS32 i = 0 ; i < f->n ; i++) { 2397 2428 if (f->type.type == PS_TYPE_F64) { … … 2401 2432 } 2402 2433 } 2403 // XXX: Check error codes2404 2434 2405 2435 if (psTraceGetLevel(__func__) >= 6) { … … 2414 2444 } 2415 2445 2416 // XXX: Check error codes2417 2446 stats = psVectorStats (stats, resid, NULL, mask, maskValue); 2447 if (stats == NULL) { 2448 psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector. Returning NULL.\n"); 2449 psFree(resid) 2450 psFree(fit) 2451 return(NULL); 2452 } 2418 2453 psTrace(__func__, 6, "Median is %f\n", stats->sampleMedian); 2419 2454 psTrace(__func__, 6, "Stdev is %f\n", stats->sampleStdev); 2420 floatminClipValue = -minClipSigma*stats->sampleStdev;2421 floatmaxClipValue = +maxClipSigma*stats->sampleStdev;2455 psF32 minClipValue = -minClipSigma*stats->sampleStdev; 2456 psF32 maxClipValue = +maxClipSigma*stats->sampleStdev; 2422 2457 2423 2458 // set mask if pts are not valid 2424 2459 // we are masking out any point which is out of range 2425 2460 // recovery is not allowed with this scheme 2426 for ( inti = 0; i < resid->n; i++) {2461 for (psS32 i = 0; i < resid->n; i++) { 2427 2462 if ((mask != NULL) && (mask->data.U8[i] & maskValue)) { 2428 2463 continue; -
trunk/psLib/src/math/psMinimizePowell.c
r6101 r6186 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-01-2 1 02:43:31 $11 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-01-23 22:25:31 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 32 32 /*****************************************************************************/ 33 33 /* DEFINE STATEMENTS */ 34 /*****************************************************************************/35 36 /*****************************************************************************/37 /* TYPE DEFINITIONS */38 /*****************************************************************************/39 40 /*****************************************************************************/41 /* GLOBAL VARIABLES */42 /* XXX: Do these conform to code standard? */43 /*****************************************************************************/44 static psMinimizeChi2PowellFunc Chi2PowellFunc = NULL;45 static psVector *myValue;46 static psVector *myError;47 /*****************************************************************************/48 /* FILE STATIC VARIABLES */49 /*****************************************************************************/50 51 /*****************************************************************************/52 /* FUNCTION IMPLEMENTATION - LOCAL */53 34 /*****************************************************************************/ 54 35 … … 82 63 } \ 83 64 65 /*****************************************************************************/ 66 /* TYPE DEFINITIONS */ 67 /*****************************************************************************/ 68 69 /*****************************************************************************/ 70 /* GLOBAL VARIABLES */ 71 /* XXX: Do these conform to code standard? */ 72 /*****************************************************************************/ 73 static psMinimizeChi2PowellFunc Chi2PowellFunc = NULL; 74 static psVector *myValue; 75 static psVector *myError; 76 /*****************************************************************************/ 77 /* FILE STATIC VARIABLES */ 78 /*****************************************************************************/ 79 80 /*****************************************************************************/ 81 /* FUNCTION IMPLEMENTATION - LOCAL */ 82 /*****************************************************************************/ 84 83 85 84 /****************************************************************************** … … 402 401 } 403 402 404 // XXX:Use psTraceGetLevel() 405 for (i=0;i<params->n;i++) { 406 psTrace(__func__, 6, 407 "(params, paramMask, line)[%d] is (%f %d %f)\n", i, 408 params->data.F32[i], 409 paramMask->data.U8[i], 410 line->data.F32[i]); 403 if (6 <= psTraceGetLevel(__func__)) { 404 for (i=0;i<params->n;i++) { 405 psTrace(__func__, 6, "(params, paramMask, line)[%d] is (%f %d %f)\n", i, 406 params->data.F32[i], paramMask->data.U8[i], line->data.F32[i]); 407 } 411 408 } 412 409 -
trunk/psLib/src/math/psPolynomial.c
r6101 r6186 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.13 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-01-2 1 02:43:31 $9 * @version $Revision: 1.136 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-01-23 22:25:31 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 14 14 * XXX: Should the "coeffErr[]" be used as well? Bug ???. Ignore coeffErr 15 15 * 16 * XXX: In the various polyAlloc(n) functions, n is really the order of the17 * polynomial plus 1. To create a 2nd-order polynomial, n == 3.18 16 */ 19 17 /*****************************************************************************/ … … 154 152 155 153 /***************************************************************************** 156 createChebyshevPolys(n): this routine takes as input the required order n,154 p_psCreateChebyshevPolys(n): this routine takes as input the required order n, 157 155 and returns as output as a pointer to an array of n psPolynomial1D 158 156 structures, corresponding to the first n Chebyshev polynomials. … … 162 160 outer coefficients of the Chebyshev polynomials. 163 161 164 XXX: From the poly nOrder/nTerm changem the maxChebyPoly here is still nTerms,165 not nOrder.166 162 *****************************************************************************/ 167 psPolynomial1D ** createChebyshevPolys(psS32 numPolys)163 psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys) 168 164 { 169 165 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL); … … 202 198 } 203 199 204 /*205 static psPolynomial1D **createChebyshevPolysOld(psS32 maxChebyPoly)206 {207 PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);208 209 psPolynomial1D **chebPolys = NULL;210 211 chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));212 for (psS32 i = 0; i < maxChebyPoly; i++) {213 chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);214 }215 216 // Create the Chebyshev polynomials.217 // Polynomial i has i-th order.218 chebPolys[0]->coeff[0] = 1;219 220 // XXX: Bug 296221 if (maxChebyPoly > 1) {222 chebPolys[1]->coeff[1] = 1;223 224 for (psS32 i = 2; i < maxChebyPoly; i++) {225 for (psS32 j = 0; j < chebPolys[i - 1]->nX; j++) {226 chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];227 }228 for (psS32 j = 0; j < chebPolys[i - 2]->nX; j++) {229 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];230 }231 }232 } else {233 // XXX: Code this.234 printf("WARNING: %u-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);235 }236 237 return (chebPolys);238 }239 */240 200 241 201 /***************************************************************************** 242 202 Polynomial coefficients will be accessed in [w][x][y][z] fashion. 243 203 *****************************************************************************/ 244 static psF64 ordPolynomial1DEval(psF64 x, 245 const psPolynomial1D* poly) 204 static psF64 ordPolynomial1DEval( 205 psF64 x, 206 const psPolynomial1D* poly) 246 207 { 247 208 unsigned int loop_x = 0; … … 249 210 psF64 xSum = 1.0; 250 211 251 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 252 "---- Calling ordPolynomial1DEval(%lf)\n", x); 253 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 254 "Polynomial order is %u\n", poly->nX); 212 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); 213 psTrace(__func__, 4, "Polynomial order is %u\n", poly->nX); 255 214 for (loop_x = 0; loop_x < poly->nX+1; loop_x++) { 256 psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4, 257 "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]); 215 psTrace(__func__, 4, "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]); 258 216 } 259 217 … … 262 220 // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to 263 221 // 2 or higher in the test code, you get seg faults. 264 psTrace( ".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 8,222 psTrace(__func__, 8, 265 223 "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]); 266 224 polySum += xSum * poly->coeff[loop_x]; … … 269 227 } 270 228 229 psTrace(__func__, 4, "---- %s() end ----\n", __func__); 271 230 return(polySum); 272 231 } … … 284 243 psVector *d; 285 244 286 // XXX: n should be nTerms here (for clarity). Or get rid of the variable.287 245 unsigned int nTerms = 1 + poly->nX; 288 246 unsigned int i; … … 338 296 } else { 339 297 // This is old code that does not use Clenshaw's formula. Get rid of it. 340 psPolynomial1D **chebPolys = createChebyshevPolys(1 + poly->nX);298 psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX); 341 299 342 300 tmp = 0.0; … … 402 360 maxChebyPoly = poly->nY; 403 361 } 404 chebPolys = createChebyshevPolys(maxChebyPoly + 1);362 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1); 405 363 406 364 for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) { … … 476 434 maxChebyPoly = poly->nZ; 477 435 } 478 chebPolys = createChebyshevPolys(maxChebyPoly + 1);436 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1); 479 437 480 438 for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) { … … 567 525 maxChebyPoly = poly->nT; 568 526 } 569 // XXX: Add 1 since createChebyshevPolys() takes nTerms, not nOrder.570 chebPolys = createChebyshevPolys(maxChebyPoly + 1);527 // Add 1 since p_psCreateChebyshevPolys() takes nTerms, not nOrder. 528 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1); 571 529 572 530 for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) { … … 648 606 /***************************************************************************** 649 607 This routine must allocate memory for the polynomial structures. 650 XXX: replaces nterms variables with nOrder. Lots of potential for bugs651 here. Probably should create separately named private variables652 in these functions.653 608 *****************************************************************************/ 654 psPolynomial1D* psPolynomial1DAlloc(unsigned int n, 655 psPolynomialType type) 609 psPolynomial1D* psPolynomial1DAlloc( 610 unsigned int n, 611 psPolynomialType type) 656 612 { 657 613 PS_ASSERT_INT_NONNEGATIVE(n, NULL); 658 659 unsigned int i = 0; 660 psPolynomial1D* newPoly = NULL; 661 662 newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D)); 614 psU32 nOrder = n; 615 psPolynomial1D *newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D)); 663 616 psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree); 664 617 665 618 newPoly->type = type; 666 newPoly->nX = n ;619 newPoly->nX = nOrder; 667 620 newPoly->p_min = NAN; 668 621 newPoly->p_max = NAN; 669 newPoly->coeff = psAlloc((n + 1) * sizeof(psF64));670 newPoly->coeffErr = psAlloc((n + 1) * sizeof(psF64));671 newPoly->mask = (psMaskType *)psAlloc((n + 1) * sizeof(psMaskType));672 for ( i = 0; i < (n+ 1); i++) {622 newPoly->coeff = psAlloc((nOrder + 1) * sizeof(psF64)); 623 newPoly->coeffErr = psAlloc((nOrder + 1) * sizeof(psF64)); 624 newPoly->mask = (psMaskType *)psAlloc((nOrder + 1) * sizeof(psMaskType)); 625 for (psU32 i = 0; i < (nOrder + 1); i++) { 673 626 newPoly->coeff[i] = 0.0; 674 627 newPoly->coeffErr[i] = 0.0; … … 967 920 // XXX: The output of this routine is always psF64 while 1D and 2D are 968 921 // dependent on the input vectors. 969 psVector *psPolynomial3DEvalVector( const psPolynomial3D *poly,970 const psVector *x,971 const psVector *y,972 const psVector *z)973 922 psVector *psPolynomial3DEvalVector( 923 const psPolynomial3D *poly, 924 const psVector *x, 925 const psVector *y, 926 const psVector *z) 974 927 { 975 928 PS_ASSERT_POLY_NON_NULL(poly, NULL); … … 1036 989 } 1037 990 1038 psF64 psPolynomial4DEval(const psPolynomial4D* poly, 1039 psF64 x, 1040 psF64 y, 1041 psF64 z, 1042 psF64 t) 991 psF64 psPolynomial4DEval( 992 const psPolynomial4D* poly, 993 psF64 x, 994 psF64 y, 995 psF64 z, 996 psF64 t) 1043 997 { 1044 998 PS_ASSERT_POLY_NON_NULL(poly, NAN); … … 1056 1010 } 1057 1011 1058 psVector *psPolynomial4DEvalVector(const psPolynomial4D *poly, 1059 const psVector *x, 1060 const psVector *y, 1061 const psVector *z, 1062 const psVector *t) 1012 psVector *psPolynomial4DEvalVector( 1013 const psPolynomial4D *poly, 1014 const psVector *x, 1015 const psVector *y, 1016 const psVector *z, 1017 const psVector *t) 1063 1018 { 1064 1019 PS_ASSERT_POLY_NON_NULL(poly, NULL); -
trunk/psLib/src/math/psPolynomial.h
r5813 r6186 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1. 59$ $Name: not supported by cvs2svn $14 * @date $Date: 200 5-12-19 23:58:47$13 * @version $Revision: 1.60 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-01-23 22:25:31 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 69 69 psPolynomialType; 70 70 71 // XXX: These are incorrect names for the order of the polynomial. We72 // keep them here temporarily so we can later sed replace them with the73 // correct names.74 71 /** One-dimensional polynomial */ 75 72 typedef struct … … 85 82 psPolynomial1D; 86 83 87 // XXX: These are incorrect names for the order of the polynomial. We88 // keep them here temporarily so we can later sed replace them with the89 // correct names.90 84 /** Two-dimensional polynomial */ 91 85 typedef struct … … 100 94 psPolynomial2D; 101 95 102 // XXX: These are incorrect names for the order of the polynomial. We103 // keep them here temporarily so we can later sed replace them with the104 // correct names.105 96 /** Three-dimensional polynomial */ 106 97 typedef struct … … 116 107 psPolynomial3D; 117 108 118 // XXX: These are incorrect names for the order of the polynomial. We119 // keep them here temporarily so we can later sed replace them with the120 // correct names.121 109 /** Four-dimensional polynomial */ 122 110 typedef struct … … 301 289 302 290 303 // XXX: Coding Standard 304 psPolynomial1D **createChebyshevPolys(psS32 numPolys); 291 292 293 /** Creates the specified number of chebyshev polys. 294 * 295 * @return psPolynomial1D** The chebyshev polys. 296 * 297 */ 298 psPolynomial1D **p_psCreateChebyshevPolys( 299 psS32 numPolys 300 ); 305 301 306 302 typedef struct -
trunk/psLib/src/math/psSpline.c
r5517 r6186 7 7 * splines. 8 8 * 9 * @version $Revision: 1.13 2$ $Name: not supported by cvs2svn $10 * @date $Date: 200 5-11-15 20:10:32$9 * @version $Revision: 1.133 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-01-23 22:25:31 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 90 90 (F32). 91 91 92 XXX: This algorithm is derived from the Numerical Recipes.93 92 XXX: use recycled vectors for internal data. 94 93 XXX: do an F64 version? … … 111 110 psF32 *Y = (psF32 *) & (y->data.F32[0]); 112 111 // 113 // XXX:The second derivatives at the endpoints, undefined in the SDR,112 // The second derivatives at the endpoints, undefined in the SDR, 114 113 // are set in psConstants.h: PS_LEFT_SPLINE_DERIV, PS_RIGHT_SPLINE_DERIV. 115 114 // … … 335 334 LaGrange interpolation. 336 335 *****************************************************************************/ 337 static psF32 interpolate1DF32(psF32 *domain, 338 psF32 *range, 339 unsigned int n, 340 unsigned int order, 341 psF32 x) 336 static psF32 interpolate1DF32( 337 psF32 *domain, 338 psF32 *range, 339 unsigned int n, 340 unsigned int order, 341 psF32 x) 342 342 { 343 343 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); -
trunk/psLib/src/math/psStats.c
r6185 r6186 17 17 * 18 18 * 19 * @version $Revision: 1.1 59$ $Name: not supported by cvs2svn $20 * @date $Date: 2006-01-23 2 0:44:29$19 * @version $Revision: 1.160 $ $Name: not supported by cvs2svn $ 20 * @date $Date: 2006-01-23 22:25:31 $ 21 21 * 22 22 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 2317 2317 psTrace(__func__, 5, "(lower, upper, n) is (%f, %f, %d)\n", lower, upper, n); 2318 2318 PS_ASSERT_INT_POSITIVE(n, NULL); 2319 PS_ FLOAT_COMPARE(lower, upper, NULL);2319 PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(upper, lower, NULL); 2320 2320 2321 2321 psS32 i = 0; // Loop index variable … … 2369 2369 PS_ASSERT_VECTOR_NON_NULL(bounds, NULL); 2370 2370 PS_ASSERT_VECTOR_TYPE(bounds, PS_TYPE_F32, NULL); 2371 PS_ INT_COMPARE(2, bounds->n, NULL);2371 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(bounds->n, 2, NULL); 2372 2372 2373 2373 psHistogram* newHist = NULL; // The new histogram structure … … 2437 2437 PS_ASSERT_PTR_NON_NULL(out->nums, -1); 2438 2438 PS_ASSERT_INT_WITHIN_RANGE(binNum, 0, ((out->nums->n)-1), -2); 2439 PS_FLOAT_COMPARE(0.0, error, -3); 2439 PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(error, 0.0, -3); 2440 2440 2441 PS_ASSERT_FLOAT_WITHIN_RANGE(data, out->bounds->data.F32[0], out->bounds->data.F32[(out->bounds->n)-1], -4); 2441 2442 … … 2756 2757 2757 2758 if ((stats->options & PS_STAT_USE_RANGE) && (stats->min >= stats->max)) { 2758 PS_ FLOAT_COMPARE(stats->min, stats->max, stats);2759 PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(stats->max, stats->min, stats); 2759 2760 } 2760 2761
Note:
See TracChangeset
for help on using the changeset viewer.
