# HG changeset patch # User jwe # Date 1043796298 0 # Node ID a9560cebae6ebc8d6b239c5e4fa94cb5efe79bbc # Parent b738d1a02adb57d80ae9daf4aaca8732cd85f7ab [project @ 2003-01-28 23:24:58 by jwe] diff -r b738d1a02adb -r a9560cebae6e Makefile.in --- a/Makefile.in Fri Jan 24 19:37:12 2003 +0000 +++ b/Makefile.in Tue Jan 28 23:24:58 2003 +0000 @@ -44,7 +44,7 @@ @echo "* To compile Octave, you will need a recent versions of" @echo "* the following software:" @echo "*" - @echo "* g++ (2.95.x or a more recent version)" + @echo "* g++ (3.2.x or a more recent version)" @echo "*" @echo "* flex (2.5.4 or a more recent version) -- required if" @echo "* you need to recreate lex.cc from lex.l" diff -r b738d1a02adb -r a9560cebae6e liboctave/CMatrix.cc --- a/liboctave/CMatrix.cc Fri Jan 24 19:37:12 2003 +0000 +++ b/liboctave/CMatrix.cc Tue Jan 28 23:24:58 2003 +0000 @@ -2916,6 +2916,192 @@ return retval; } +// XXX FIXME XXX -- it would be nice to share code among the min/max +// functions below. + +#define EMPTY_RETURN_CHECK(T) \ + if (nr == 0 || nc == 0) \ + return T (nr, nc); + +ComplexMatrix +min (const Complex& c, const ComplexMatrix& m) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (ComplexMatrix); + + ComplexMatrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmin (c, m (i, j)); + } + + return result; +} + +ComplexMatrix +min (const ComplexMatrix& m, const Complex& c) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (ComplexMatrix); + + ComplexMatrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmin (m (i, j), c); + } + + return result; +} + +ComplexMatrix +min (const ComplexMatrix& a, const ComplexMatrix& b) +{ + int nr = a.rows (); + int nc = a.columns (); + + if (nr != b.rows () || nc != b.columns ()) + { + (*current_liboctave_error_handler) + ("two-arg min expecting args of same size"); + return ComplexMatrix (); + } + + EMPTY_RETURN_CHECK (ComplexMatrix); + + ComplexMatrix result (nr, nc); + + for (int j = 0; j < nc; j++) + { + int columns_are_real_only = 1; + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0) + { + columns_are_real_only = 0; + break; + } + } + + if (columns_are_real_only) + { + for (int i = 0; i < nr; i++) + result (i, j) = xmin (real (a (i, j)), real (b (i, j))); + } + else + { + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmin (a (i, j), b (i, j)); + } + } + } + + return result; +} + +ComplexMatrix +max (const Complex& c, const ComplexMatrix& m) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (ComplexMatrix); + + ComplexMatrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmax (c, m (i, j)); + } + + return result; +} + +ComplexMatrix +max (const ComplexMatrix& m, const Complex& c) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (ComplexMatrix); + + ComplexMatrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmax (m (i, j), c); + } + + return result; +} + +ComplexMatrix +max (const ComplexMatrix& a, const ComplexMatrix& b) +{ + int nr = a.rows (); + int nc = a.columns (); + + if (nr != b.rows () || nc != b.columns ()) + { + (*current_liboctave_error_handler) + ("two-arg max expecting args of same size"); + return ComplexMatrix (); + } + + EMPTY_RETURN_CHECK (ComplexMatrix); + + ComplexMatrix result (nr, nc); + + for (int j = 0; j < nc; j++) + { + int columns_are_real_only = 1; + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0) + { + columns_are_real_only = 0; + break; + } + } + + if (columns_are_real_only) + { + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmax (real (a (i, j)), real (b (i, j))); + } + } + else + { + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmax (a (i, j), b (i, j)); + } + } + } + + return result; +} + MS_CMP_OPS(ComplexMatrix, real, Complex, real) MS_BOOL_OPS(ComplexMatrix, Complex, 0.0) diff -r b738d1a02adb -r a9560cebae6e liboctave/CMatrix.h --- a/liboctave/CMatrix.h Fri Jan 24 19:37:12 2003 +0000 +++ b/liboctave/CMatrix.h Tue Jan 28 23:24:58 2003 +0000 @@ -289,6 +289,14 @@ extern ComplexMatrix operator * (const ComplexMatrix&, const Matrix&); extern ComplexMatrix operator * (const ComplexMatrix&, const ComplexMatrix&); +extern ComplexMatrix min (const Complex& c, const ComplexMatrix& m); +extern ComplexMatrix min (const ComplexMatrix& m, const Complex& c); +extern ComplexMatrix min (const ComplexMatrix& a, const ComplexMatrix& b); + +extern ComplexMatrix max (const Complex& c, const ComplexMatrix& m); +extern ComplexMatrix max (const ComplexMatrix& m, const Complex& c); +extern ComplexMatrix max (const ComplexMatrix& a, const ComplexMatrix& b); + MS_CMP_OP_DECLS (ComplexMatrix, Complex) MS_BOOL_OP_DECLS (ComplexMatrix, Complex) diff -r b738d1a02adb -r a9560cebae6e liboctave/ChangeLog --- a/liboctave/ChangeLog Fri Jan 24 19:37:12 2003 +0000 +++ b/liboctave/ChangeLog Tue Jan 28 23:24:58 2003 +0000 @@ -1,3 +1,9 @@ +2003-01-28 John W. Eaton + + * CMatrix.cc, dMatrix.cc: Move min and max functions here, from + src/DLD-FUNCTIONS/minmax.cc, and make them extern. + * CMatrix.h, dMatrix.h: Provide decls. + 2003-01-24 John W. Eaton * oct-rand.h, oct-rand.cc: New files. diff -r b738d1a02adb -r a9560cebae6e liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc Fri Jan 24 19:37:12 2003 +0000 +++ b/liboctave/dMatrix.cc Tue Jan 28 23:24:58 2003 +0000 @@ -2884,6 +2884,147 @@ return retval; } +// XXX FIXME XXX -- it would be nice to share code among the min/max +// functions below. + +#define EMPTY_RETURN_CHECK(T) \ + if (nr == 0 || nc == 0) \ + return T (nr, nc); + +Matrix +min (double d, const Matrix& m) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (Matrix); + + Matrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmin (d, m (i, j)); + } + + return result; +} + +Matrix +min (const Matrix& m, double d) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (Matrix); + + Matrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmin (m (i, j), d); + } + + return result; +} + +Matrix +min (const Matrix& a, const Matrix& b) +{ + int nr = a.rows (); + int nc = a.columns (); + + if (nr != b.rows () || nc != b.columns ()) + { + (*current_liboctave_error_handler) + ("two-arg min expecting args of same size"); + return Matrix (); + } + + EMPTY_RETURN_CHECK (Matrix); + + Matrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmin (a (i, j), b (i, j)); + } + + return result; +} + +Matrix +max (double d, const Matrix& m) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (Matrix); + + Matrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmax (d, m (i, j)); + } + + return result; +} + +Matrix +max (const Matrix& m, double d) +{ + int nr = m.rows (); + int nc = m.columns (); + + EMPTY_RETURN_CHECK (Matrix); + + Matrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmax (m (i, j), d); + } + + return result; +} + +Matrix +max (const Matrix& a, const Matrix& b) +{ + int nr = a.rows (); + int nc = a.columns (); + + if (nr != b.rows () || nc != b.columns ()) + { + (*current_liboctave_error_handler) + ("two-arg max expecting args of same size"); + return Matrix (); + } + + EMPTY_RETURN_CHECK (Matrix); + + Matrix result (nr, nc); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + OCTAVE_QUIT; + result (i, j) = xmax (a (i, j), b (i, j)); + } + + return result; +} + MS_CMP_OPS(Matrix, , double, ) MS_BOOL_OPS(Matrix, double, 0.0) diff -r b738d1a02adb -r a9560cebae6e liboctave/dMatrix.h --- a/liboctave/dMatrix.h Fri Jan 24 19:37:12 2003 +0000 +++ b/liboctave/dMatrix.h Tue Jan 28 23:24:58 2003 +0000 @@ -246,6 +246,14 @@ extern Matrix operator * (const Matrix& a, const Matrix& b); +extern Matrix min (double d, const Matrix& m); +extern Matrix min (const Matrix& m, double d); +extern Matrix min (const Matrix& a, const Matrix& b); + +extern Matrix max (double d, const Matrix& m); +extern Matrix max (const Matrix& m, double d); +extern Matrix max (const Matrix& a, const Matrix& b); + MS_CMP_OP_DECLS (Matrix, double) MS_BOOL_OP_DECLS (Matrix, double) diff -r b738d1a02adb -r a9560cebae6e scripts/general/int2str.m --- a/scripts/general/int2str.m Fri Jan 24 19:37:12 2003 +0000 +++ b/scripts/general/int2str.m Tue Jan 28 23:24:58 2003 +0000 @@ -76,7 +76,7 @@ else ## Could have anything. tfw = floor (log10 (abs (t))) + 1 + sep; - fw = max (tfw) + fw = max (tfw); if (any (t(tfw == fw) < 0)) fw++; endif diff -r b738d1a02adb -r a9560cebae6e src/ChangeLog --- a/src/ChangeLog Fri Jan 24 19:37:12 2003 +0000 +++ b/src/ChangeLog Tue Jan 28 23:24:58 2003 +0000 @@ -1,3 +1,8 @@ +2003-01-28 John W. Eaton + + * DLD-FUNCTIONS/minmax.cc: Move min and max functions from here to + liboctave/dMatrix.cc and liboctave/CMatrix.cc. + 2003-01-24 John W. Eaton * DLD-FUNCTIONS/rand.cc: Rewrite to use new octave_rand functions. diff -r b738d1a02adb -r a9560cebae6e src/DLD-FUNCTIONS/minmax.cc --- a/src/DLD-FUNCTIONS/minmax.cc Fri Jan 24 19:37:12 2003 +0000 +++ b/src/DLD-FUNCTIONS/minmax.cc Tue Jan 28 23:24:58 2003 +0000 @@ -28,6 +28,8 @@ #include "lo-ieee.h" #include "lo-mappers.h" +#include "dMatrix.h" +#include "CMatrix.h" #include "quit.h" #include "defun-dld.h" @@ -35,322 +37,6 @@ #include "gripes.h" #include "oct-obj.h" -// XXX FIXME XXX -- it would be nice to share code among the min/max -// functions below. - -#define EMPTY_RETURN_CHECK(T) \ - if (nr == 0 || nc == 0) \ - return T (nr, nc); - -static Matrix -min (double d, const Matrix& m) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (Matrix); - - Matrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmin (d, m (i, j)); - } - - return result; -} - -static Matrix -min (const Matrix& m, double d) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (Matrix); - - Matrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmin (m (i, j), d); - } - - return result; -} - -static ComplexMatrix -min (const Complex& c, const ComplexMatrix& m) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (ComplexMatrix); - - ComplexMatrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmin (c, m (i, j)); - } - - return result; -} - -static ComplexMatrix -min (const ComplexMatrix& m, const Complex& c) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (ComplexMatrix); - - ComplexMatrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmin (m (i, j), c); - } - - return result; -} - -static Matrix -min (const Matrix& a, const Matrix& b) -{ - int nr = a.rows (); - int nc = a.columns (); - - if (nr != b.rows () || nc != b.columns ()) - { - error ("two-arg min expecting args of same size"); - return Matrix (); - } - - EMPTY_RETURN_CHECK (Matrix); - - Matrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmin (a (i, j), b (i, j)); - } - - return result; -} - -static ComplexMatrix -min (const ComplexMatrix& a, const ComplexMatrix& b) -{ - int nr = a.rows (); - int nc = a.columns (); - - if (nr != b.rows () || nc != b.columns ()) - { - error ("two-arg min expecting args of same size"); - return ComplexMatrix (); - } - - EMPTY_RETURN_CHECK (ComplexMatrix); - - ComplexMatrix result (nr, nc); - - for (int j = 0; j < nc; j++) - { - int columns_are_real_only = 1; - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0) - { - columns_are_real_only = 0; - break; - } - } - - if (columns_are_real_only) - { - for (int i = 0; i < nr; i++) - result (i, j) = xmin (real (a (i, j)), real (b (i, j))); - } - else - { - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmin (a (i, j), b (i, j)); - } - } - } - - return result; -} - -static Matrix -max (double d, const Matrix& m) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (Matrix); - - Matrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmax (d, m (i, j)); - } - - return result; -} - -static Matrix -max (const Matrix& m, double d) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (Matrix); - - Matrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmax (m (i, j), d); - } - - return result; -} - -static ComplexMatrix -max (const Complex& c, const ComplexMatrix& m) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (ComplexMatrix); - - ComplexMatrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmax (c, m (i, j)); - } - - return result; -} - -static ComplexMatrix -max (const ComplexMatrix& m, const Complex& c) -{ - int nr = m.rows (); - int nc = m.columns (); - - EMPTY_RETURN_CHECK (ComplexMatrix); - - ComplexMatrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmax (m (i, j), c); - } - - return result; -} - -static Matrix -max (const Matrix& a, const Matrix& b) -{ - int nr = a.rows (); - int nc = a.columns (); - - if (nr != b.rows () || nc != b.columns ()) - { - error ("two-arg max expecting args of same size"); - return Matrix (); - } - - EMPTY_RETURN_CHECK (Matrix); - - Matrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmax (a (i, j), b (i, j)); - } - - return result; -} - -static ComplexMatrix -max (const ComplexMatrix& a, const ComplexMatrix& b) -{ - int nr = a.rows (); - int nc = a.columns (); - - if (nr != b.rows () || nc != b.columns ()) - { - error ("two-arg max expecting args of same size"); - return ComplexMatrix (); - } - - EMPTY_RETURN_CHECK (ComplexMatrix); - - ComplexMatrix result (nr, nc); - - for (int j = 0; j < nc; j++) - { - int columns_are_real_only = 1; - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0) - { - columns_are_real_only = 0; - break; - } - } - - if (columns_are_real_only) - { - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmax (real (a (i, j)), real (b (i, j))); - } - } - else - { - for (int i = 0; i < nr; i++) - { - OCTAVE_QUIT; - result (i, j) = xmax (a (i, j), b (i, j)); - } - } - } - - return result; -} - #define MINMAX_BODY(FCN) \ \ octave_value_list retval; \ diff -r b738d1a02adb -r a9560cebae6e test/octave.test/string/int2str-1.m --- a/test/octave.test/string/int2str-1.m Fri Jan 24 19:37:12 2003 +0000 +++ b/test/octave.test/string/int2str-1.m Tue Jan 28 23:24:58 2003 +0000 @@ -1,1 +1,1 @@ -strcmp (int2str (-123), " -123") && strcmp (int2str (1.2), " 1") +strcmp (int2str (-123), "-123") && strcmp (int2str (1.2), "1") diff -r b738d1a02adb -r a9560cebae6e test/octave.test/string/num2str-1.m --- a/test/octave.test/string/num2str-1.m Fri Jan 24 19:37:12 2003 +0000 +++ b/test/octave.test/string/num2str-1.m Tue Jan 28 23:24:58 2003 +0000 @@ -1,2 +1,1 @@ -(strcmp (num2str (123), " 123") - && strcmp (num2str (1.23), " 1.23")) +(strcmp (num2str (123), "123") && strcmp (num2str (1.23), "1.23"))