Mercurial > jwe > octave
comparison liboctave/array/fCMatrix.cc @ 21136:7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
* Array-util.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MArray.cc,
PermMatrix.cc, Sparse.cc, Sparse.h, chMatrix.cc, chNDArray.cc, dColVector.cc,
dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc,
fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc,
fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc,
idx-vector.cc, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc,
CmplxLU.cc, CmplxQR.cc, CmplxSCHUR.cc, CmplxSVD.cc, DASPK.cc, EIG.cc, LSODE.cc,
Quad.cc, SparseCmplxCHOL.cc, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseQR.cc,
SparsedbleCHOL.cc, SparsedbleLU.cc, base-lu.cc, bsxfun-defs.cc, dbleAEPBAL.cc,
dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc, dbleSCHUR.cc,
dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc, fCmplxCHOL.cc, fCmplxLU.cc,
fCmplxQR.cc, fCmplxSCHUR.cc, fEIG.cc, floatAEPBAL.cc, floatCHOL.cc,
floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc, floatSCHUR.cc,
floatSVD.cc, lo-specfun.cc, oct-fftw.cc, oct-rand.cc, oct-spparms.cc,
sparse-base-chol.cc, sparse-dmsolve.cc, file-ops.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-syscalls.cc, cmd-edit.cc, cmd-hist.cc,
data-conv.cc, lo-ieee.cc, lo-regexp.cc, oct-base64.cc, oct-shlib.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-util.cc, unwind-prot.cc:
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 23 Jan 2016 13:52:03 -0800 |
parents | 228b65504557 |
children | 40051830f89b |
comparison
equal
deleted
inserted
replaced
21135:95da3bc8a281 | 21136:7cac4e7458f2 |
---|---|
405 { | 405 { |
406 octave_idx_type a_nr = a.rows (); | 406 octave_idx_type a_nr = a.rows (); |
407 octave_idx_type a_nc = a.cols (); | 407 octave_idx_type a_nc = a.cols (); |
408 | 408 |
409 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) | 409 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) |
410 { | 410 (*current_liboctave_error_handler) ("range error for insert"); |
411 (*current_liboctave_error_handler) ("range error for insert"); | |
412 return *this; | |
413 } | |
414 | 411 |
415 if (a_nr >0 && a_nc > 0) | 412 if (a_nr >0 && a_nc > 0) |
416 { | 413 { |
417 make_unique (); | 414 make_unique (); |
418 | 415 |
429 octave_idx_type r, octave_idx_type c) | 426 octave_idx_type r, octave_idx_type c) |
430 { | 427 { |
431 octave_idx_type a_len = a.numel (); | 428 octave_idx_type a_len = a.numel (); |
432 | 429 |
433 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) | 430 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) |
434 { | 431 (*current_liboctave_error_handler) ("range error for insert"); |
435 (*current_liboctave_error_handler) ("range error for insert"); | |
436 return *this; | |
437 } | |
438 | 432 |
439 if (a_len > 0) | 433 if (a_len > 0) |
440 { | 434 { |
441 make_unique (); | 435 make_unique (); |
442 | 436 |
452 octave_idx_type r, octave_idx_type c) | 446 octave_idx_type r, octave_idx_type c) |
453 { | 447 { |
454 octave_idx_type a_len = a.numel (); | 448 octave_idx_type a_len = a.numel (); |
455 | 449 |
456 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) | 450 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) |
457 { | 451 (*current_liboctave_error_handler) ("range error for insert"); |
458 (*current_liboctave_error_handler) ("range error for insert"); | |
459 return *this; | |
460 } | |
461 | 452 |
462 if (a_len > 0) | 453 if (a_len > 0) |
463 { | 454 { |
464 make_unique (); | 455 make_unique (); |
465 | 456 |
476 { | 467 { |
477 octave_idx_type a_nr = a.rows (); | 468 octave_idx_type a_nr = a.rows (); |
478 octave_idx_type a_nc = a.cols (); | 469 octave_idx_type a_nc = a.cols (); |
479 | 470 |
480 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) | 471 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) |
481 { | 472 (*current_liboctave_error_handler) ("range error for insert"); |
482 (*current_liboctave_error_handler) ("range error for insert"); | |
483 return *this; | |
484 } | |
485 | 473 |
486 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); | 474 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); |
487 | 475 |
488 octave_idx_type a_len = a.length (); | 476 octave_idx_type a_len = a.length (); |
489 | 477 |
510 FloatComplexMatrix::insert (const FloatComplexRowVector& a, | 498 FloatComplexMatrix::insert (const FloatComplexRowVector& a, |
511 octave_idx_type r, octave_idx_type c) | 499 octave_idx_type r, octave_idx_type c) |
512 { | 500 { |
513 octave_idx_type a_len = a.numel (); | 501 octave_idx_type a_len = a.numel (); |
514 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) | 502 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) |
515 { | 503 (*current_liboctave_error_handler) ("range error for insert"); |
516 (*current_liboctave_error_handler) ("range error for insert"); | |
517 return *this; | |
518 } | |
519 | 504 |
520 for (octave_idx_type i = 0; i < a_len; i++) | 505 for (octave_idx_type i = 0; i < a_len; i++) |
521 elem (r, c+i) = a.elem (i); | 506 elem (r, c+i) = a.elem (i); |
522 | 507 |
523 return *this; | 508 return *this; |
528 octave_idx_type r, octave_idx_type c) | 513 octave_idx_type r, octave_idx_type c) |
529 { | 514 { |
530 octave_idx_type a_len = a.numel (); | 515 octave_idx_type a_len = a.numel (); |
531 | 516 |
532 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) | 517 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) |
533 { | 518 (*current_liboctave_error_handler) ("range error for insert"); |
534 (*current_liboctave_error_handler) ("range error for insert"); | |
535 return *this; | |
536 } | |
537 | 519 |
538 if (a_len > 0) | 520 if (a_len > 0) |
539 { | 521 { |
540 make_unique (); | 522 make_unique (); |
541 | 523 |
552 { | 534 { |
553 octave_idx_type a_nr = a.rows (); | 535 octave_idx_type a_nr = a.rows (); |
554 octave_idx_type a_nc = a.cols (); | 536 octave_idx_type a_nc = a.cols (); |
555 | 537 |
556 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) | 538 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) |
557 { | 539 (*current_liboctave_error_handler) ("range error for insert"); |
558 (*current_liboctave_error_handler) ("range error for insert"); | |
559 return *this; | |
560 } | |
561 | 540 |
562 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); | 541 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); |
563 | 542 |
564 octave_idx_type a_len = a.length (); | 543 octave_idx_type a_len = a.length (); |
565 | 544 |
617 octave_idx_type nr = rows (); | 596 octave_idx_type nr = rows (); |
618 octave_idx_type nc = cols (); | 597 octave_idx_type nc = cols (); |
619 | 598 |
620 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 | 599 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 |
621 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) | 600 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) |
622 { | 601 (*current_liboctave_error_handler) ("range error for fill"); |
623 (*current_liboctave_error_handler) ("range error for fill"); | |
624 return *this; | |
625 } | |
626 | 602 |
627 if (r1 > r2) { std::swap (r1, r2); } | 603 if (r1 > r2) { std::swap (r1, r2); } |
628 if (c1 > c2) { std::swap (c1, c2); } | 604 if (c1 > c2) { std::swap (c1, c2); } |
629 | 605 |
630 if (r2 >= r1 && c2 >= c1) | 606 if (r2 >= r1 && c2 >= c1) |
647 octave_idx_type nr = rows (); | 623 octave_idx_type nr = rows (); |
648 octave_idx_type nc = cols (); | 624 octave_idx_type nc = cols (); |
649 | 625 |
650 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 | 626 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 |
651 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) | 627 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) |
652 { | 628 (*current_liboctave_error_handler) ("range error for fill"); |
653 (*current_liboctave_error_handler) ("range error for fill"); | |
654 return *this; | |
655 } | |
656 | 629 |
657 if (r1 > r2) { std::swap (r1, r2); } | 630 if (r1 > r2) { std::swap (r1, r2); } |
658 if (c1 > c2) { std::swap (c1, c2); } | 631 if (c1 > c2) { std::swap (c1, c2); } |
659 | 632 |
660 if (r2 >= r1 && c2 >=c1) | 633 if (r2 >= r1 && c2 >=c1) |
673 FloatComplexMatrix::append (const FloatMatrix& a) const | 646 FloatComplexMatrix::append (const FloatMatrix& a) const |
674 { | 647 { |
675 octave_idx_type nr = rows (); | 648 octave_idx_type nr = rows (); |
676 octave_idx_type nc = cols (); | 649 octave_idx_type nc = cols (); |
677 if (nr != a.rows ()) | 650 if (nr != a.rows ()) |
678 { | 651 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
679 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
680 return *this; | |
681 } | |
682 | 652 |
683 octave_idx_type nc_insert = nc; | 653 octave_idx_type nc_insert = nc; |
684 FloatComplexMatrix retval (nr, nc + a.cols ()); | 654 FloatComplexMatrix retval (nr, nc + a.cols ()); |
685 retval.insert (*this, 0, 0); | 655 retval.insert (*this, 0, 0); |
686 retval.insert (a, 0, nc_insert); | 656 retval.insert (a, 0, nc_insert); |
691 FloatComplexMatrix::append (const FloatRowVector& a) const | 661 FloatComplexMatrix::append (const FloatRowVector& a) const |
692 { | 662 { |
693 octave_idx_type nr = rows (); | 663 octave_idx_type nr = rows (); |
694 octave_idx_type nc = cols (); | 664 octave_idx_type nc = cols (); |
695 if (nr != 1) | 665 if (nr != 1) |
696 { | 666 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
697 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
698 return *this; | |
699 } | |
700 | 667 |
701 octave_idx_type nc_insert = nc; | 668 octave_idx_type nc_insert = nc; |
702 FloatComplexMatrix retval (nr, nc + a.numel ()); | 669 FloatComplexMatrix retval (nr, nc + a.numel ()); |
703 retval.insert (*this, 0, 0); | 670 retval.insert (*this, 0, 0); |
704 retval.insert (a, 0, nc_insert); | 671 retval.insert (a, 0, nc_insert); |
709 FloatComplexMatrix::append (const FloatColumnVector& a) const | 676 FloatComplexMatrix::append (const FloatColumnVector& a) const |
710 { | 677 { |
711 octave_idx_type nr = rows (); | 678 octave_idx_type nr = rows (); |
712 octave_idx_type nc = cols (); | 679 octave_idx_type nc = cols (); |
713 if (nr != a.numel ()) | 680 if (nr != a.numel ()) |
714 { | 681 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
715 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
716 return *this; | |
717 } | |
718 | 682 |
719 octave_idx_type nc_insert = nc; | 683 octave_idx_type nc_insert = nc; |
720 FloatComplexMatrix retval (nr, nc + 1); | 684 FloatComplexMatrix retval (nr, nc + 1); |
721 retval.insert (*this, 0, 0); | 685 retval.insert (*this, 0, 0); |
722 retval.insert (a, 0, nc_insert); | 686 retval.insert (a, 0, nc_insert); |
727 FloatComplexMatrix::append (const FloatDiagMatrix& a) const | 691 FloatComplexMatrix::append (const FloatDiagMatrix& a) const |
728 { | 692 { |
729 octave_idx_type nr = rows (); | 693 octave_idx_type nr = rows (); |
730 octave_idx_type nc = cols (); | 694 octave_idx_type nc = cols (); |
731 if (nr != a.rows ()) | 695 if (nr != a.rows ()) |
732 { | 696 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
733 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
734 return *this; | |
735 } | |
736 | 697 |
737 octave_idx_type nc_insert = nc; | 698 octave_idx_type nc_insert = nc; |
738 FloatComplexMatrix retval (nr, nc + a.cols ()); | 699 FloatComplexMatrix retval (nr, nc + a.cols ()); |
739 retval.insert (*this, 0, 0); | 700 retval.insert (*this, 0, 0); |
740 retval.insert (a, 0, nc_insert); | 701 retval.insert (a, 0, nc_insert); |
745 FloatComplexMatrix::append (const FloatComplexMatrix& a) const | 706 FloatComplexMatrix::append (const FloatComplexMatrix& a) const |
746 { | 707 { |
747 octave_idx_type nr = rows (); | 708 octave_idx_type nr = rows (); |
748 octave_idx_type nc = cols (); | 709 octave_idx_type nc = cols (); |
749 if (nr != a.rows ()) | 710 if (nr != a.rows ()) |
750 { | 711 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
751 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
752 return *this; | |
753 } | |
754 | 712 |
755 octave_idx_type nc_insert = nc; | 713 octave_idx_type nc_insert = nc; |
756 FloatComplexMatrix retval (nr, nc + a.cols ()); | 714 FloatComplexMatrix retval (nr, nc + a.cols ()); |
757 retval.insert (*this, 0, 0); | 715 retval.insert (*this, 0, 0); |
758 retval.insert (a, 0, nc_insert); | 716 retval.insert (a, 0, nc_insert); |
763 FloatComplexMatrix::append (const FloatComplexRowVector& a) const | 721 FloatComplexMatrix::append (const FloatComplexRowVector& a) const |
764 { | 722 { |
765 octave_idx_type nr = rows (); | 723 octave_idx_type nr = rows (); |
766 octave_idx_type nc = cols (); | 724 octave_idx_type nc = cols (); |
767 if (nr != 1) | 725 if (nr != 1) |
768 { | 726 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
769 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
770 return *this; | |
771 } | |
772 | 727 |
773 octave_idx_type nc_insert = nc; | 728 octave_idx_type nc_insert = nc; |
774 FloatComplexMatrix retval (nr, nc + a.numel ()); | 729 FloatComplexMatrix retval (nr, nc + a.numel ()); |
775 retval.insert (*this, 0, 0); | 730 retval.insert (*this, 0, 0); |
776 retval.insert (a, 0, nc_insert); | 731 retval.insert (a, 0, nc_insert); |
781 FloatComplexMatrix::append (const FloatComplexColumnVector& a) const | 736 FloatComplexMatrix::append (const FloatComplexColumnVector& a) const |
782 { | 737 { |
783 octave_idx_type nr = rows (); | 738 octave_idx_type nr = rows (); |
784 octave_idx_type nc = cols (); | 739 octave_idx_type nc = cols (); |
785 if (nr != a.numel ()) | 740 if (nr != a.numel ()) |
786 { | 741 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
787 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
788 return *this; | |
789 } | |
790 | 742 |
791 octave_idx_type nc_insert = nc; | 743 octave_idx_type nc_insert = nc; |
792 FloatComplexMatrix retval (nr, nc + 1); | 744 FloatComplexMatrix retval (nr, nc + 1); |
793 retval.insert (*this, 0, 0); | 745 retval.insert (*this, 0, 0); |
794 retval.insert (a, 0, nc_insert); | 746 retval.insert (a, 0, nc_insert); |
799 FloatComplexMatrix::append (const FloatComplexDiagMatrix& a) const | 751 FloatComplexMatrix::append (const FloatComplexDiagMatrix& a) const |
800 { | 752 { |
801 octave_idx_type nr = rows (); | 753 octave_idx_type nr = rows (); |
802 octave_idx_type nc = cols (); | 754 octave_idx_type nc = cols (); |
803 if (nr != a.rows ()) | 755 if (nr != a.rows ()) |
804 { | 756 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
805 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
806 return *this; | |
807 } | |
808 | 757 |
809 octave_idx_type nc_insert = nc; | 758 octave_idx_type nc_insert = nc; |
810 FloatComplexMatrix retval (nr, nc + a.cols ()); | 759 FloatComplexMatrix retval (nr, nc + a.cols ()); |
811 retval.insert (*this, 0, 0); | 760 retval.insert (*this, 0, 0); |
812 retval.insert (a, 0, nc_insert); | 761 retval.insert (a, 0, nc_insert); |
817 FloatComplexMatrix::stack (const FloatMatrix& a) const | 766 FloatComplexMatrix::stack (const FloatMatrix& a) const |
818 { | 767 { |
819 octave_idx_type nr = rows (); | 768 octave_idx_type nr = rows (); |
820 octave_idx_type nc = cols (); | 769 octave_idx_type nc = cols (); |
821 if (nc != a.cols ()) | 770 if (nc != a.cols ()) |
822 { | 771 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
823 (*current_liboctave_error_handler) | |
824 ("column dimension mismatch for stack"); | |
825 return *this; | |
826 } | |
827 | 772 |
828 octave_idx_type nr_insert = nr; | 773 octave_idx_type nr_insert = nr; |
829 FloatComplexMatrix retval (nr + a.rows (), nc); | 774 FloatComplexMatrix retval (nr + a.rows (), nc); |
830 retval.insert (*this, 0, 0); | 775 retval.insert (*this, 0, 0); |
831 retval.insert (a, nr_insert, 0); | 776 retval.insert (a, nr_insert, 0); |
836 FloatComplexMatrix::stack (const FloatRowVector& a) const | 781 FloatComplexMatrix::stack (const FloatRowVector& a) const |
837 { | 782 { |
838 octave_idx_type nr = rows (); | 783 octave_idx_type nr = rows (); |
839 octave_idx_type nc = cols (); | 784 octave_idx_type nc = cols (); |
840 if (nc != a.numel ()) | 785 if (nc != a.numel ()) |
841 { | 786 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
842 (*current_liboctave_error_handler) | |
843 ("column dimension mismatch for stack"); | |
844 return *this; | |
845 } | |
846 | 787 |
847 octave_idx_type nr_insert = nr; | 788 octave_idx_type nr_insert = nr; |
848 FloatComplexMatrix retval (nr + 1, nc); | 789 FloatComplexMatrix retval (nr + 1, nc); |
849 retval.insert (*this, 0, 0); | 790 retval.insert (*this, 0, 0); |
850 retval.insert (a, nr_insert, 0); | 791 retval.insert (a, nr_insert, 0); |
855 FloatComplexMatrix::stack (const FloatColumnVector& a) const | 796 FloatComplexMatrix::stack (const FloatColumnVector& a) const |
856 { | 797 { |
857 octave_idx_type nr = rows (); | 798 octave_idx_type nr = rows (); |
858 octave_idx_type nc = cols (); | 799 octave_idx_type nc = cols (); |
859 if (nc != 1) | 800 if (nc != 1) |
860 { | 801 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
861 (*current_liboctave_error_handler) | |
862 ("column dimension mismatch for stack"); | |
863 return *this; | |
864 } | |
865 | 802 |
866 octave_idx_type nr_insert = nr; | 803 octave_idx_type nr_insert = nr; |
867 FloatComplexMatrix retval (nr + a.numel (), nc); | 804 FloatComplexMatrix retval (nr + a.numel (), nc); |
868 retval.insert (*this, 0, 0); | 805 retval.insert (*this, 0, 0); |
869 retval.insert (a, nr_insert, 0); | 806 retval.insert (a, nr_insert, 0); |
874 FloatComplexMatrix::stack (const FloatDiagMatrix& a) const | 811 FloatComplexMatrix::stack (const FloatDiagMatrix& a) const |
875 { | 812 { |
876 octave_idx_type nr = rows (); | 813 octave_idx_type nr = rows (); |
877 octave_idx_type nc = cols (); | 814 octave_idx_type nc = cols (); |
878 if (nc != a.cols ()) | 815 if (nc != a.cols ()) |
879 { | 816 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
880 (*current_liboctave_error_handler) | |
881 ("column dimension mismatch for stack"); | |
882 return *this; | |
883 } | |
884 | 817 |
885 octave_idx_type nr_insert = nr; | 818 octave_idx_type nr_insert = nr; |
886 FloatComplexMatrix retval (nr + a.rows (), nc); | 819 FloatComplexMatrix retval (nr + a.rows (), nc); |
887 retval.insert (*this, 0, 0); | 820 retval.insert (*this, 0, 0); |
888 retval.insert (a, nr_insert, 0); | 821 retval.insert (a, nr_insert, 0); |
893 FloatComplexMatrix::stack (const FloatComplexMatrix& a) const | 826 FloatComplexMatrix::stack (const FloatComplexMatrix& a) const |
894 { | 827 { |
895 octave_idx_type nr = rows (); | 828 octave_idx_type nr = rows (); |
896 octave_idx_type nc = cols (); | 829 octave_idx_type nc = cols (); |
897 if (nc != a.cols ()) | 830 if (nc != a.cols ()) |
898 { | 831 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
899 (*current_liboctave_error_handler) | |
900 ("column dimension mismatch for stack"); | |
901 return *this; | |
902 } | |
903 | 832 |
904 octave_idx_type nr_insert = nr; | 833 octave_idx_type nr_insert = nr; |
905 FloatComplexMatrix retval (nr + a.rows (), nc); | 834 FloatComplexMatrix retval (nr + a.rows (), nc); |
906 retval.insert (*this, 0, 0); | 835 retval.insert (*this, 0, 0); |
907 retval.insert (a, nr_insert, 0); | 836 retval.insert (a, nr_insert, 0); |
912 FloatComplexMatrix::stack (const FloatComplexRowVector& a) const | 841 FloatComplexMatrix::stack (const FloatComplexRowVector& a) const |
913 { | 842 { |
914 octave_idx_type nr = rows (); | 843 octave_idx_type nr = rows (); |
915 octave_idx_type nc = cols (); | 844 octave_idx_type nc = cols (); |
916 if (nc != a.numel ()) | 845 if (nc != a.numel ()) |
917 { | 846 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
918 (*current_liboctave_error_handler) | |
919 ("column dimension mismatch for stack"); | |
920 return *this; | |
921 } | |
922 | 847 |
923 octave_idx_type nr_insert = nr; | 848 octave_idx_type nr_insert = nr; |
924 FloatComplexMatrix retval (nr + 1, nc); | 849 FloatComplexMatrix retval (nr + 1, nc); |
925 retval.insert (*this, 0, 0); | 850 retval.insert (*this, 0, 0); |
926 retval.insert (a, nr_insert, 0); | 851 retval.insert (a, nr_insert, 0); |
931 FloatComplexMatrix::stack (const FloatComplexColumnVector& a) const | 856 FloatComplexMatrix::stack (const FloatComplexColumnVector& a) const |
932 { | 857 { |
933 octave_idx_type nr = rows (); | 858 octave_idx_type nr = rows (); |
934 octave_idx_type nc = cols (); | 859 octave_idx_type nc = cols (); |
935 if (nc != 1) | 860 if (nc != 1) |
936 { | 861 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
937 (*current_liboctave_error_handler) | |
938 ("column dimension mismatch for stack"); | |
939 return *this; | |
940 } | |
941 | 862 |
942 octave_idx_type nr_insert = nr; | 863 octave_idx_type nr_insert = nr; |
943 FloatComplexMatrix retval (nr + a.numel (), nc); | 864 FloatComplexMatrix retval (nr + a.numel (), nc); |
944 retval.insert (*this, 0, 0); | 865 retval.insert (*this, 0, 0); |
945 retval.insert (a, nr_insert, 0); | 866 retval.insert (a, nr_insert, 0); |
950 FloatComplexMatrix::stack (const FloatComplexDiagMatrix& a) const | 871 FloatComplexMatrix::stack (const FloatComplexDiagMatrix& a) const |
951 { | 872 { |
952 octave_idx_type nr = rows (); | 873 octave_idx_type nr = rows (); |
953 octave_idx_type nc = cols (); | 874 octave_idx_type nc = cols (); |
954 if (nc != a.cols ()) | 875 if (nc != a.cols ()) |
955 { | 876 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
956 (*current_liboctave_error_handler) | |
957 ("column dimension mismatch for stack"); | |
958 return *this; | |
959 } | |
960 | 877 |
961 octave_idx_type nr_insert = nr; | 878 octave_idx_type nr_insert = nr; |
962 FloatComplexMatrix retval (nr + a.rows (), nc); | 879 FloatComplexMatrix retval (nr + a.rows (), nc); |
963 retval.insert (*this, 0, 0); | 880 retval.insert (*this, 0, 0); |
964 retval.insert (a, nr_insert, 0); | 881 retval.insert (a, nr_insert, 0); |
1053 octave_idx_type nr = rows (); | 970 octave_idx_type nr = rows (); |
1054 octave_idx_type nc = cols (); | 971 octave_idx_type nc = cols (); |
1055 | 972 |
1056 if (nr != nc || nr == 0 || nc == 0) | 973 if (nr != nc || nr == 0 || nc == 0) |
1057 (*current_liboctave_error_handler) ("inverse requires square matrix"); | 974 (*current_liboctave_error_handler) ("inverse requires square matrix"); |
1058 else | 975 |
1059 { | 976 int typ = mattype.type (); |
1060 int typ = mattype.type (); | 977 char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); |
1061 char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); | 978 char udiag = 'N'; |
1062 char udiag = 'N'; | 979 retval = *this; |
1063 retval = *this; | 980 FloatComplex *tmp_data = retval.fortran_vec (); |
1064 FloatComplex *tmp_data = retval.fortran_vec (); | 981 |
1065 | 982 F77_XFCN (ctrtri, CTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
1066 F77_XFCN (ctrtri, CTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), | 983 F77_CONST_CHAR_ARG2 (&udiag, 1), |
984 nr, tmp_data, nr, info | |
985 F77_CHAR_ARG_LEN (1) | |
986 F77_CHAR_ARG_LEN (1))); | |
987 | |
988 // Throw-away extra info LAPACK gives so as to not change output. | |
989 rcon = 0.0; | |
990 if (info != 0) | |
991 info = -1; | |
992 else if (calc_cond) | |
993 { | |
994 octave_idx_type ztrcon_info = 0; | |
995 char job = '1'; | |
996 | |
997 OCTAVE_LOCAL_BUFFER (FloatComplex, cwork, 2*nr); | |
998 OCTAVE_LOCAL_BUFFER (float, rwork, nr); | |
999 | |
1000 F77_XFCN (ctrcon, CTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), | |
1001 F77_CONST_CHAR_ARG2 (&uplo, 1), | |
1067 F77_CONST_CHAR_ARG2 (&udiag, 1), | 1002 F77_CONST_CHAR_ARG2 (&udiag, 1), |
1068 nr, tmp_data, nr, info | 1003 nr, tmp_data, nr, rcon, |
1004 cwork, rwork, ztrcon_info | |
1005 F77_CHAR_ARG_LEN (1) | |
1069 F77_CHAR_ARG_LEN (1) | 1006 F77_CHAR_ARG_LEN (1) |
1070 F77_CHAR_ARG_LEN (1))); | 1007 F77_CHAR_ARG_LEN (1))); |
1071 | 1008 |
1072 // Throw-away extra info LAPACK gives so as to not change output. | 1009 if (ztrcon_info != 0) |
1073 rcon = 0.0; | |
1074 if (info != 0) | |
1075 info = -1; | 1010 info = -1; |
1076 else if (calc_cond) | 1011 } |
1077 { | 1012 |
1078 octave_idx_type ztrcon_info = 0; | 1013 if (info == -1 && ! force) |
1079 char job = '1'; | 1014 retval = *this; // Restore matrix contents. |
1080 | |
1081 OCTAVE_LOCAL_BUFFER (FloatComplex, cwork, 2*nr); | |
1082 OCTAVE_LOCAL_BUFFER (float, rwork, nr); | |
1083 | |
1084 F77_XFCN (ctrcon, CTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), | |
1085 F77_CONST_CHAR_ARG2 (&uplo, 1), | |
1086 F77_CONST_CHAR_ARG2 (&udiag, 1), | |
1087 nr, tmp_data, nr, rcon, | |
1088 cwork, rwork, ztrcon_info | |
1089 F77_CHAR_ARG_LEN (1) | |
1090 F77_CHAR_ARG_LEN (1) | |
1091 F77_CHAR_ARG_LEN (1))); | |
1092 | |
1093 if (ztrcon_info != 0) | |
1094 info = -1; | |
1095 } | |
1096 | |
1097 if (info == -1 && ! force) | |
1098 retval = *this; // Restore matrix contents. | |
1099 } | |
1100 | 1015 |
1101 return retval; | 1016 return retval; |
1102 } | 1017 } |
1103 | 1018 |
1104 FloatComplexMatrix | 1019 FloatComplexMatrix |
1110 octave_idx_type nr = rows (); | 1025 octave_idx_type nr = rows (); |
1111 octave_idx_type nc = cols (); | 1026 octave_idx_type nc = cols (); |
1112 | 1027 |
1113 if (nr != nc) | 1028 if (nr != nc) |
1114 (*current_liboctave_error_handler) ("inverse requires square matrix"); | 1029 (*current_liboctave_error_handler) ("inverse requires square matrix"); |
1030 | |
1031 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); | |
1032 octave_idx_type *pipvt = ipvt.fortran_vec (); | |
1033 | |
1034 retval = *this; | |
1035 FloatComplex *tmp_data = retval.fortran_vec (); | |
1036 | |
1037 Array<FloatComplex> z (dim_vector (1, 1)); | |
1038 octave_idx_type lwork = -1; | |
1039 | |
1040 // Query the optimum work array size. | |
1041 | |
1042 F77_XFCN (cgetri, CGETRI, (nc, tmp_data, nr, pipvt, | |
1043 z.fortran_vec (), lwork, info)); | |
1044 | |
1045 lwork = static_cast<octave_idx_type> (std::real (z(0))); | |
1046 lwork = (lwork < 2 *nc ? 2*nc : lwork); | |
1047 z.resize (dim_vector (lwork, 1)); | |
1048 FloatComplex *pz = z.fortran_vec (); | |
1049 | |
1050 info = 0; | |
1051 | |
1052 // Calculate the norm of the matrix, for later use. | |
1053 float anorm; | |
1054 if (calc_cond) | |
1055 anorm = retval.abs ().sum ().row (static_cast<octave_idx_type>(0)) | |
1056 .max (); | |
1057 | |
1058 F77_XFCN (cgetrf, CGETRF, (nc, nc, tmp_data, nr, pipvt, info)); | |
1059 | |
1060 // Throw-away extra info LAPACK gives so as to not change output. | |
1061 rcon = 0.0; | |
1062 if (info != 0) | |
1063 info = -1; | |
1064 else if (calc_cond) | |
1065 { | |
1066 // Now calculate the condition number for non-singular matrix. | |
1067 octave_idx_type zgecon_info = 0; | |
1068 char job = '1'; | |
1069 Array<float> rz (dim_vector (2 * nc, 1)); | |
1070 float *prz = rz.fortran_vec (); | |
1071 F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), | |
1072 nc, tmp_data, nr, anorm, | |
1073 rcon, pz, prz, zgecon_info | |
1074 F77_CHAR_ARG_LEN (1))); | |
1075 | |
1076 if (zgecon_info != 0) | |
1077 info = -1; | |
1078 } | |
1079 | |
1080 if (info == -1 && ! force) | |
1081 retval = *this; // Restore contents. | |
1115 else | 1082 else |
1116 { | 1083 { |
1117 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); | 1084 octave_idx_type zgetri_info = 0; |
1118 octave_idx_type *pipvt = ipvt.fortran_vec (); | |
1119 | |
1120 retval = *this; | |
1121 FloatComplex *tmp_data = retval.fortran_vec (); | |
1122 | |
1123 Array<FloatComplex> z (dim_vector (1, 1)); | |
1124 octave_idx_type lwork = -1; | |
1125 | |
1126 // Query the optimum work array size. | |
1127 | 1085 |
1128 F77_XFCN (cgetri, CGETRI, (nc, tmp_data, nr, pipvt, | 1086 F77_XFCN (cgetri, CGETRI, (nc, tmp_data, nr, pipvt, |
1129 z.fortran_vec (), lwork, info)); | 1087 pz, lwork, zgetri_info)); |
1130 | 1088 |
1131 lwork = static_cast<octave_idx_type> (std::real (z(0))); | 1089 if (zgetri_info != 0) |
1132 lwork = (lwork < 2 *nc ? 2*nc : lwork); | |
1133 z.resize (dim_vector (lwork, 1)); | |
1134 FloatComplex *pz = z.fortran_vec (); | |
1135 | |
1136 info = 0; | |
1137 | |
1138 // Calculate the norm of the matrix, for later use. | |
1139 float anorm; | |
1140 if (calc_cond) | |
1141 anorm = retval.abs ().sum ().row (static_cast<octave_idx_type>(0)) | |
1142 .max (); | |
1143 | |
1144 F77_XFCN (cgetrf, CGETRF, (nc, nc, tmp_data, nr, pipvt, info)); | |
1145 | |
1146 // Throw-away extra info LAPACK gives so as to not change output. | |
1147 rcon = 0.0; | |
1148 if (info != 0) | |
1149 info = -1; | 1090 info = -1; |
1150 else if (calc_cond) | 1091 } |
1151 { | 1092 |
1152 // Now calculate the condition number for non-singular matrix. | 1093 if (info != 0) |
1153 octave_idx_type zgecon_info = 0; | 1094 mattype.mark_as_rectangular (); |
1154 char job = '1'; | |
1155 Array<float> rz (dim_vector (2 * nc, 1)); | |
1156 float *prz = rz.fortran_vec (); | |
1157 F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), | |
1158 nc, tmp_data, nr, anorm, | |
1159 rcon, pz, prz, zgecon_info | |
1160 F77_CHAR_ARG_LEN (1))); | |
1161 | |
1162 if (zgecon_info != 0) | |
1163 info = -1; | |
1164 } | |
1165 | |
1166 if (info == -1 && ! force) | |
1167 retval = *this; // Restore contents. | |
1168 else | |
1169 { | |
1170 octave_idx_type zgetri_info = 0; | |
1171 | |
1172 F77_XFCN (cgetri, CGETRI, (nc, tmp_data, nr, pipvt, | |
1173 pz, lwork, zgetri_info)); | |
1174 | |
1175 if (zgetri_info != 0) | |
1176 info = -1; | |
1177 } | |
1178 | |
1179 if (info != 0) | |
1180 mattype.mark_as_rectangular (); | |
1181 } | |
1182 | 1095 |
1183 return retval; | 1096 return retval; |
1184 } | 1097 } |
1185 | 1098 |
1186 FloatComplexMatrix | 1099 FloatComplexMatrix |
1626 octave_idx_type nr = rows (); | 1539 octave_idx_type nr = rows (); |
1627 octave_idx_type nc = cols (); | 1540 octave_idx_type nc = cols (); |
1628 | 1541 |
1629 if (nr != nc) | 1542 if (nr != nc) |
1630 (*current_liboctave_error_handler) ("matrix must be square"); | 1543 (*current_liboctave_error_handler) ("matrix must be square"); |
1631 else | 1544 |
1632 { | 1545 volatile int typ = mattype.type (); |
1633 volatile int typ = mattype.type (); | 1546 |
1634 | 1547 // Even though the matrix is marked as singular (Rectangular), we may |
1635 // Even though the matrix is marked as singular (Rectangular), we may | 1548 // still get a useful number from the LU factorization, because it always |
1636 // still get a useful number from the LU factorization, because it always | 1549 // completes. |
1637 // completes. | 1550 |
1638 | 1551 if (typ == MatrixType::Unknown) |
1639 if (typ == MatrixType::Unknown) | 1552 typ = mattype.type (*this); |
1640 typ = mattype.type (*this); | 1553 else if (typ == MatrixType::Rectangular) |
1641 else if (typ == MatrixType::Rectangular) | 1554 typ = MatrixType::Full; |
1642 typ = MatrixType::Full; | 1555 |
1643 | 1556 if (typ == MatrixType::Lower || typ == MatrixType::Upper) |
1644 if (typ == MatrixType::Lower || typ == MatrixType::Upper) | 1557 { |
1558 for (octave_idx_type i = 0; i < nc; i++) | |
1559 retval *= elem (i,i); | |
1560 } | |
1561 else if (typ == MatrixType::Hermitian) | |
1562 { | |
1563 FloatComplexMatrix atmp = *this; | |
1564 FloatComplex *tmp_data = atmp.fortran_vec (); | |
1565 | |
1566 float anorm = 0; | |
1567 if (calc_cond) anorm = xnorm (*this, 1); | |
1568 | |
1569 | |
1570 char job = 'L'; | |
1571 F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, | |
1572 tmp_data, nr, info | |
1573 F77_CHAR_ARG_LEN (1))); | |
1574 | |
1575 if (info != 0) | |
1645 { | 1576 { |
1577 rcon = 0.0; | |
1578 mattype.mark_as_unsymmetric (); | |
1579 typ = MatrixType::Full; | |
1580 } | |
1581 else | |
1582 { | |
1583 Array<FloatComplex> z (dim_vector (2 * nc, 1)); | |
1584 FloatComplex *pz = z.fortran_vec (); | |
1585 Array<float> rz (dim_vector (nc, 1)); | |
1586 float *prz = rz.fortran_vec (); | |
1587 | |
1588 F77_XFCN (cpocon, CPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), | |
1589 nr, tmp_data, nr, anorm, | |
1590 rcon, pz, prz, info | |
1591 F77_CHAR_ARG_LEN (1))); | |
1592 | |
1593 if (info != 0) | |
1594 rcon = 0.0; | |
1595 | |
1646 for (octave_idx_type i = 0; i < nc; i++) | 1596 for (octave_idx_type i = 0; i < nc; i++) |
1647 retval *= elem (i,i); | 1597 retval *= atmp (i,i); |
1598 | |
1599 retval = retval.square (); | |
1648 } | 1600 } |
1649 else if (typ == MatrixType::Hermitian) | 1601 } |
1602 else if (typ != MatrixType::Full) | |
1603 (*current_liboctave_error_handler) ("det: invalid dense matrix type"); | |
1604 | |
1605 if (typ == MatrixType::Full) | |
1606 { | |
1607 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); | |
1608 octave_idx_type *pipvt = ipvt.fortran_vec (); | |
1609 | |
1610 FloatComplexMatrix atmp = *this; | |
1611 FloatComplex *tmp_data = atmp.fortran_vec (); | |
1612 | |
1613 info = 0; | |
1614 | |
1615 // Calculate the norm of the matrix, for later use. | |
1616 float anorm = 0; | |
1617 if (calc_cond) anorm = xnorm (*this, 1); | |
1618 | |
1619 F77_XFCN (cgetrf, CGETRF, (nr, nr, tmp_data, nr, pipvt, info)); | |
1620 | |
1621 // Throw-away extra info LAPACK gives so as to not change output. | |
1622 rcon = 0.0; | |
1623 if (info != 0) | |
1650 { | 1624 { |
1651 FloatComplexMatrix atmp = *this; | 1625 info = -1; |
1652 FloatComplex *tmp_data = atmp.fortran_vec (); | 1626 retval = FloatComplexDET (); |
1653 | 1627 } |
1654 float anorm = 0; | 1628 else |
1655 if (calc_cond) anorm = xnorm (*this, 1); | 1629 { |
1656 | 1630 if (calc_cond) |
1657 | |
1658 char job = 'L'; | |
1659 F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, | |
1660 tmp_data, nr, info | |
1661 F77_CHAR_ARG_LEN (1))); | |
1662 | |
1663 if (info != 0) | |
1664 { | 1631 { |
1665 rcon = 0.0; | 1632 // Now calc the condition number for non-singular matrix. |
1666 mattype.mark_as_unsymmetric (); | 1633 char job = '1'; |
1667 typ = MatrixType::Full; | |
1668 } | |
1669 else | |
1670 { | |
1671 Array<FloatComplex> z (dim_vector (2 * nc, 1)); | 1634 Array<FloatComplex> z (dim_vector (2 * nc, 1)); |
1672 FloatComplex *pz = z.fortran_vec (); | 1635 FloatComplex *pz = z.fortran_vec (); |
1673 Array<float> rz (dim_vector (nc, 1)); | 1636 Array<float> rz (dim_vector (2 * nc, 1)); |
1674 float *prz = rz.fortran_vec (); | 1637 float *prz = rz.fortran_vec (); |
1675 | 1638 |
1676 F77_XFCN (cpocon, CPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), | 1639 F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
1677 nr, tmp_data, nr, anorm, | 1640 nc, tmp_data, nr, anorm, |
1678 rcon, pz, prz, info | 1641 rcon, pz, prz, info |
1679 F77_CHAR_ARG_LEN (1))); | 1642 F77_CHAR_ARG_LEN (1))); |
1680 | |
1681 if (info != 0) | |
1682 rcon = 0.0; | |
1683 | |
1684 for (octave_idx_type i = 0; i < nc; i++) | |
1685 retval *= atmp (i,i); | |
1686 | |
1687 retval = retval.square (); | |
1688 } | 1643 } |
1689 } | 1644 |
1690 else if (typ != MatrixType::Full) | |
1691 (*current_liboctave_error_handler) ("det: invalid dense matrix type"); | |
1692 | |
1693 if (typ == MatrixType::Full) | |
1694 { | |
1695 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); | |
1696 octave_idx_type *pipvt = ipvt.fortran_vec (); | |
1697 | |
1698 FloatComplexMatrix atmp = *this; | |
1699 FloatComplex *tmp_data = atmp.fortran_vec (); | |
1700 | |
1701 info = 0; | |
1702 | |
1703 // Calculate the norm of the matrix, for later use. | |
1704 float anorm = 0; | |
1705 if (calc_cond) anorm = xnorm (*this, 1); | |
1706 | |
1707 F77_XFCN (cgetrf, CGETRF, (nr, nr, tmp_data, nr, pipvt, info)); | |
1708 | |
1709 // Throw-away extra info LAPACK gives so as to not change output. | |
1710 rcon = 0.0; | |
1711 if (info != 0) | 1645 if (info != 0) |
1712 { | 1646 { |
1713 info = -1; | 1647 info = -1; |
1714 retval = FloatComplexDET (); | 1648 retval = FloatComplexDET (); |
1715 } | 1649 } |
1716 else | 1650 else |
1717 { | 1651 { |
1718 if (calc_cond) | 1652 for (octave_idx_type i = 0; i < nc; i++) |
1719 { | 1653 { |
1720 // Now calc the condition number for non-singular matrix. | 1654 FloatComplex c = atmp(i,i); |
1721 char job = '1'; | 1655 retval *= (ipvt(i) != (i+1)) ? -c : c; |
1722 Array<FloatComplex> z (dim_vector (2 * nc, 1)); | |
1723 FloatComplex *pz = z.fortran_vec (); | |
1724 Array<float> rz (dim_vector (2 * nc, 1)); | |
1725 float *prz = rz.fortran_vec (); | |
1726 | |
1727 F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), | |
1728 nc, tmp_data, nr, anorm, | |
1729 rcon, pz, prz, info | |
1730 F77_CHAR_ARG_LEN (1))); | |
1731 } | |
1732 | |
1733 if (info != 0) | |
1734 { | |
1735 info = -1; | |
1736 retval = FloatComplexDET (); | |
1737 } | |
1738 else | |
1739 { | |
1740 for (octave_idx_type i = 0; i < nc; i++) | |
1741 { | |
1742 FloatComplex c = atmp(i,i); | |
1743 retval *= (ipvt(i) != (i+1)) ? -c : c; | |
1744 } | |
1745 } | 1656 } |
1746 } | 1657 } |
1747 } | 1658 } |
1748 } | 1659 } |
1749 | 1660 |
1764 octave_idx_type nr = rows (); | 1675 octave_idx_type nr = rows (); |
1765 octave_idx_type nc = cols (); | 1676 octave_idx_type nc = cols (); |
1766 | 1677 |
1767 if (nr != nc) | 1678 if (nr != nc) |
1768 (*current_liboctave_error_handler) ("matrix must be square"); | 1679 (*current_liboctave_error_handler) ("matrix must be square"); |
1769 else if (nr == 0 || nc == 0) | 1680 |
1681 if (nr == 0 || nc == 0) | |
1770 rcon = octave_Inf; | 1682 rcon = octave_Inf; |
1771 else | 1683 else |
1772 { | 1684 { |
1773 volatile int typ = mattype.type (); | 1685 volatile int typ = mattype.type (); |
1774 | 1686 |
1934 octave_idx_type nc = cols (); | 1846 octave_idx_type nc = cols (); |
1935 | 1847 |
1936 if (nr != b.rows ()) | 1848 if (nr != b.rows ()) |
1937 (*current_liboctave_error_handler) | 1849 (*current_liboctave_error_handler) |
1938 ("matrix dimension mismatch solution of linear equations"); | 1850 ("matrix dimension mismatch solution of linear equations"); |
1939 else if (nr == 0 || nc == 0 || b.cols () == 0) | 1851 |
1852 if (nr == 0 || nc == 0 || b.cols () == 0) | |
1940 retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); | 1853 retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); |
1941 else | 1854 else |
1942 { | 1855 { |
1943 volatile int typ = mattype.type (); | 1856 volatile int typ = mattype.type (); |
1944 | 1857 |
1947 octave_idx_type b_nc = b.cols (); | 1860 octave_idx_type b_nc = b.cols (); |
1948 rcon = 1.; | 1861 rcon = 1.; |
1949 info = 0; | 1862 info = 0; |
1950 | 1863 |
1951 if (typ == MatrixType::Permuted_Upper) | 1864 if (typ == MatrixType::Permuted_Upper) |
1952 { | 1865 (*current_liboctave_error_handler) |
1953 (*current_liboctave_error_handler) | 1866 ("permuted triangular matrix not implemented"); |
1954 ("permuted triangular matrix not implemented"); | |
1955 } | |
1956 else | 1867 else |
1957 { | 1868 { |
1958 const FloatComplex *tmp_data = fortran_vec (); | 1869 const FloatComplex *tmp_data = fortran_vec (); |
1959 | 1870 |
1960 retval = b; | 1871 retval = b; |
2029 octave_idx_type nc = cols (); | 1940 octave_idx_type nc = cols (); |
2030 | 1941 |
2031 if (nr != b.rows ()) | 1942 if (nr != b.rows ()) |
2032 (*current_liboctave_error_handler) | 1943 (*current_liboctave_error_handler) |
2033 ("matrix dimension mismatch solution of linear equations"); | 1944 ("matrix dimension mismatch solution of linear equations"); |
2034 else if (nr == 0 || nc == 0 || b.cols () == 0) | 1945 |
1946 if (nr == 0 || nc == 0 || b.cols () == 0) | |
2035 retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); | 1947 retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); |
2036 else | 1948 else |
2037 { | 1949 { |
2038 volatile int typ = mattype.type (); | 1950 volatile int typ = mattype.type (); |
2039 | 1951 |
2042 octave_idx_type b_nc = b.cols (); | 1954 octave_idx_type b_nc = b.cols (); |
2043 rcon = 1.; | 1955 rcon = 1.; |
2044 info = 0; | 1956 info = 0; |
2045 | 1957 |
2046 if (typ == MatrixType::Permuted_Lower) | 1958 if (typ == MatrixType::Permuted_Lower) |
2047 { | 1959 (*current_liboctave_error_handler) |
2048 (*current_liboctave_error_handler) | 1960 ("permuted triangular matrix not implemented"); |
2049 ("permuted triangular matrix not implemented"); | |
2050 } | |
2051 else | 1961 else |
2052 { | 1962 { |
2053 const FloatComplex *tmp_data = fortran_vec (); | 1963 const FloatComplex *tmp_data = fortran_vec (); |
2054 | 1964 |
2055 retval = b; | 1965 retval = b; |
2125 | 2035 |
2126 | 2036 |
2127 if (nr != nc || nr != b.rows ()) | 2037 if (nr != nc || nr != b.rows ()) |
2128 (*current_liboctave_error_handler) | 2038 (*current_liboctave_error_handler) |
2129 ("matrix dimension mismatch solution of linear equations"); | 2039 ("matrix dimension mismatch solution of linear equations"); |
2130 else if (nr == 0 || b.cols () == 0) | 2040 |
2041 if (nr == 0 || b.cols () == 0) | |
2131 retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); | 2042 retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); |
2132 else | 2043 else |
2133 { | 2044 { |
2134 volatile int typ = mattype.type (); | 2045 volatile int typ = mattype.type (); |
2135 | 2046 |
2375 retval = hermitian ().solve (mattype, b, info, rcon, sing_handler, | 2286 retval = hermitian ().solve (mattype, b, info, rcon, sing_handler, |
2376 singular_fallback); | 2287 singular_fallback); |
2377 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) | 2288 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) |
2378 retval = fsolve (mattype, b, info, rcon, sing_handler, true); | 2289 retval = fsolve (mattype, b, info, rcon, sing_handler, true); |
2379 else if (typ != MatrixType::Rectangular) | 2290 else if (typ != MatrixType::Rectangular) |
2380 { | 2291 (*current_liboctave_error_handler) ("unknown matrix type"); |
2381 (*current_liboctave_error_handler) ("unknown matrix type"); | |
2382 return FloatComplexMatrix (); | |
2383 } | |
2384 | 2292 |
2385 // Rectangular or one of the above solvers flags a singular matrix | 2293 // Rectangular or one of the above solvers flags a singular matrix |
2386 if (singular_fallback && mattype.type () == MatrixType::Rectangular) | 2294 if (singular_fallback && mattype.type () == MatrixType::Rectangular) |
2387 { | 2295 { |
2388 octave_idx_type rank; | 2296 octave_idx_type rank; |
2663 octave_idx_type n = cols (); | 2571 octave_idx_type n = cols (); |
2664 | 2572 |
2665 if (m != b.rows ()) | 2573 if (m != b.rows ()) |
2666 (*current_liboctave_error_handler) | 2574 (*current_liboctave_error_handler) |
2667 ("matrix dimension mismatch solution of linear equations"); | 2575 ("matrix dimension mismatch solution of linear equations"); |
2668 else if (m== 0 || n == 0 || b.cols () == 0) | 2576 |
2577 if (m== 0 || n == 0 || b.cols () == 0) | |
2669 retval = FloatComplexMatrix (n, b.cols (), FloatComplex (0.0, 0.0)); | 2578 retval = FloatComplexMatrix (n, b.cols (), FloatComplex (0.0, 0.0)); |
2670 else | 2579 else |
2671 { | 2580 { |
2672 volatile octave_idx_type minmn = (m < n ? m : n); | 2581 volatile octave_idx_type minmn = (m < n ? m : n); |
2673 octave_idx_type maxmn = m > n ? m : n; | 2582 octave_idx_type maxmn = m > n ? m : n; |
2863 octave_idx_type n = cols (); | 2772 octave_idx_type n = cols (); |
2864 | 2773 |
2865 if (m != b.numel ()) | 2774 if (m != b.numel ()) |
2866 (*current_liboctave_error_handler) | 2775 (*current_liboctave_error_handler) |
2867 ("matrix dimension mismatch solution of linear equations"); | 2776 ("matrix dimension mismatch solution of linear equations"); |
2868 else if (m == 0 || n == 0 || b.cols () == 0) | 2777 |
2778 if (m == 0 || n == 0 || b.cols () == 0) | |
2869 retval = FloatComplexColumnVector (n, FloatComplex (0.0, 0.0)); | 2779 retval = FloatComplexColumnVector (n, FloatComplex (0.0, 0.0)); |
2870 else | 2780 else |
2871 { | 2781 { |
2872 volatile octave_idx_type minmn = (m < n ? m : n); | 2782 volatile octave_idx_type minmn = (m < n ? m : n); |
2873 octave_idx_type maxmn = m > n ? m : n; | 2783 octave_idx_type maxmn = m > n ? m : n; |
3177 octave_idx_type nc = cols (); | 3087 octave_idx_type nc = cols (); |
3178 | 3088 |
3179 if (nr == 1 || nc == 1) | 3089 if (nr == 1 || nc == 1) |
3180 retval = FloatComplexDiagMatrix (*this, m, n); | 3090 retval = FloatComplexDiagMatrix (*this, m, n); |
3181 else | 3091 else |
3182 (*current_liboctave_error_handler) | 3092 (*current_liboctave_error_handler) ("diag: expecting vector argument"); |
3183 ("diag: expecting vector argument"); | |
3184 | 3093 |
3185 return retval; | 3094 return retval; |
3186 } | 3095 } |
3187 | 3096 |
3188 bool | 3097 bool |
3860 { | 3769 { |
3861 octave_idx_type nr = a.rows (); | 3770 octave_idx_type nr = a.rows (); |
3862 octave_idx_type nc = a.columns (); | 3771 octave_idx_type nc = a.columns (); |
3863 | 3772 |
3864 if (nr != b.rows () || nc != b.columns ()) | 3773 if (nr != b.rows () || nc != b.columns ()) |
3865 { | 3774 (*current_liboctave_error_handler) |
3866 (*current_liboctave_error_handler) | 3775 ("two-arg min requires same size arguments"); |
3867 ("two-arg min requires same size arguments"); | |
3868 return FloatComplexMatrix (); | |
3869 } | |
3870 | 3776 |
3871 EMPTY_RETURN_CHECK (FloatComplexMatrix); | 3777 EMPTY_RETURN_CHECK (FloatComplexMatrix); |
3872 | 3778 |
3873 FloatComplexMatrix result (nr, nc); | 3779 FloatComplexMatrix result (nr, nc); |
3874 | 3780 |
3948 { | 3854 { |
3949 octave_idx_type nr = a.rows (); | 3855 octave_idx_type nr = a.rows (); |
3950 octave_idx_type nc = a.columns (); | 3856 octave_idx_type nc = a.columns (); |
3951 | 3857 |
3952 if (nr != b.rows () || nc != b.columns ()) | 3858 if (nr != b.rows () || nc != b.columns ()) |
3953 { | 3859 (*current_liboctave_error_handler) |
3954 (*current_liboctave_error_handler) | 3860 ("two-arg max requires same size arguments"); |
3955 ("two-arg max requires same size arguments"); | |
3956 return FloatComplexMatrix (); | |
3957 } | |
3958 | 3861 |
3959 EMPTY_RETURN_CHECK (FloatComplexMatrix); | 3862 EMPTY_RETURN_CHECK (FloatComplexMatrix); |
3960 | 3863 |
3961 FloatComplexMatrix result (nr, nc); | 3864 FloatComplexMatrix result (nr, nc); |
3962 | 3865 |