Mercurial > hg > octave-nkf
comparison liboctave/CMatrix.cc @ 4309:a9560cebae6e
[project @ 2003-01-28 23:24:58 by jwe]
author | jwe |
---|---|
date | Tue, 28 Jan 2003 23:24:58 +0000 |
parents | 5719210fff4c |
children | 236c10efcde2 |
comparison
equal
deleted
inserted
replaced
4308:b738d1a02adb | 4309:a9560cebae6e |
---|---|
2914 } | 2914 } |
2915 | 2915 |
2916 return retval; | 2916 return retval; |
2917 } | 2917 } |
2918 | 2918 |
2919 // XXX FIXME XXX -- it would be nice to share code among the min/max | |
2920 // functions below. | |
2921 | |
2922 #define EMPTY_RETURN_CHECK(T) \ | |
2923 if (nr == 0 || nc == 0) \ | |
2924 return T (nr, nc); | |
2925 | |
2926 ComplexMatrix | |
2927 min (const Complex& c, const ComplexMatrix& m) | |
2928 { | |
2929 int nr = m.rows (); | |
2930 int nc = m.columns (); | |
2931 | |
2932 EMPTY_RETURN_CHECK (ComplexMatrix); | |
2933 | |
2934 ComplexMatrix result (nr, nc); | |
2935 | |
2936 for (int j = 0; j < nc; j++) | |
2937 for (int i = 0; i < nr; i++) | |
2938 { | |
2939 OCTAVE_QUIT; | |
2940 result (i, j) = xmin (c, m (i, j)); | |
2941 } | |
2942 | |
2943 return result; | |
2944 } | |
2945 | |
2946 ComplexMatrix | |
2947 min (const ComplexMatrix& m, const Complex& c) | |
2948 { | |
2949 int nr = m.rows (); | |
2950 int nc = m.columns (); | |
2951 | |
2952 EMPTY_RETURN_CHECK (ComplexMatrix); | |
2953 | |
2954 ComplexMatrix result (nr, nc); | |
2955 | |
2956 for (int j = 0; j < nc; j++) | |
2957 for (int i = 0; i < nr; i++) | |
2958 { | |
2959 OCTAVE_QUIT; | |
2960 result (i, j) = xmin (m (i, j), c); | |
2961 } | |
2962 | |
2963 return result; | |
2964 } | |
2965 | |
2966 ComplexMatrix | |
2967 min (const ComplexMatrix& a, const ComplexMatrix& b) | |
2968 { | |
2969 int nr = a.rows (); | |
2970 int nc = a.columns (); | |
2971 | |
2972 if (nr != b.rows () || nc != b.columns ()) | |
2973 { | |
2974 (*current_liboctave_error_handler) | |
2975 ("two-arg min expecting args of same size"); | |
2976 return ComplexMatrix (); | |
2977 } | |
2978 | |
2979 EMPTY_RETURN_CHECK (ComplexMatrix); | |
2980 | |
2981 ComplexMatrix result (nr, nc); | |
2982 | |
2983 for (int j = 0; j < nc; j++) | |
2984 { | |
2985 int columns_are_real_only = 1; | |
2986 for (int i = 0; i < nr; i++) | |
2987 { | |
2988 OCTAVE_QUIT; | |
2989 if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0) | |
2990 { | |
2991 columns_are_real_only = 0; | |
2992 break; | |
2993 } | |
2994 } | |
2995 | |
2996 if (columns_are_real_only) | |
2997 { | |
2998 for (int i = 0; i < nr; i++) | |
2999 result (i, j) = xmin (real (a (i, j)), real (b (i, j))); | |
3000 } | |
3001 else | |
3002 { | |
3003 for (int i = 0; i < nr; i++) | |
3004 { | |
3005 OCTAVE_QUIT; | |
3006 result (i, j) = xmin (a (i, j), b (i, j)); | |
3007 } | |
3008 } | |
3009 } | |
3010 | |
3011 return result; | |
3012 } | |
3013 | |
3014 ComplexMatrix | |
3015 max (const Complex& c, const ComplexMatrix& m) | |
3016 { | |
3017 int nr = m.rows (); | |
3018 int nc = m.columns (); | |
3019 | |
3020 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3021 | |
3022 ComplexMatrix result (nr, nc); | |
3023 | |
3024 for (int j = 0; j < nc; j++) | |
3025 for (int i = 0; i < nr; i++) | |
3026 { | |
3027 OCTAVE_QUIT; | |
3028 result (i, j) = xmax (c, m (i, j)); | |
3029 } | |
3030 | |
3031 return result; | |
3032 } | |
3033 | |
3034 ComplexMatrix | |
3035 max (const ComplexMatrix& m, const Complex& c) | |
3036 { | |
3037 int nr = m.rows (); | |
3038 int nc = m.columns (); | |
3039 | |
3040 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3041 | |
3042 ComplexMatrix result (nr, nc); | |
3043 | |
3044 for (int j = 0; j < nc; j++) | |
3045 for (int i = 0; i < nr; i++) | |
3046 { | |
3047 OCTAVE_QUIT; | |
3048 result (i, j) = xmax (m (i, j), c); | |
3049 } | |
3050 | |
3051 return result; | |
3052 } | |
3053 | |
3054 ComplexMatrix | |
3055 max (const ComplexMatrix& a, const ComplexMatrix& b) | |
3056 { | |
3057 int nr = a.rows (); | |
3058 int nc = a.columns (); | |
3059 | |
3060 if (nr != b.rows () || nc != b.columns ()) | |
3061 { | |
3062 (*current_liboctave_error_handler) | |
3063 ("two-arg max expecting args of same size"); | |
3064 return ComplexMatrix (); | |
3065 } | |
3066 | |
3067 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3068 | |
3069 ComplexMatrix result (nr, nc); | |
3070 | |
3071 for (int j = 0; j < nc; j++) | |
3072 { | |
3073 int columns_are_real_only = 1; | |
3074 for (int i = 0; i < nr; i++) | |
3075 { | |
3076 OCTAVE_QUIT; | |
3077 if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0) | |
3078 { | |
3079 columns_are_real_only = 0; | |
3080 break; | |
3081 } | |
3082 } | |
3083 | |
3084 if (columns_are_real_only) | |
3085 { | |
3086 for (int i = 0; i < nr; i++) | |
3087 { | |
3088 OCTAVE_QUIT; | |
3089 result (i, j) = xmax (real (a (i, j)), real (b (i, j))); | |
3090 } | |
3091 } | |
3092 else | |
3093 { | |
3094 for (int i = 0; i < nr; i++) | |
3095 { | |
3096 OCTAVE_QUIT; | |
3097 result (i, j) = xmax (a (i, j), b (i, j)); | |
3098 } | |
3099 } | |
3100 } | |
3101 | |
3102 return result; | |
3103 } | |
3104 | |
2919 MS_CMP_OPS(ComplexMatrix, real, Complex, real) | 3105 MS_CMP_OPS(ComplexMatrix, real, Complex, real) |
2920 MS_BOOL_OPS(ComplexMatrix, Complex, 0.0) | 3106 MS_BOOL_OPS(ComplexMatrix, Complex, 0.0) |
2921 | 3107 |
2922 SM_CMP_OPS(Complex, real, ComplexMatrix, real) | 3108 SM_CMP_OPS(Complex, real, ComplexMatrix, real) |
2923 SM_BOOL_OPS(Complex, ComplexMatrix, 0.0) | 3109 SM_BOOL_OPS(Complex, ComplexMatrix, 0.0) |