comparison liboctave/CMatrix.cc @ 3504:5eef8a2294bd

[project @ 2000-02-01 10:06:51 by jwe]
author jwe
date Tue, 01 Feb 2000 10:07:26 +0000
parents d14c483b3c12
children 8d641545e006
comparison
equal deleted inserted replaced
3503:d14c483b3c12 3504:5eef8a2294bd
2549 for (int i = 0; i < ndiag; i++) 2549 for (int i = 0; i < ndiag; i++)
2550 d.elem (i) = elem (i, i); 2550 d.elem (i) = elem (i, i);
2551 } 2551 }
2552 } 2552 }
2553 else 2553 else
2554 cerr << "diag: requested diagonal out of range\n"; 2554 std::cerr << "diag: requested diagonal out of range\n";
2555 2555
2556 return d; 2556 return d;
2557 } 2557 }
2558 2558
2559 bool 2559 bool
2614 result.resize (nr); 2614 result.resize (nr);
2615 index.resize (nr); 2615 index.resize (nr);
2616 2616
2617 for (int i = 0; i < nr; i++) 2617 for (int i = 0; i < nr; i++)
2618 { 2618 {
2619 int idx = 0; 2619 int idx_j = 0;
2620 2620
2621 Complex tmp_min = elem (i, idx); 2621 Complex tmp_min = elem (i, idx_j);
2622 2622
2623 bool real_only = row_is_real_only (i); 2623 bool real_only = row_is_real_only (i);
2624 2624
2625 double abs_min = real_only ? real (tmp_min) : abs (tmp_min); 2625 double abs_min = real_only ? real (tmp_min) : abs (tmp_min);
2626 2626
2627 if (xisnan (tmp_min)) 2627 if (xisnan (tmp_min))
2628 idx = -1; 2628 idx_j = -1;
2629 else 2629 else
2630 { 2630 {
2631 for (int j = 1; j < nc; j++) 2631 for (int j = 1; j < nc; j++)
2632 { 2632 {
2633 Complex tmp = elem (i, j); 2633 Complex tmp = elem (i, j);
2634 2634
2635 double abs_tmp = real_only ? real (tmp) : abs (tmp); 2635 double abs_tmp = real_only ? real (tmp) : abs (tmp);
2636 2636
2637 if (xisnan (tmp)) 2637 if (xisnan (tmp))
2638 { 2638 {
2639 idx = -1; 2639 idx_j = -1;
2640 break; 2640 break;
2641 } 2641 }
2642 else if (abs_tmp < abs_min) 2642 else if (abs_tmp < abs_min)
2643 { 2643 {
2644 idx = j; 2644 idx_j = j;
2645 tmp_min = tmp; 2645 tmp_min = tmp;
2646 abs_min = abs_tmp; 2646 abs_min = abs_tmp;
2647 } 2647 }
2648 } 2648 }
2649 2649
2650 result.elem (i) = (idx < 0) ? Complex_NaN_result : tmp_min; 2650 result.elem (i) = (idx_j < 0) ? Complex_NaN_result : tmp_min;
2651 index.elem (i) = idx; 2651 index.elem (i) = idx_j;
2652 } 2652 }
2653 } 2653 }
2654 } 2654 }
2655 2655
2656 return result; 2656 return result;
2676 result.resize (nr); 2676 result.resize (nr);
2677 index.resize (nr); 2677 index.resize (nr);
2678 2678
2679 for (int i = 0; i < nr; i++) 2679 for (int i = 0; i < nr; i++)
2680 { 2680 {
2681 int idx = 0; 2681 int idx_j = 0;
2682 2682
2683 Complex tmp_max = elem (i, idx); 2683 Complex tmp_max = elem (i, idx_j);
2684 2684
2685 bool real_only = row_is_real_only (i); 2685 bool real_only = row_is_real_only (i);
2686 2686
2687 double abs_max = real_only ? real (tmp_max) : abs (tmp_max); 2687 double abs_max = real_only ? real (tmp_max) : abs (tmp_max);
2688 2688
2689 if (xisnan (tmp_max)) 2689 if (xisnan (tmp_max))
2690 idx = -1; 2690 idx_j = -1;
2691 else 2691 else
2692 { 2692 {
2693 for (int j = 1; j < nc; j++) 2693 for (int j = 1; j < nc; j++)
2694 { 2694 {
2695 Complex tmp = elem (i, j); 2695 Complex tmp = elem (i, j);
2696 2696
2697 double abs_tmp = real_only ? real (tmp) : abs (tmp); 2697 double abs_tmp = real_only ? real (tmp) : abs (tmp);
2698 2698
2699 if (xisnan (tmp)) 2699 if (xisnan (tmp))
2700 { 2700 {
2701 idx = -1; 2701 idx_j = -1;
2702 break; 2702 break;
2703 } 2703 }
2704 else if (abs_tmp > abs_max) 2704 else if (abs_tmp > abs_max)
2705 { 2705 {
2706 idx = j; 2706 idx_j = j;
2707 tmp_max = tmp; 2707 tmp_max = tmp;
2708 abs_max = abs_tmp; 2708 abs_max = abs_tmp;
2709 } 2709 }
2710 } 2710 }
2711 2711
2712 result.elem (i) = (idx < 0) ? Complex_NaN_result : tmp_max; 2712 result.elem (i) = (idx_j < 0) ? Complex_NaN_result : tmp_max;
2713 index.elem (i) = idx; 2713 index.elem (i) = idx_j;
2714 } 2714 }
2715 } 2715 }
2716 } 2716 }
2717 2717
2718 return result; 2718 return result;
2738 result.resize (nc); 2738 result.resize (nc);
2739 index.resize (nc); 2739 index.resize (nc);
2740 2740
2741 for (int j = 0; j < nc; j++) 2741 for (int j = 0; j < nc; j++)
2742 { 2742 {
2743 int idx = 0; 2743 int idx_i = 0;
2744 2744
2745 Complex tmp_min = elem (idx, j); 2745 Complex tmp_min = elem (idx_i, j);
2746 2746
2747 bool real_only = column_is_real_only (j); 2747 bool real_only = column_is_real_only (j);
2748 2748
2749 double abs_min = real_only ? real (tmp_min) : abs (tmp_min); 2749 double abs_min = real_only ? real (tmp_min) : abs (tmp_min);
2750 2750
2751 if (xisnan (tmp_min)) 2751 if (xisnan (tmp_min))
2752 idx = -1; 2752 idx_i = -1;
2753 else 2753 else
2754 { 2754 {
2755 for (int i = 1; i < nr; i++) 2755 for (int i = 1; i < nr; i++)
2756 { 2756 {
2757 Complex tmp = elem (i, j); 2757 Complex tmp = elem (i, j);
2758 2758
2759 double abs_tmp = real_only ? real (tmp) : abs (tmp); 2759 double abs_tmp = real_only ? real (tmp) : abs (tmp);
2760 2760
2761 if (xisnan (tmp)) 2761 if (xisnan (tmp))
2762 { 2762 {
2763 idx = -1; 2763 idx_i = -1;
2764 break; 2764 break;
2765 } 2765 }
2766 else if (abs_tmp < abs_min) 2766 else if (abs_tmp < abs_min)
2767 { 2767 {
2768 idx = i; 2768 idx_i = i;
2769 tmp_min = tmp; 2769 tmp_min = tmp;
2770 abs_min = abs_tmp; 2770 abs_min = abs_tmp;
2771 } 2771 }
2772 } 2772 }
2773 2773
2774 result.elem (j) = (idx < 0) ? Complex_NaN_result : tmp_min; 2774 result.elem (j) = (idx_i < 0) ? Complex_NaN_result : tmp_min;
2775 index.elem (j) = idx; 2775 index.elem (j) = idx_i;
2776 } 2776 }
2777 } 2777 }
2778 } 2778 }
2779 2779
2780 return result; 2780 return result;
2800 result.resize (nc); 2800 result.resize (nc);
2801 index.resize (nc); 2801 index.resize (nc);
2802 2802
2803 for (int j = 0; j < nc; j++) 2803 for (int j = 0; j < nc; j++)
2804 { 2804 {
2805 int idx = 0; 2805 int idx_i = 0;
2806 2806
2807 Complex tmp_max = elem (idx, j); 2807 Complex tmp_max = elem (idx_i, j);
2808 2808
2809 bool real_only = column_is_real_only (j); 2809 bool real_only = column_is_real_only (j);
2810 2810
2811 double abs_max = real_only ? real (tmp_max) : abs (tmp_max); 2811 double abs_max = real_only ? real (tmp_max) : abs (tmp_max);
2812 2812
2813 if (xisnan (tmp_max)) 2813 if (xisnan (tmp_max))
2814 idx = -1; 2814 idx_i = -1;
2815 else 2815 else
2816 { 2816 {
2817 for (int i = 1; i < nr; i++) 2817 for (int i = 1; i < nr; i++)
2818 { 2818 {
2819 Complex tmp = elem (i, j); 2819 Complex tmp = elem (i, j);
2820 2820
2821 double abs_tmp = real_only ? real (tmp) : abs (tmp); 2821 double abs_tmp = real_only ? real (tmp) : abs (tmp);
2822 2822
2823 if (xisnan (tmp)) 2823 if (xisnan (tmp))
2824 { 2824 {
2825 idx = -1; 2825 idx_i = -1;
2826 break; 2826 break;
2827 } 2827 }
2828 else if (abs_tmp > abs_max) 2828 else if (abs_tmp > abs_max)
2829 { 2829 {
2830 idx = i; 2830 idx_i = i;
2831 tmp_max = tmp; 2831 tmp_max = tmp;
2832 abs_max = abs_tmp; 2832 abs_max = abs_tmp;
2833 } 2833 }
2834 } 2834 }
2835 2835
2836 result.elem (j) = (idx < 0) ? Complex_NaN_result : tmp_max; 2836 result.elem (j) = (idx_i < 0) ? Complex_NaN_result : tmp_max;
2837 index.elem (j) = idx; 2837 index.elem (j) = idx_i;
2838 } 2838 }
2839 } 2839 }
2840 } 2840 }
2841 2841
2842 return result; 2842 return result;
2843 } 2843 }
2844 2844
2845 // i/o 2845 // i/o
2846 2846
2847 ostream& 2847 std::ostream&
2848 operator << (ostream& os, const ComplexMatrix& a) 2848 operator << (std::ostream& os, const ComplexMatrix& a)
2849 { 2849 {
2850 // int field_width = os.precision () + 7; 2850 // int field_width = os.precision () + 7;
2851 for (int i = 0; i < a.rows (); i++) 2851 for (int i = 0; i < a.rows (); i++)
2852 { 2852 {
2853 for (int j = 0; j < a.cols (); j++) 2853 for (int j = 0; j < a.cols (); j++)
2855 os << "\n"; 2855 os << "\n";
2856 } 2856 }
2857 return os; 2857 return os;
2858 } 2858 }
2859 2859
2860 istream& 2860 std::istream&
2861 operator >> (istream& is, ComplexMatrix& a) 2861 operator >> (std::istream& is, ComplexMatrix& a)
2862 { 2862 {
2863 int nr = a.rows (); 2863 int nr = a.rows ();
2864 int nc = a.cols (); 2864 int nc = a.cols ();
2865 2865
2866 if (nr < 1 || nc < 1) 2866 if (nr < 1 || nc < 1)
2867 is.clear (ios::badbit); 2867 is.clear (std::ios::badbit);
2868 else 2868 else
2869 { 2869 {
2870 Complex tmp; 2870 Complex tmp;
2871 for (int i = 0; i < nr; i++) 2871 for (int i = 0; i < nr; i++)
2872 for (int j = 0; j < nc; j++) 2872 for (int j = 0; j < nc; j++)
3006 3006
3007 return retval; 3007 return retval;
3008 } 3008 }
3009 3009
3010 MS_CMP_OPS(ComplexMatrix, real, Complex, real) 3010 MS_CMP_OPS(ComplexMatrix, real, Complex, real)
3011 MS_BOOL_OPS(ComplexMatrix, Complex) 3011 MS_BOOL_OPS(ComplexMatrix, Complex, 0.0)
3012 3012
3013 SM_CMP_OPS(Complex, real, ComplexMatrix, real) 3013 SM_CMP_OPS(Complex, real, ComplexMatrix, real)
3014 SM_BOOL_OPS(Complex, ComplexMatrix) 3014 SM_BOOL_OPS(Complex, ComplexMatrix, 0.0)
3015 3015
3016 MM_CMP_OPS(ComplexMatrix, real, ComplexMatrix, real) 3016 MM_CMP_OPS(ComplexMatrix, real, ComplexMatrix, real)
3017 MM_BOOL_OPS(ComplexMatrix, ComplexMatrix) 3017 MM_BOOL_OPS(ComplexMatrix, ComplexMatrix, 0.0)
3018 3018
3019 /* 3019 /*
3020 ;;; Local Variables: *** 3020 ;;; Local Variables: ***
3021 ;;; mode: C++ *** 3021 ;;; mode: C++ ***
3022 ;;; End: *** 3022 ;;; End: ***