Mercurial > hg > octave-nkf
diff src/DLD-FUNCTIONS/minmax.cc @ 4309:a9560cebae6e
[project @ 2003-01-28 23:24:58 by jwe]
author | jwe |
---|---|
date | Tue, 28 Jan 2003 23:24:58 +0000 |
parents | 6b96ce9f5743 |
children | abdcb14e598d |
line wrap: on
line diff
--- 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; \