Changeset 2273 for trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
- Timestamp:
- Nov 3, 2004, 3:05:00 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
r2204 r2273 29 29 * @author Ross Harman, MHPCC 30 30 * 31 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $32 * @date $Date: 2004-1 0-27 00:57:31$31 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 32 * @date $Date: 2004-11-04 01:04:59 $ 33 33 * 34 34 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 48 48 #include "psScalar.h" 49 49 #include "psLogMsg.h" 50 #include "psConstants.h" 51 #include "psDataManipErrors.h" 50 52 51 53 /***************************************************************************** … … 58 60 // Conversion for radians to degrees 59 61 #define R2D 57.29577950924861 /* 180.0/PI */ 60 61 /* IEEE Standards on floating-point makes this function pointless, really.62 // Division with NAN checking63 static complex double psNanDiv(complex double a, complex double b)64 {65 complex double out = 0 + 0i;66 67 out = a / b;68 if (isnan(creal(out)) || isnan(cimag(out))) {69 psError(__func__, ": Divide by zero");70 }71 72 return out;73 }74 */75 62 76 63 // Binary SCALAR_XXXX operations … … 142 129 #define VECTOR_VECTOR(OUT,IN1,OP,IN2,TYPE) \ 143 130 { \ 144 psS32 i = 0; \145 psS32 n1 = 0; \146 psS32 n2 = 0; \131 psS32 i = 0; \ 132 psS32 n1 = 0; \ 133 psS32 n2 = 0; \ 147 134 ps##TYPE *o = NULL; \ 148 135 ps##TYPE *i1 = NULL; \ … … 151 138 n2 = ((psVector* )IN2)->n; \ 152 139 if(n1 != n2) { \ 153 psError(__func__, ": Inconsistent element count: %d vs %d", n1, n2); \ 140 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 141 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 142 n1, n2); \ 154 143 if (OUT != IN1 && OUT != IN2) { \ 155 144 psFree(OUT); \ … … 167 156 #define VECTOR_IMAGE(OUT,IN1,OP,IN2,TYPE) \ 168 157 { \ 169 psS32 i = 0; \170 psS32 j = 0; \171 psS32 n1 = 0; \172 psS32 numRows2 = 0; \173 psS32 numCols2 = 0; \158 psS32 i = 0; \ 159 psS32 j = 0; \ 160 psS32 n1 = 0; \ 161 psS32 numRows2 = 0; \ 162 psS32 numCols2 = 0; \ 174 163 psDimen dim1 = 0; \ 175 164 ps##TYPE *o = NULL; \ … … 181 170 numCols2 = ((psImage* )IN2)->numCols; \ 182 171 \ 183 if(dim1 == PS_DIMEN_VECTOR) { /* Regular vectors */ \172 if(dim1 == PS_DIMEN_VECTOR) { /* Regular vectors */ \ 184 173 if(n1!=numRows2) { \ 185 psError(__func__, ": Inconsistent element count: %d vs %d", n1, numRows2); \ 174 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 175 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 176 n1, numRows2); \ 186 177 if (OUT != IN1 && OUT != IN2) { \ 187 178 psFree(OUT); \ … … 200 191 } else { /* Transposed vectors */ \ 201 192 if(n1!=numCols2) { \ 202 psError(__func__, ": Inconsistent element count: %d vs %d", n1, numCols2); \ 193 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 194 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 195 n1, numCols2); \ 203 196 if (OUT != IN1 && OUT != IN2) { \ 204 197 psFree(OUT); \ … … 256 249 numCols1 = ((psImage* )IN1)->numCols; \ 257 250 \ 258 if(dim2 == PS_DIMEN_VECTOR) { /* Regular vectors */ \251 if(dim2 == PS_DIMEN_VECTOR) { /* Regular vectors */ \ 259 252 if(n2!=numRows1) { \ 260 psError(__func__, ": Inconsistent element count: %d vs %d", n2, numRows1); \ 253 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 254 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 255 n2, numRows1); \ 261 256 if (OUT != IN1 && OUT != IN2) { \ 262 257 psFree(OUT); \ … … 275 270 } else { /* Transposed vectors */ \ 276 271 if(n2!=numCols1) { \ 277 psError(__func__, ": Inconsistent element count: %d vs %d", n2, numCols1); \ 272 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 273 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 274 n2, numCols1); \ 278 275 if (OUT != IN1) { \ 279 276 psFree(OUT); \ … … 309 306 numCols2 = ((psImage* )IN2)->numCols; \ 310 307 if(numRows1!=numRows2 || numCols1!=numCols2) { \ 311 psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRows1, \ 312 numRows2, numCols1, numCols2); \ 308 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 309 PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS, \ 310 numCols1, numRows1, numCols2, numRows2); \ 313 311 if (OUT != IN1 && OUT != IN2) { \ 314 312 psFree(OUT); \ … … 366 364 break; \ 367 365 default: \ 368 psError(__func__, ": Invalid PS_TYPE: %d", IN1->type); \ 366 /* char* strType; \ 367 PS_TYPE_NAME(strType,IN1->type); \ 368 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 369 PS_ERRORTEXT_psMatrix_TYPE_MISMATCH, \ 370 strType); */ \ 369 371 if (OUT != IN1 && OUT != IN2) { \ 370 372 psFree(OUT); \ … … 391 393 } else if(!strncmp(OP, "min", 3)) { \ 392 394 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ 393 psError(__func__, ": Minimum operation not supported for complex numbers"); \ 395 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 396 PS_ERRORTEXT_psMatrix_MIN_COMPLEX_SUPPORT); \ 394 397 if (OUT != IN1 && OUT != IN2) { \ 395 398 psFree(OUT); \ … … 401 404 } else if(!strncmp(OP, "max", 3)) { \ 402 405 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ 403 psError(__func__, ": Maximum operation not supported for complex numbers"); \ 406 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 407 PS_ERRORTEXT_psMatrix_MAX_COMPLEX_SUPPORT); \ 404 408 if (OUT != IN1 && OUT != IN2) { \ 405 409 psFree(OUT); \ … … 410 414 } \ 411 415 } else { \ 412 psError(__func__, ": Invalid operation: %s", OP); \ 416 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 417 PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED, \ 418 OP); \ 413 419 if (OUT != IN1 && OUT != IN2) { \ 414 420 psFree(OUT); \ … … 419 425 psPtr psBinaryOp(psPtr out, psPtr in1, char *op, psPtr in2) 420 426 { 421 psDimen dim1 = 0; 422 psDimen dim2 = 0; 423 psElemType elType1 = 0; 424 psElemType elType2 = 0; 425 psType* psType1 = NULL; 426 psType* psType2 = NULL; 427 428 psType1 = (psType* ) in1; 429 if (psType1 == NULL) { 430 psError(__func__, ": Line %d - Null in1 argument", __LINE__); 431 if (out != in1 && out != in2) { 432 psFree(out); 433 } 434 return NULL; 435 } 436 437 psType2 = (psType* ) in2; 438 if (psType2 == NULL) { 439 psError(__func__, ": Line %d - Null in2 argument", __LINE__); 440 if (out != in1 && out != in2) { 441 psFree(out); 442 } 443 return NULL; 444 } 445 446 if (op == NULL) { 447 psError(__func__, ": Line %d - Null op argument", __LINE__); 448 if (out != in1 && out != in2) { 449 psFree(out); 450 } 451 return NULL; 452 } 453 454 dim1 = psType1->dimen; 455 dim2 = psType2->dimen; 456 elType1 = psType1->type; 457 elType2 = psType2->type; 458 459 if (elType1 != elType2) { 460 psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d)", __LINE__, 461 elType1, elType2); 462 if (out != in1 && out != in2) { 463 psFree(out); 464 } 465 return NULL; 466 } 467 468 if (dim1 == PS_DIMEN_OTHER || dim2 == PS_DIMEN_OTHER) { 469 psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d)", __LINE__, 470 dim1, dim2); 471 if (out != in1 && out != in2) { 472 psFree(out); 473 } 474 return NULL; 475 } 427 428 psVector* input1 = (psVector* ) in1; 429 psVector* input2 = (psVector* ) in2; 430 431 #define psBinaryOp_EXIT { \ 432 if (out != in1 && out != in2) { \ 433 psFree(out); \ 434 } \ 435 return NULL; \ 436 } 437 438 PS_PTR_CHECK_NULL_GENERAL(input1, psBinaryOp_EXIT); 439 PS_PTR_CHECK_NULL_GENERAL(input2, psBinaryOp_EXIT); 440 PS_PTR_CHECK_NULL_GENERAL(op, psBinaryOp_EXIT); 441 442 PS_PTR_CHECK_TYPE_EQUAL_GENERAL(input1,input2, psBinaryOp_EXIT); 443 444 PS_PTR_CHECK_DIMEN_GENERAL(input1, PS_DIMEN_OTHER, psBinaryOp_EXIT); 445 PS_PTR_CHECK_DIMEN_GENERAL(input2, PS_DIMEN_OTHER, psBinaryOp_EXIT); 446 447 psType* psType1 = (psType*)in1; 448 psType* psType2 = (psType*)in2; 449 psDimen dim1 = psType1->dimen; 450 psDimen dim2 = psType2->dimen; 451 psElemType elType1 = psType1->type; 452 psElemType elType2 = psType2->type; 476 453 477 454 if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) { 478 455 if (((psVector* ) in1)->n == 0) { 479 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Vector contains zero elements");456 psLogMsg(__func__, PS_LOG_WARN, "Vector contains zero elements"); 480 457 } 481 458 } else if (dim1 == PS_DIMEN_IMAGE) { 482 459 if (((psImage* ) in1)->numCols == 0 || ((psImage* ) in1)->numRows == 0) { 483 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Image contains zero length row or cols");460 psLogMsg(__func__, PS_LOG_WARN, "Image contains zero length row or cols"); 484 461 } 485 462 } … … 487 464 if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 488 465 if (((psVector* ) in2)->n == 0) { 489 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Vector contains zero elements");466 psLogMsg(__func__, PS_LOG_WARN, "Vector contains zero elements"); 490 467 } 491 468 } else if (dim2 == PS_DIMEN_IMAGE) { 492 469 if (((psImage* ) in2)->numCols == 0 || ((psImage* ) in2)->numRows == 0) { 493 psLogMsg(__func__, PS_LOG_WARN, " : Line %d -Image contains zero length row or cols");470 psLogMsg(__func__, PS_LOG_WARN, "Image contains zero length row or cols"); 494 471 } 495 472 } … … 513 490 out = psVectorRecycle(out,((psVector*)in2)->n,elType1); 514 491 if (out == NULL) { 515 psError(__func__, "Couldn't create a proper output psVector."); 492 psError(PS_ERR_UNKNOWN, false, 493 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 516 494 return NULL; 517 495 } … … 520 498 out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows,elType1); 521 499 if (out == NULL) { 522 psError(__func__, "Couldn't create a proper output psImage."); 500 psError(PS_ERR_UNKNOWN, false, 501 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 523 502 return NULL; 524 503 } 525 504 BINARY_OP(SCALAR, IMAGE, out, psType1, op, psType2); // scalar op image 526 505 } else { 527 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 506 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 507 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 508 "in2",dim2); 509 psBinaryOp_EXIT; 528 510 } 529 511 } else if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) { … … 531 513 out = psVectorRecycle(out,((psVector*)in1)->n,elType1); 532 514 if (out == NULL) { 533 psError(__func__, "Couldn't create a proper output psVector."); 515 psError(PS_ERR_UNKNOWN, false, 516 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 534 517 return NULL; 535 518 } … … 538 521 out = psVectorRecycle(out,((psVector*)in2)->n,elType2); 539 522 if (out == NULL) { 540 psError(__func__, "Couldn't create a proper output psVector."); 523 psError(PS_ERR_UNKNOWN, false, 524 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 541 525 return NULL; 542 526 } … … 545 529 out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows, elType2); 546 530 if (out == NULL) { 547 psError(__func__, "Couldn't create a proper output psImage."); 531 psError(PS_ERR_UNKNOWN, false, 532 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 548 533 return NULL; 549 534 } 550 535 BINARY_OP(VECTOR, IMAGE, out, psType1, op, psType2); // vector op image 551 536 } else { 552 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 537 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 538 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 539 "in2",dim2); 540 psBinaryOp_EXIT; 553 541 } 554 542 } else if (dim1 == PS_DIMEN_IMAGE) { 555 543 out = psImageRecycle(out, ((psImage*)in1)->numCols, ((psImage*)in1)->numRows, elType1); 556 544 if (out == NULL) { 557 psError(__func__, "Couldn't create a proper output psImage."); 545 psError(PS_ERR_UNKNOWN, false, 546 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 558 547 return NULL; 559 548 } … … 565 554 BINARY_OP(IMAGE, IMAGE, out, psType1, op, psType2); // image op image 566 555 } else { 567 if (out != in1 && out != in2) { 568 psFree(out); 569 } 570 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 571 return NULL; 556 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 557 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 558 "in2",dim2); 559 psBinaryOp_EXIT; 572 560 } 573 561 } else { 574 if (out != in1 && out != in2) { 575 psFree(out); 576 } 577 psError(__func__, ": Line %d - Invalid dimensionality for in1 arg: %d", __LINE__, dim1); 578 return NULL; 562 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 563 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 564 "in1",dim1); 565 psBinaryOp_EXIT; 579 566 } 580 567 … … 605 592 #define VECTOR(OUT,IN,OP,TYPE) \ 606 593 { \ 607 psS32 i = 0; \608 psS32 nIn = 0; \609 psS32 nOut = 0; \594 psS32 i = 0; \ 595 psS32 nIn = 0; \ 596 psS32 nOut = 0; \ 610 597 ps##TYPE *o = NULL; \ 611 598 ps##TYPE *i1 = NULL; \ … … 613 600 nOut = ((psVector* )OUT)->n; \ 614 601 if(nIn != nOut) { \ 615 psError(__func__, ": Inconsistent element count: %d vs %d", nIn, nOut); \ 602 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 603 PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, \ 604 nIn, nOut); \ 616 605 if (OUT != IN) { \ 617 606 psFree(OUT); \ … … 629 618 #define IMAGE(OUT,IN,OP,TYPE) \ 630 619 { \ 631 psS32 i = 0; \632 psS32 j = 0; \633 psS32 numRowsIn = 0; \634 psS32 numColsIn = 0; \635 psS32 numRowsOut = 0; \636 psS32 numColsOut = 0; \620 psS32 i = 0; \ 621 psS32 j = 0; \ 622 psS32 numRowsIn = 0; \ 623 psS32 numColsIn = 0; \ 624 psS32 numRowsOut = 0; \ 625 psS32 numColsOut = 0; \ 637 626 ps##TYPE *o = NULL; \ 638 627 ps##TYPE *i1 = NULL; \ … … 642 631 numColsOut = ((psImage* )OUT)->numCols; \ 643 632 if(numRowsIn!=numRowsOut || numColsIn!=numColsOut) { \ 644 psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRowsIn, \ 645 numRowsOut, numColsIn, numColsOut); \ 633 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \ 634 PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS, \ 635 numColsIn, numRowsIn, numColsOut, numRowsOut); \ 646 636 if (OUT != IN) { \ 647 637 psFree(OUT); \ … … 697 687 DIM(OUT,IN,OP,C32); \ 698 688 break; \ 699 default: \ 700 psError(__func__, ": Invalid PS_TYPE: %d", IN->type); \ 701 if (OUT != IN) { \ 702 psFree(OUT); \ 703 } \ 704 return NULL; \ 689 default: { \ 690 char* strType; \ 691 PS_TYPE_NAME(strType, IN->type); \ 692 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \ 693 PS_ERRORTEXT_psMatrix_TYPE_MISMATCH, \ 694 strType); \ 695 if (OUT != IN) { \ 696 psFree(OUT); \ 697 } \ 698 return NULL; \ 699 } \ 705 700 } 706 701 … … 815 810 } \ 816 811 } else { \ 817 psError(__func__, ": Invalid operation: %s", OP); \ 812 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 813 PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED, \ 814 OP); \ 818 815 } 819 816 820 817 psPtr psUnaryOp(psPtr out, psPtr in, char *op) 821 818 { 822 psDimen dimIn = 0; 823 psElemType elTypeIn = 0; 824 psType* psTypeIn = NULL; 825 826 psTypeIn = (psType* ) in; 827 if (psTypeIn == NULL) { 828 psError(__func__, ": Line %d - Null in argument", __LINE__); 829 if (out != in) { 830 psFree(out); 831 } 832 return NULL; 833 } 834 835 if (op == NULL) { 836 psError(__func__, ": Line %d - Null op argument", __LINE__); 837 if (out != in) { 838 psFree(out); 839 } 840 return NULL; 841 } 842 843 dimIn = psTypeIn->dimen; 844 elTypeIn = psTypeIn->type; 819 #define psUnaryOp_EXIT { \ 820 if (out != in) { \ 821 psFree(out); \ 822 } \ 823 if(psTypeIn->dimen==PS_DIMEN_SCALAR && in!=out) { \ 824 psFree(in); \ 825 } \ 826 return NULL; \ 827 } 828 829 psType* psTypeIn = (psType* ) in; 830 831 PS_PTR_CHECK_NULL_GENERAL(in, psUnaryOp_EXIT); 832 PS_PTR_CHECK_NULL_GENERAL(op, psUnaryOp_EXIT); 833 834 psDimen dimIn = psTypeIn->dimen; 835 psElemType elTypeIn = psTypeIn->type; 845 836 846 837 switch (dimIn) { … … 857 848 case PS_DIMEN_TRANSV: 858 849 if (((psVector*)in)->n == 0) { 859 if (out != in) { 860 psFree(out); 861 } 862 psError(__func__, ": Line %d - Vector contains zero elements"); 863 return NULL; 850 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 851 PS_ERRORTEXT_psMatrix_VECTOR_EMPTY); 852 psUnaryOp_EXIT; 864 853 } 865 854 … … 868 857 elTypeIn); 869 858 if (out == NULL) { 870 psError(__func__, "Couldn't create a proper output psVector."); 871 return NULL; 859 psError(PS_ERR_UNKNOWN, false, 860 PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED); 861 psUnaryOp_EXIT; 872 862 } 873 863 … … 876 866 case PS_DIMEN_IMAGE: 877 867 if (((psImage* ) in)->numCols == 0 || ((psImage* ) in)->numRows == 0) { 878 if (out != in) { 879 psFree(out); 880 } 881 psError(__func__, ": Line %d - Image contains zero length row or cols"); 882 return NULL; 868 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 869 PS_ERRORTEXT_psMatrix_IMAGE_EMPTY); 870 psUnaryOp_EXIT; 883 871 } 884 872 … … 888 876 elTypeIn); 889 877 if (out == NULL) { 890 psError(__func__, "Couldn't create a proper output psImage."); 891 return NULL; 878 psError(PS_ERR_UNKNOWN, false, 879 PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED); 880 psUnaryOp_EXIT; 892 881 } 893 882 … … 898 887 psFree(out); 899 888 } 900 psError(__func__, ": Line %d - Invalid dimensionality for in arg: %d", __LINE__, dimIn); 901 return NULL; 889 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 890 PS_ERRORTEXT_psMatrix_DIMEN_INVALID, 891 "in", dimIn); 892 psUnaryOp_EXIT; 902 893 } 903 894
Note:
See TracChangeset
for help on using the changeset viewer.
