comparison src/xpow.cc @ 4153:6b96ce9f5743

[project @ 2002-11-06 20:38:49 by jwe]
author jwe
date Wed, 06 Nov 2002 20:38:50 +0000
parents 7690958e7726
children 79df15d4470c
comparison
equal deleted inserted replaced
4152:f14251d33b01 4153:6b96ce9f5743
33 #include "EIG.h" 33 #include "EIG.h"
34 #include "dDiagMatrix.h" 34 #include "dDiagMatrix.h"
35 #include "dMatrix.h" 35 #include "dMatrix.h"
36 #include "mx-cm-cdm.h" 36 #include "mx-cm-cdm.h"
37 #include "oct-cmplx.h" 37 #include "oct-cmplx.h"
38 #include "quit.h"
38 39
39 #include "error.h" 40 #include "error.h"
40 #include "oct-obj.h" 41 #include "oct-obj.h"
41 #include "utils.h" 42 #include "utils.h"
42 #include "xpow.h" 43 #include "xpow.h"
498 { 499 {
499 Complex atmp (a); 500 Complex atmp (a);
500 ComplexMatrix result (nr, nc); 501 ComplexMatrix result (nr, nc);
501 for (int j = 0; j < nc; j++) 502 for (int j = 0; j < nc; j++)
502 for (int i = 0; i < nr; i++) 503 for (int i = 0; i < nr; i++)
503 result (i, j) = pow (atmp, b (i, j)); 504 {
505 OCTAVE_QUIT;
506 result (i, j) = pow (atmp, b (i, j));
507 }
504 508
505 retval = result; 509 retval = result;
506 } 510 }
507 else 511 else
508 { 512 {
509 Matrix result (nr, nc); 513 Matrix result (nr, nc);
510 for (int j = 0; j < nc; j++) 514 for (int j = 0; j < nc; j++)
511 for (int i = 0; i < nr; i++) 515 for (int i = 0; i < nr; i++)
512 result (i, j) = pow (a, b (i, j)); 516 {
517 OCTAVE_QUIT;
518 result (i, j) = pow (a, b (i, j));
519 }
513 520
514 retval = result; 521 retval = result;
515 } 522 }
516 523
517 return retval; 524 return retval;
526 533
527 ComplexMatrix result (nr, nc); 534 ComplexMatrix result (nr, nc);
528 Complex atmp (a); 535 Complex atmp (a);
529 for (int j = 0; j < nc; j++) 536 for (int j = 0; j < nc; j++)
530 for (int i = 0; i < nr; i++) 537 for (int i = 0; i < nr; i++)
531 result (i, j) = pow (atmp, b (i, j)); 538 {
539 OCTAVE_QUIT;
540 result (i, j) = pow (atmp, b (i, j));
541 }
532 542
533 return result; 543 return result;
534 } 544 }
535 545
536 // -*- 3 -*- 546 // -*- 3 -*-
546 { 556 {
547 ComplexMatrix result (nr, nc); 557 ComplexMatrix result (nr, nc);
548 for (int j = 0; j < nc; j++) 558 for (int j = 0; j < nc; j++)
549 for (int i = 0; i < nr; i++) 559 for (int i = 0; i < nr; i++)
550 { 560 {
561 OCTAVE_QUIT;
551 Complex atmp (a (i, j)); 562 Complex atmp (a (i, j));
552 result (i, j) = pow (atmp, b); 563 result (i, j) = pow (atmp, b);
553 } 564 }
554 565
555 retval = result; 566 retval = result;
557 else 568 else
558 { 569 {
559 Matrix result (nr, nc); 570 Matrix result (nr, nc);
560 for (int j = 0; j < nc; j++) 571 for (int j = 0; j < nc; j++)
561 for (int i = 0; i < nr; i++) 572 for (int i = 0; i < nr; i++)
562 result (i, j) = pow (a (i, j), b); 573 {
574 OCTAVE_QUIT;
575 result (i, j) = pow (a (i, j), b);
576 }
563 577
564 retval = result; 578 retval = result;
565 } 579 }
566 580
567 return retval; 581 return retval;
587 601
588 int convert_to_complex = 0; 602 int convert_to_complex = 0;
589 for (int j = 0; j < nc; j++) 603 for (int j = 0; j < nc; j++)
590 for (int i = 0; i < nr; i++) 604 for (int i = 0; i < nr; i++)
591 { 605 {
606 OCTAVE_QUIT;
592 double atmp = a (i, j); 607 double atmp = a (i, j);
593 double btmp = b (i, j); 608 double btmp = b (i, j);
594 if (atmp < 0.0 && static_cast<int> (btmp) != btmp) 609 if (atmp < 0.0 && static_cast<int> (btmp) != btmp)
595 { 610 {
596 convert_to_complex = 1; 611 convert_to_complex = 1;
605 ComplexMatrix complex_result (nr, nc); 620 ComplexMatrix complex_result (nr, nc);
606 621
607 for (int j = 0; j < nc; j++) 622 for (int j = 0; j < nc; j++)
608 for (int i = 0; i < nr; i++) 623 for (int i = 0; i < nr; i++)
609 { 624 {
625 OCTAVE_QUIT;
610 Complex atmp (a (i, j)); 626 Complex atmp (a (i, j));
611 Complex btmp (b (i, j)); 627 Complex btmp (b (i, j));
612 complex_result (i, j) = pow (atmp, btmp); 628 complex_result (i, j) = pow (atmp, btmp);
613 } 629 }
614 630
618 { 634 {
619 Matrix result (nr, nc); 635 Matrix result (nr, nc);
620 636
621 for (int j = 0; j < nc; j++) 637 for (int j = 0; j < nc; j++)
622 for (int i = 0; i < nr; i++) 638 for (int i = 0; i < nr; i++)
623 result (i, j) = pow (a (i, j), b (i, j)); 639 {
640 OCTAVE_QUIT;
641 result (i, j) = pow (a (i, j), b (i, j));
642 }
624 643
625 retval = result; 644 retval = result;
626 } 645 }
627 646
628 return retval; 647 return retval;
632 octave_value 651 octave_value
633 elem_xpow (const Matrix& a, const Complex& b) 652 elem_xpow (const Matrix& a, const Complex& b)
634 { 653 {
635 int nr = a.rows (); 654 int nr = a.rows ();
636 int nc = a.cols (); 655 int nc = a.cols ();
637
638 ComplexMatrix result (nr, nc);
639 for (int j = 0; j < nc; j++)
640 for (int i = 0; i < nr; i++)
641 result (i, j) = pow (Complex (a (i, j)), b);
642
643 return result;
644 }
645
646 // -*- 6 -*-
647 octave_value
648 elem_xpow (const Matrix& a, const ComplexMatrix& b)
649 {
650 int nr = a.rows ();
651 int nc = a.cols ();
652
653 int b_nr = b.rows ();
654 int b_nc = b.cols ();
655
656 if (nr != b_nr || nc != b_nc)
657 {
658 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
659 return octave_value ();
660 }
661
662 ComplexMatrix result (nr, nc);
663 for (int j = 0; j < nc; j++)
664 for (int i = 0; i < nr; i++)
665 result (i, j) = pow (Complex (a (i, j)), b (i, j));
666
667 return result;
668 }
669
670 // -*- 7 -*-
671 octave_value
672 elem_xpow (const Complex& a, const Matrix& b)
673 {
674 int nr = b.rows ();
675 int nc = b.cols ();
676 656
677 ComplexMatrix result (nr, nc); 657 ComplexMatrix result (nr, nc);
678 for (int j = 0; j < nc; j++) 658 for (int j = 0; j < nc; j++)
679 for (int i = 0; i < nr; i++) 659 for (int i = 0; i < nr; i++)
680 { 660 {
661 OCTAVE_QUIT;
662 result (i, j) = pow (Complex (a (i, j)), b);
663 }
664
665 return result;
666 }
667
668 // -*- 6 -*-
669 octave_value
670 elem_xpow (const Matrix& a, const ComplexMatrix& b)
671 {
672 int nr = a.rows ();
673 int nc = a.cols ();
674
675 int b_nr = b.rows ();
676 int b_nc = b.cols ();
677
678 if (nr != b_nr || nc != b_nc)
679 {
680 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
681 return octave_value ();
682 }
683
684 ComplexMatrix result (nr, nc);
685 for (int j = 0; j < nc; j++)
686 for (int i = 0; i < nr; i++)
687 {
688 OCTAVE_QUIT;
689 result (i, j) = pow (Complex (a (i, j)), b (i, j));
690 }
691
692 return result;
693 }
694
695 // -*- 7 -*-
696 octave_value
697 elem_xpow (const Complex& a, const Matrix& b)
698 {
699 int nr = b.rows ();
700 int nc = b.cols ();
701
702 ComplexMatrix result (nr, nc);
703 for (int j = 0; j < nc; j++)
704 for (int i = 0; i < nr; i++)
705 {
706 OCTAVE_QUIT;
681 double btmp = b (i, j); 707 double btmp = b (i, j);
682 if (xisint (btmp)) 708 if (xisint (btmp))
683 result (i, j) = pow (a, static_cast<int> (btmp)); 709 result (i, j) = pow (a, static_cast<int> (btmp));
684 else 710 else
685 result (i, j) = pow (a, btmp); 711 result (i, j) = pow (a, btmp);
696 int nc = b.cols (); 722 int nc = b.cols ();
697 723
698 ComplexMatrix result (nr, nc); 724 ComplexMatrix result (nr, nc);
699 for (int j = 0; j < nc; j++) 725 for (int j = 0; j < nc; j++)
700 for (int i = 0; i < nr; i++) 726 for (int i = 0; i < nr; i++)
701 result (i, j) = pow (a, b (i, j)); 727 {
728 OCTAVE_QUIT;
729 result (i, j) = pow (a, b (i, j));
730 }
702 731
703 return result; 732 return result;
704 } 733 }
705 734
706 // -*- 9 -*- 735 // -*- 9 -*-
714 743
715 if (xisint (b)) 744 if (xisint (b))
716 { 745 {
717 for (int j = 0; j < nc; j++) 746 for (int j = 0; j < nc; j++)
718 for (int i = 0; i < nr; i++) 747 for (int i = 0; i < nr; i++)
719 result (i, j) = pow (a (i, j), static_cast<int> (b)); 748 {
749 OCTAVE_QUIT;
750 result (i, j) = pow (a (i, j), static_cast<int> (b));
751 }
720 } 752 }
721 else 753 else
722 { 754 {
723 for (int j = 0; j < nc; j++) 755 for (int j = 0; j < nc; j++)
724 for (int i = 0; i < nr; i++) 756 for (int i = 0; i < nr; i++)
725 result (i, j) = pow (a (i, j), b); 757 {
758 OCTAVE_QUIT;
759 result (i, j) = pow (a (i, j), b);
760 }
726 } 761 }
727 762
728 return result; 763 return result;
729 } 764 }
730 765
746 781
747 ComplexMatrix result (nr, nc); 782 ComplexMatrix result (nr, nc);
748 for (int j = 0; j < nc; j++) 783 for (int j = 0; j < nc; j++)
749 for (int i = 0; i < nr; i++) 784 for (int i = 0; i < nr; i++)
750 { 785 {
786 OCTAVE_QUIT;
751 double btmp = b (i, j); 787 double btmp = b (i, j);
752 if (xisint (btmp)) 788 if (xisint (btmp))
753 result (i, j) = pow (a (i, j), static_cast<int> (btmp)); 789 result (i, j) = pow (a (i, j), static_cast<int> (btmp));
754 else 790 else
755 result (i, j) = pow (a (i, j), btmp); 791 result (i, j) = pow (a (i, j), btmp);
766 int nc = a.cols (); 802 int nc = a.cols ();
767 803
768 ComplexMatrix result (nr, nc); 804 ComplexMatrix result (nr, nc);
769 for (int j = 0; j < nc; j++) 805 for (int j = 0; j < nc; j++)
770 for (int i = 0; i < nr; i++) 806 for (int i = 0; i < nr; i++)
771 result (i, j) = pow (a (i, j), b); 807 {
808 OCTAVE_QUIT;
809 result (i, j) = pow (a (i, j), b);
810 }
772 811
773 return result; 812 return result;
774 } 813 }
775 814
776 // -*- 12 -*- 815 // -*- 12 -*-
790 } 829 }
791 830
792 ComplexMatrix result (nr, nc); 831 ComplexMatrix result (nr, nc);
793 for (int j = 0; j < nc; j++) 832 for (int j = 0; j < nc; j++)
794 for (int i = 0; i < nr; i++) 833 for (int i = 0; i < nr; i++)
795 result (i, j) = pow (a (i, j), b (i, j)); 834 {
835 OCTAVE_QUIT;
836 result (i, j) = pow (a (i, j), b (i, j));
837 }
796 838
797 return result; 839 return result;
798 } 840 }
799 841
800 /* 842 /*