comparison liboctave/CNDArray.cc @ 10143:f3c34b518422

simplify pairwise min/max implementations
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 20 Jan 2010 10:58:55 +0100
parents 829e69ec3110
children 4c0cdbe0acca
comparison
equal deleted inserted replaced
10142:829e69ec3110 10143:f3c34b518422
912 done: 912 done:
913 913
914 return is; 914 return is;
915 } 915 }
916 916
917 // FIXME -- it would be nice to share code among the min/max 917 ComplexNDArray
918 // functions below. 918 min (const Complex& s, const ComplexNDArray& m)
919 919 {
920 #define EMPTY_RETURN_CHECK(T) \ 920 return do_sm_binary_op<ComplexNDArray> (s, m, mx_inline_xmin);
921 if (nel == 0) \ 921 }
922 return T (dv); 922
923 923 ComplexNDArray
924 ComplexNDArray 924 min (const ComplexNDArray& m, const Complex& s)
925 min (const Complex& c, const ComplexNDArray& m) 925 {
926 { 926 return do_ms_binary_op<ComplexNDArray> (m, s, mx_inline_xmin);
927 dim_vector dv = m.dims ();
928 int nel = dv.numel ();
929
930 EMPTY_RETURN_CHECK (ComplexNDArray);
931
932 ComplexNDArray result (dv);
933
934 for (int i = 0; i < nel; i++)
935 {
936 octave_quit ();
937 result (i) = xmin (c, m (i));
938 }
939
940 return result;
941 }
942
943 ComplexNDArray
944 min (const ComplexNDArray& m, const Complex& c)
945 {
946 dim_vector dv = m.dims ();
947 int nel = dv.numel ();
948
949 EMPTY_RETURN_CHECK (ComplexNDArray);
950
951 ComplexNDArray result (dv);
952
953 for (int i = 0; i < nel; i++)
954 {
955 octave_quit ();
956 result (i) = xmin (c, m (i));
957 }
958
959 return result;
960 } 927 }
961 928
962 ComplexNDArray 929 ComplexNDArray
963 min (const ComplexNDArray& a, const ComplexNDArray& b) 930 min (const ComplexNDArray& a, const ComplexNDArray& b)
964 { 931 {
965 dim_vector dv = a.dims (); 932 return do_mm_binary_op<ComplexNDArray> (a, b, mx_inline_xmin, "min");
966 int nel = dv.numel (); 933 }
967 934
968 if (dv != b.dims ()) 935 ComplexNDArray
969 { 936 max (const Complex& s, const ComplexNDArray& m)
970 (*current_liboctave_error_handler) 937 {
971 ("two-arg min expecting args of same size"); 938 return do_sm_binary_op<ComplexNDArray> (s, m, mx_inline_xmax);
972 return ComplexNDArray (); 939 }
973 } 940
974 941 ComplexNDArray
975 EMPTY_RETURN_CHECK (ComplexNDArray); 942 max (const ComplexNDArray& m, const Complex& s)
976 943 {
977 ComplexNDArray result (dv); 944 return do_ms_binary_op<ComplexNDArray> (m, s, mx_inline_xmax);
978
979 for (int i = 0; i < nel; i++)
980 {
981 octave_quit ();
982 result (i) = xmin (a (i), b (i));
983 }
984
985 return result;
986 }
987
988 ComplexNDArray
989 max (const Complex& c, const ComplexNDArray& m)
990 {
991 dim_vector dv = m.dims ();
992 int nel = dv.numel ();
993
994 EMPTY_RETURN_CHECK (ComplexNDArray);
995
996 ComplexNDArray result (dv);
997
998 for (int i = 0; i < nel; i++)
999 {
1000 octave_quit ();
1001 result (i) = xmax (c, m (i));
1002 }
1003
1004 return result;
1005 }
1006
1007 ComplexNDArray
1008 max (const ComplexNDArray& m, const Complex& c)
1009 {
1010 dim_vector dv = m.dims ();
1011 int nel = dv.numel ();
1012
1013 EMPTY_RETURN_CHECK (ComplexNDArray);
1014
1015 ComplexNDArray result (dv);
1016
1017 for (int i = 0; i < nel; i++)
1018 {
1019 octave_quit ();
1020 result (i) = xmax (c, m (i));
1021 }
1022
1023 return result;
1024 } 945 }
1025 946
1026 ComplexNDArray 947 ComplexNDArray
1027 max (const ComplexNDArray& a, const ComplexNDArray& b) 948 max (const ComplexNDArray& a, const ComplexNDArray& b)
1028 { 949 {
1029 dim_vector dv = a.dims (); 950 return do_mm_binary_op<ComplexNDArray> (a, b, mx_inline_xmax, "max");
1030 int nel = dv.numel ();
1031
1032 if (dv != b.dims ())
1033 {
1034 (*current_liboctave_error_handler)
1035 ("two-arg max expecting args of same size");
1036 return ComplexNDArray ();
1037 }
1038
1039 EMPTY_RETURN_CHECK (ComplexNDArray);
1040
1041 ComplexNDArray result (dv);
1042
1043 for (int i = 0; i < nel; i++)
1044 {
1045 octave_quit ();
1046 result (i) = xmax (a (i), b (i));
1047 }
1048
1049 return result;
1050 } 951 }
1051 952
1052 NDS_CMP_OPS (ComplexNDArray, Complex) 953 NDS_CMP_OPS (ComplexNDArray, Complex)
1053 NDS_BOOL_OPS (ComplexNDArray, Complex) 954 NDS_BOOL_OPS (ComplexNDArray, Complex)
1054 955