Mercurial > hg > octave-terminal
changeset 4309:a9560cebae6e
[project @ 2003-01-28 23:24:58 by jwe]
author | jwe |
---|---|
date | Tue, 28 Jan 2003 23:24:58 +0000 |
parents | b738d1a02adb |
children | da7226ca8b91 |
files | Makefile.in liboctave/CMatrix.cc liboctave/CMatrix.h liboctave/ChangeLog liboctave/dMatrix.cc liboctave/dMatrix.h scripts/general/int2str.m src/ChangeLog src/DLD-FUNCTIONS/minmax.cc test/octave.test/string/int2str-1.m test/octave.test/string/num2str-1.m |
diffstat | 11 files changed, 360 insertions(+), 321 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.in +++ b/Makefile.in @@ -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"
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -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)
--- a/liboctave/CMatrix.h +++ b/liboctave/CMatrix.h @@ -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)
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2003-01-28 John W. Eaton <jwe@bevo.che.wisc.edu> + + * 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 <jwe@bevo.che.wisc.edu> * oct-rand.h, oct-rand.cc: New files.
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -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)
--- a/liboctave/dMatrix.h +++ b/liboctave/dMatrix.h @@ -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)
--- a/scripts/general/int2str.m +++ b/scripts/general/int2str.m @@ -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
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-01-28 John W. Eaton <jwe@bevo.che.wisc.edu> + + * 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 <jwe@bevo.che.wisc.edu> * DLD-FUNCTIONS/rand.cc: Rewrite to use new octave_rand functions.
--- a/src/DLD-FUNCTIONS/minmax.cc +++ b/src/DLD-FUNCTIONS/minmax.cc @@ -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; \