Changeset 1407 for trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
- Timestamp:
- Aug 6, 2004, 2:06:06 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
r1406 r1407 1 1 2 /** @file psMatrixVectorArithmetic.c 2 3 * … … 29 30 * @author Ross Harman, MHPCC 30 31 * 31 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $32 * @date $Date: 2004-08-0 6 22:34:05$32 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 33 * @date $Date: 2004-08-07 00:06:06 $ 33 34 * 34 35 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 36 37 37 38 /******************************************************************************/ 39 38 40 /* INCLUDE FILES */ 41 39 42 /******************************************************************************/ 40 43 #include <string.h> … … 49 52 50 53 /******************************************************************************/ 54 51 55 /* DEFINE STATEMENTS */ 56 52 57 /******************************************************************************/ 53 58 … … 55 60 56 61 /******************************************************************************/ 62 57 63 /* TYPE DEFINITIONS */ 64 58 65 /******************************************************************************/ 59 66 … … 61 68 62 69 /*****************************************************************************/ 70 63 71 /* GLOBAL VARIABLES */ 72 64 73 /*****************************************************************************/ 65 74 … … 67 76 68 77 /*****************************************************************************/ 78 69 79 /* FILE STATIC VARIABLES */ 80 70 81 /*****************************************************************************/ 71 82 … … 73 84 74 85 /*****************************************************************************/ 86 75 87 /* FUNCTION IMPLEMENTATION - LOCAL */ 88 76 89 /*****************************************************************************/ 77 90 … … 85 98 static complex double psNanDiv(complex double a, complex double b) 86 99 { 87 complex double out = 0+0i; 88 out = a/b; 89 if(isnan(creal(out)) || isnan(cimag(out))) { 100 complex double out = 0 + 0i; 101 102 out = a / b; 103 if (isnan(creal(out)) || isnan(cimag(out))) { 90 104 psError(__func__, ": Divide by zero"); 91 105 } … … 399 413 psType *psTypeOut = NULL; 400 414 401 psTypeOut = (psType *)out;402 if (psTypeOut == NULL) {415 psTypeOut = (psType *) out; 416 if (psTypeOut == NULL) { 403 417 psError(__func__, ": Line %d - Null out argument", __LINE__); 404 418 return out; 405 419 } 406 420 407 psType1 = (psType *)in1;408 if (psType1 == NULL) {421 psType1 = (psType *) in1; 422 if (psType1 == NULL) { 409 423 psError(__func__, ": Line %d - Null in1 argument", __LINE__); 410 424 return out; 411 425 } 412 426 413 psType2 = (psType *)in2;414 if (psType2 == NULL) {427 psType2 = (psType *) in2; 428 if (psType2 == NULL) { 415 429 psError(__func__, ": Line %d - Null in2 argument", __LINE__); 416 430 return out; 417 431 } 418 432 419 if (op == NULL) {433 if (op == NULL) { 420 434 psError(__func__, ": Line %d - Null op argument", __LINE__); 421 435 return out; … … 429 443 elTypeOut = psTypeOut->type; 430 444 431 if (elType1!=elType2 && elType1!=elTypeOut) {445 if (elType1 != elType2 && elType1 != elTypeOut) { 432 446 psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d, %d)", __LINE__, 433 447 elType1, elType2, elTypeOut); … … 435 449 } 436 450 437 if (dim1==PS_DIMEN_OTHER || dim2==PS_DIMEN_OTHER || dimOut==PS_DIMEN_OTHER) {451 if (dim1 == PS_DIMEN_OTHER || dim2 == PS_DIMEN_OTHER || dimOut == PS_DIMEN_OTHER) { 438 452 psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d, %d)", __LINE__, 439 453 dim1, dim2, dimOut); … … 441 455 } 442 456 443 if (dim1 == PS_DIMEN_VECTOR) {444 if (((psVector*)in1)->n == 0) {457 if (dim1 == PS_DIMEN_VECTOR) { 458 if (((psVector *) in1)->n == 0) { 445 459 psError(__func__, ": Line %d - Vector contains zero elements"); 446 460 } 447 } else 448 if(dim1 == PS_DIMEN_IMAGE) { 449 if(((psImage*)in1)->numCols==0 || ((psImage*)in1)->numRows==0) { 450 psError(__func__, ": Line %d - Image contains zero length row or cols"); 451 } 452 } 453 454 if(dim2 == PS_DIMEN_VECTOR) { 455 if(((psVector*)in2)->n == 0) { 461 } else if (dim1 == PS_DIMEN_IMAGE) { 462 if (((psImage *) in1)->numCols == 0 || ((psImage *) in1)->numRows == 0) { 463 psError(__func__, ": Line %d - Image contains zero length row or cols"); 464 } 465 } 466 467 if (dim2 == PS_DIMEN_VECTOR) { 468 if (((psVector *) in2)->n == 0) { 456 469 psError(__func__, ": Line %d - Vector contains zero elements"); 457 470 } 458 } else 459 if(dim2 == PS_DIMEN_IMAGE) { 460 if(((psImage*)in2)->numCols==0 || ((psImage*)in2)->numRows==0) { 461 psError(__func__, ": Line %d - Image contains zero length row or cols"); 462 } 463 } 464 465 if(dim1 == PS_DIMEN_SCALAR) { 466 if(dim2 == PS_DIMEN_SCALAR) { 467 BINARY_OP(SCALAR,SCALAR,out,psType1,op,psType2); // scalar op scalar 468 } else 469 if(dim2==PS_DIMEN_VECTOR || dim2==PS_DIMEN_TRANSV) { 470 BINARY_OP(SCALAR,VECTOR,out,psType1,op,psType2); // scalar op vector 471 } else 472 if(dim2 == PS_DIMEN_IMAGE) { 473 BINARY_OP(SCALAR,IMAGE,out,psType1,op,psType2); // scalar op image 474 } else { 475 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 476 } 477 } else 478 if(dim1==PS_DIMEN_VECTOR || dim1==PS_DIMEN_TRANSV) { 479 if(dim2 == PS_DIMEN_SCALAR) { 480 BINARY_OP(VECTOR,SCALAR,out,psType1,op,psType2); // vector op scalar 481 } else 482 if(dim2==PS_DIMEN_VECTOR || dim2==PS_DIMEN_TRANSV) { 483 BINARY_OP(VECTOR,VECTOR,out,psType1,op,psType2); // vector op vector 484 } else 485 if(dim2 == PS_DIMEN_IMAGE) { 486 BINARY_OP(VECTOR,IMAGE,out,psType1,op,psType2); // vector op image 487 } else { 488 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 489 } 490 } else 491 if(dim1 == PS_DIMEN_IMAGE) { 492 if(dim2 == PS_DIMEN_SCALAR) { 493 BINARY_OP(IMAGE,SCALAR,out,psType1,op,psType2); // image op scalar 494 } else 495 if(dim2==PS_DIMEN_VECTOR || dim2==PS_DIMEN_TRANSV) { 496 BINARY_OP(IMAGE,VECTOR,out,psType1,op,psType2); // image op vector 497 } else 498 if(dim2 == PS_DIMEN_IMAGE) { 499 BINARY_OP(IMAGE,IMAGE,out,psType1,op,psType2); // image op image 500 } else { 501 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 502 } 503 } else { 504 psError(__func__, ": Line %d - Invalid dimensionality for in1 arg: %d", __LINE__, dim1); 505 } 471 } else if (dim2 == PS_DIMEN_IMAGE) { 472 if (((psImage *) in2)->numCols == 0 || ((psImage *) in2)->numRows == 0) { 473 psError(__func__, ": Line %d - Image contains zero length row or cols"); 474 } 475 } 476 477 if (dim1 == PS_DIMEN_SCALAR) { 478 if (dim2 == PS_DIMEN_SCALAR) { 479 BINARY_OP(SCALAR, SCALAR, out, psType1, op, psType2); // scalar op scalar 480 } else if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 481 BINARY_OP(SCALAR, VECTOR, out, psType1, op, psType2); // scalar op vector 482 } else if (dim2 == PS_DIMEN_IMAGE) { 483 BINARY_OP(SCALAR, IMAGE, out, psType1, op, psType2); // scalar op image 484 } else { 485 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 486 } 487 } else if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) { 488 if (dim2 == PS_DIMEN_SCALAR) { 489 BINARY_OP(VECTOR, SCALAR, out, psType1, op, psType2); // vector op scalar 490 } else if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 491 BINARY_OP(VECTOR, VECTOR, out, psType1, op, psType2); // vector op vector 492 } else if (dim2 == PS_DIMEN_IMAGE) { 493 BINARY_OP(VECTOR, IMAGE, out, psType1, op, psType2); // vector op image 494 } else { 495 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 496 } 497 } else if (dim1 == PS_DIMEN_IMAGE) { 498 if (dim2 == PS_DIMEN_SCALAR) { 499 BINARY_OP(IMAGE, SCALAR, out, psType1, op, psType2); // image op scalar 500 } else if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 501 BINARY_OP(IMAGE, VECTOR, out, psType1, op, psType2); // image op vector 502 } else if (dim2 == PS_DIMEN_IMAGE) { 503 BINARY_OP(IMAGE, IMAGE, out, psType1, op, psType2); // image op image 504 } else { 505 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 506 } 507 } else { 508 psError(__func__, ": Line %d - Invalid dimensionality for in1 arg: %d", __LINE__, dim1); 509 } 506 510 507 511 return out; … … 567 571 } \ 568 572 } 569 570 573 571 574 // Preprocessor macro function to create arithmetic function based on input type … … 596 599 } 597 600 598 599 601 // Preprocessor macro function to create arithmetic function operation name 600 602 #define UNARY_OP(DIM,OUT,IN,OP) \ … … 714 716 psType *psTypeOut = NULL; 715 717 716 psTypeOut = (psType *)out;717 if (psTypeOut == NULL) {718 psTypeOut = (psType *) out; 719 if (psTypeOut == NULL) { 718 720 psError(__func__, ": Line %d - Null out argument", __LINE__); 719 721 return out; 720 722 } 721 723 722 psTypeIn = (psType *)in;723 if (psTypeIn == NULL) {724 psTypeIn = (psType *) in; 725 if (psTypeIn == NULL) { 724 726 psError(__func__, ": Line %d - Null in argument", __LINE__); 725 727 return out; 726 728 } 727 729 728 if (op == NULL) {730 if (op == NULL) { 729 731 psError(__func__, ": Line %d - Null op argument", __LINE__); 730 732 return out; … … 736 738 elTypeOut = psTypeOut->type; 737 739 738 if (elTypeIn!=elTypeOut) {740 if (elTypeIn != elTypeOut) { 739 741 psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d)", __LINE__, 740 742 elTypeIn, elTypeOut); … … 742 744 } 743 745 744 if (dimIn!=dimOut) {746 if (dimIn != dimOut) { 745 747 psError(__func__, ": Line %d - Dimensionality for arguments inconsistent: (%d, %d)", __LINE__, 746 748 dimIn, dimOut); … … 748 750 } 749 751 750 if (dimIn==PS_DIMEN_OTHER || dimOut==PS_DIMEN_OTHER) {752 if (dimIn == PS_DIMEN_OTHER || dimOut == PS_DIMEN_OTHER) { 751 753 psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d)", __LINE__, 752 754 dimIn, dimOut); … … 754 756 } 755 757 756 if (dimIn == PS_DIMEN_VECTOR) {757 if (((psVector*)in)->n == 0) {758 if (dimIn == PS_DIMEN_VECTOR) { 759 if (((psVector *) in)->n == 0) { 758 760 psError(__func__, ": Line %d - Vector contains zero elements"); 759 761 } 760 } else 761 if(dimIn == PS_DIMEN_IMAGE) { 762 if(((psImage*)in)->numCols==0 || ((psImage*)in)->numRows==0) { 763 psError(__func__, ": Line %d - Image contains zero length row or cols"); 764 } 765 } 766 767 if(dimOut == PS_DIMEN_VECTOR) { 768 if(((psVector*)out)->n == 0) { 762 } else if (dimIn == PS_DIMEN_IMAGE) { 763 if (((psImage *) in)->numCols == 0 || ((psImage *) in)->numRows == 0) { 764 psError(__func__, ": Line %d - Image contains zero length row or cols"); 765 } 766 } 767 768 if (dimOut == PS_DIMEN_VECTOR) { 769 if (((psVector *) out)->n == 0) { 769 770 psError(__func__, ": Line %d - Vector contains zero elements"); 770 771 } 771 } else 772 if(dimOut == PS_DIMEN_IMAGE) { 773 if(((psImage*)out)->numCols==0 || ((psImage*)out)->numRows==0) { 774 psError(__func__, ": Line %d - Image contains zero length row or cols"); 775 } 776 } 777 778 if(dimIn == PS_DIMEN_SCALAR) { 779 UNARY_OP(SCALAR,out,psTypeIn,op); // scalar 780 } else 781 if(dimIn==PS_DIMEN_VECTOR || dimIn==PS_DIMEN_TRANSV) { 782 UNARY_OP(VECTOR,out,psTypeIn,op); // vector 783 } else 784 if(dimIn == PS_DIMEN_IMAGE) { 785 UNARY_OP(IMAGE,out,psTypeIn,op); // image 786 } else { 787 psError(__func__, ": Line %d - Invalid dimensionality for in arg: %d", __LINE__, dimIn); 788 } 772 } else if (dimOut == PS_DIMEN_IMAGE) { 773 if (((psImage *) out)->numCols == 0 || ((psImage *) out)->numRows == 0) { 774 psError(__func__, ": Line %d - Image contains zero length row or cols"); 775 } 776 } 777 778 if (dimIn == PS_DIMEN_SCALAR) { 779 UNARY_OP(SCALAR, out, psTypeIn, op); // scalar 780 } else if (dimIn == PS_DIMEN_VECTOR || dimIn == PS_DIMEN_TRANSV) { 781 UNARY_OP(VECTOR, out, psTypeIn, op); // vector 782 } else if (dimIn == PS_DIMEN_IMAGE) { 783 UNARY_OP(IMAGE, out, psTypeIn, op); // image 784 } else { 785 psError(__func__, ": Line %d - Invalid dimensionality for in arg: %d", __LINE__, dimIn); 786 } 789 787 790 788 return out;
Note:
See TracChangeset
for help on using the changeset viewer.
