changeset 3248:68259f410026

[project @ 1999-07-13 03:34:54 by jwe]
author jwe
date Tue, 13 Jul 1999 03:40:17 +0000
parents 256f98d26275
children 60866c521b92
files liboctave/CMatrix.cc liboctave/CMatrix.h liboctave/ChangeLog liboctave/dMatrix.cc liboctave/dMatrix.h liboctave/lo-mappers.cc liboctave/lo-mappers.h liboctave/mx-defs.h src/DLD-FUNCTIONS/minmax.cc src/pr-output.cc src/sysdep.cc src/variables.cc
diffstat 12 files changed, 183 insertions(+), 169 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/CMatrix.cc	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/CMatrix.cc	Tue Jul 13 03:40:17 1999 +0000
@@ -1928,14 +1928,29 @@
 Matrix
 ComplexMatrix::map (d_c_Mapper f) const
 {
-  const Complex *d = data ();
-
-  Matrix retval (rows (), columns ());
-
-  double *r = retval.fortran_vec ();
-
-  for (int i = 0; i < length (); i++)
-    r[i] = f (d[i]);
+  int nr = rows ();
+  int nc = cols ();
+
+  Matrix retval (nr, nc);
+
+  for (int j = 0; j < nc; j++)
+    for (int i = 0; i < nr; i++)
+      retval(i,j) = f (elem(i,j));
+
+  return retval;
+}
+
+boolMatrix
+ComplexMatrix::map (b_c_Mapper f) const
+{
+  int nr = rows ();
+  int nc = cols ();
+
+  boolMatrix retval (nr, nc);
+
+  for (int j = 0; j < nc; j++)
+    for (int i = 0; i < nr; i++)
+      retval(i,j) = f (elem(i,j));
 
   return retval;
 }
--- a/liboctave/CMatrix.h	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/CMatrix.h	Tue Jul 13 03:40:17 1999 +0000
@@ -207,6 +207,7 @@
 
   ComplexMatrix map (c_c_Mapper f) const;
   Matrix map (d_c_Mapper f) const;
+  boolMatrix map (b_c_Mapper f) const;
 
   ComplexMatrix& apply (c_c_Mapper f);
 
--- a/liboctave/ChangeLog	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/ChangeLog	Tue Jul 13 03:40:17 1999 +0000
@@ -1,3 +1,12 @@
+Mon Jul 12 22:34:34 1999  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* mx-defs.h (b_d_Mapper, b_c_Mapper): New typedefs.
+	* dMatrix.cc (Matrix::map (b_d_Mapper)): New function.
+	* CMatrix.cc (ComplexMatrix::map (b_c_Mapper)): New function.
+	* lo-mappers.cc (xisinf, xisnan, xfinite): Return bool, not double.
+
+	* lo-mappers.cc (xmin, xmax): New functions to correctly handle NaNs.
+
 Mon May 10 07:45:11 1999  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* MArray-defs.h (DO_VV_OP2): Fix macro definition to use arg.
--- a/liboctave/dMatrix.cc	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/dMatrix.cc	Tue Jul 13 03:40:17 1999 +0000
@@ -1556,6 +1556,21 @@
   return b.apply (f);
 }
 
+boolMatrix
+Matrix::map (b_d_Mapper f) const
+{
+  int nr = rows ();
+  int nc = cols ();
+
+  boolMatrix retval (nr, nc);
+
+  for (int j = 0; j < nc; j++)
+    for (int i = 0; i < nr; i++)
+      retval(i,j) = f (elem(i,j));
+
+  return retval;
+}
+
 Matrix&
 Matrix::apply (d_d_Mapper f)
 {
--- a/liboctave/dMatrix.h	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/dMatrix.h	Tue Jul 13 03:40:17 1999 +0000
@@ -180,6 +180,7 @@
   // other operations
 
   Matrix map (d_d_Mapper f) const;
+  boolMatrix map (b_d_Mapper f) const;
 
   Matrix& apply (d_d_Mapper f);
 
--- a/liboctave/lo-mappers.cc	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/lo-mappers.cc	Tue Jul 13 03:40:17 1999 +0000
@@ -49,7 +49,7 @@
 #define M_PI 3.14159265358979323846
 #endif
 
-// Double -> double mappers.
+// double -> double mappers.
 
 double
 arg (double x)
@@ -136,17 +136,19 @@
 #endif
 }
 
-double
+// double -> bool mappers.
+
+bool
 xisnan (double x)
 {
 #if defined (HAVE_ISNAN)
   return isnan (x) != 0;
 #else
-  return 0;
+  return false;
 #endif
 }
 
-double
+bool
 xfinite (double x)
 {
 #if defined (HAVE_FINITE)
@@ -154,11 +156,11 @@
 #elif defined (HAVE_ISINF) && defined (HAVE_ISNAN)
   return (! isinf (x) && ! isnan (x));
 #else
-  return 1;
+  return true;
 #endif
 }
 
-double
+bool
 xisinf (double x)
 {
 #if defined (HAVE_ISINF)
@@ -166,35 +168,25 @@
 #elif defined (HAVE_FINITE) && defined (HAVE_ISNAN)
   return (! (finite (x) || isnan (x)));
 #else
-  return 0;
+  return false;
 #endif
 }
 
-// Complex -> double mappers.
+// (double, double) -> double mappers.
 
 double
-xisnan (const Complex& x)
+xmin (double x, double y)
 {
-#if defined (HAVE_ISNAN)
-  return (isnan (real (x)) || isnan (imag (x)));
-#else
-  return 0;
-#endif
+  return x < y ? x : (xisnan (x) ? x : y);
 }
 
 double
-xfinite (const Complex& x)
+xmax (double x, double y)
 {
-  return (xfinite (real (x)) && xfinite (imag (x)));
+  return x > y ? x : (xisnan (x) ? x : y);
 }
 
-double
-xisinf (const Complex& x)
-{
-  return (xisinf (real (x)) || xisinf (imag (x)));
-}
-
-// Complex -> complex mappers.
+// complex -> complex mappers.
 
 Complex
 acos (const Complex& x)
@@ -286,6 +278,44 @@
   return sinh (x) / cosh (x);
 }
 
+// complex -> bool mappers.
+
+bool
+xisnan (const Complex& x)
+{
+#if defined (HAVE_ISNAN)
+  return (isnan (real (x)) || isnan (imag (x)));
+#else
+  return false;
+#endif
+}
+
+bool
+xfinite (const Complex& x)
+{
+  return (xfinite (real (x)) && xfinite (imag (x)));
+}
+
+bool
+xisinf (const Complex& x)
+{
+  return (xisinf (real (x)) || xisinf (imag (x)));
+}
+
+// (complex, complex) -> complex mappers.
+
+Complex
+xmin (const Complex& x, const Complex& y)
+{
+  return abs (x) < abs (y) ? x : (xisnan (x) ? x : y);
+}
+
+Complex
+xmax (const Complex& x, const Complex& y)
+{
+  return abs (x) > abs (y) ? x : (xisnan (x) ? x : y);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/lo-mappers.h	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/lo-mappers.h	Tue Jul 13 03:40:17 1999 +0000
@@ -34,13 +34,13 @@
 extern double signum (double x);
 extern double xerf (double x);
 extern double xerfc (double x);
-extern double xisnan (double x);
-extern double xfinite (double x);
-extern double xisinf (double x);
 
-extern double xisnan (const Complex& x);
-extern double xfinite (const Complex& x);
-extern double xisinf (const Complex& x);
+extern bool xisnan (double x);
+extern bool xfinite (double x);
+extern bool xisinf (double x);
+
+extern double xmin (double x, double y);
+extern double xmax (double x, double y);
 
 extern Complex acos (const Complex& x);
 extern Complex acosh (const Complex& x);
@@ -57,6 +57,13 @@
 extern Complex tan (const Complex& x);
 extern Complex tanh (const Complex& x);
 
+extern bool xisnan (const Complex& x);
+extern bool xfinite (const Complex& x);
+extern bool xisinf (const Complex& x);
+
+extern Complex xmin (const Complex& x, const Complex& y);
+extern Complex xmax (const Complex& x, const Complex& y);
+
 #endif
 
 /*
--- a/liboctave/mx-defs.h	Sat Jun 19 06:51:15 1999 +0000
+++ b/liboctave/mx-defs.h	Tue Jul 13 03:40:17 1999 +0000
@@ -78,6 +78,9 @@
 #ifndef MAPPER_FCN_TYPEDEFS
 #define MAPPER_FCN_TYPEDEFS 1
 
+typedef bool (*b_d_Mapper)(double);
+typedef bool (*b_c_Mapper)(const Complex&);
+
 typedef double (*d_d_Mapper)(double);
 typedef double (*d_c_Mapper)(const Complex&);
 typedef Complex (*c_c_Mapper)(const Complex&);
--- a/src/DLD-FUNCTIONS/minmax.cc	Sat Jun 19 06:51:15 1999 +0000
+++ b/src/DLD-FUNCTIONS/minmax.cc	Tue Jul 13 03:40:17 1999 +0000
@@ -27,20 +27,13 @@
 #include <cmath>
 
 #include "lo-ieee.h"
+#include "lo-mappers.h"
 
 #include "defun-dld.h"
 #include "error.h"
 #include "gripes.h"
 #include "oct-obj.h"
 
-#ifndef MAX
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
 // XXX FIXME XXX -- it would be nice to share code among the min/max
 // functions below.
 
@@ -54,10 +47,7 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double m_elem = m (i, j);
-	result (i, j) = MIN (d, m_elem);
-      }
+      result (i, j) = xmin (d, m (i, j));
 
   return result;
 }
@@ -72,10 +62,7 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double m_elem = m (i, j);
-	result (i, j) = MIN (m_elem, d);
-      }
+      result (i, j) = xmin (m (i, j), d);
 
   return result;
 }
@@ -88,19 +75,9 @@
 
   ComplexMatrix result (nr, nc);
 
-  double abs_c = abs (c);
-
   for (int j = 0; j < nc; j++)
-    {
-      for (int i = 0; i < nr; i++)
-	{
-	  double abs_m_elem = abs (m (i, j));
-	  if (abs_c < abs_m_elem)
-	    result (i, j) = c;
-	  else
-	    result (i, j) = m (i, j);
-	}
-    }
+    for (int i = 0; i < nr; i++)
+      result (i, j) = xmin (c, m (i, j));
 
   return result;
 }
@@ -113,17 +90,9 @@
 
   ComplexMatrix result (nr, nc);
 
-  double abs_c = abs (c);
-
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double abs_m_elem = abs (m (i, j));
-	if (abs_m_elem < abs_c)
-	  result (i, j) = m (i, j);
-	else
-	  result (i, j) = c;
-      }
+      result (i, j) = xmin (m (i, j), c);
 
   return result;
 }
@@ -143,11 +112,7 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double a_elem = a (i, j);
-	double b_elem = b (i, j);
-	result (i, j) = MIN (a_elem, b_elem);
-      }
+      result (i, j) = xmin (a (i, j), b (i, j));
 
   return result;
 }
@@ -178,26 +143,12 @@
       if (columns_are_real_only)
 	{
 	  for (int i = 0; i < nr; i++)
-	    {
-	      double a_elem = real (a (i, j));
-	      double b_elem = real (b (i, j));
-	      if (a_elem < b_elem)
-		result (i, j) = a_elem;
-	      else
-		result (i, j) = b_elem;
-	    }
+	    result (i, j) = xmin (real (a (i, j)), real (b (i, j)));
 	}
       else
 	{
 	  for (int i = 0; i < nr; i++)
-	    {
-	      double abs_a_elem = abs (a (i, j));
-	      double abs_b_elem = abs (b (i, j));
-	      if (abs_a_elem < abs_b_elem)
-		result (i, j) = a (i, j);
-	      else
-		result (i, j) = b (i, j);
-	    }
+	    result (i, j) = xmin (a (i, j), b (i, j));
 	}
     }
 
@@ -214,10 +165,7 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double m_elem = m (i, j);
-	result (i, j) = MAX (d, m_elem);
-      }
+      result (i, j) = xmax (d, m (i, j));
 
   return result;
 }
@@ -232,10 +180,7 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double m_elem = m (i, j);
-	result (i, j) = MAX (m_elem, d);
-      }
+      result (i, j) = xmax (m (i, j), d);
 
   return result;
 }
@@ -248,17 +193,9 @@
 
   ComplexMatrix result (nr, nc);
 
-  double abs_c = abs (c);
-
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double abs_m_elem = abs (m (i, j));
-	if (abs_c > abs_m_elem)
-	  result (i, j) = c;
-	else
-	  result (i, j) = m (i, j);
-      }
+      result (i, j) = xmax (c, m (i, j));
 
   return result;
 }
@@ -271,17 +208,9 @@
 
   ComplexMatrix result (nr, nc);
 
-  double abs_c = abs (c);
-
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double abs_m_elem = abs (m (i, j));
-	if (abs_m_elem > abs_c)
-	  result (i, j) = m (i, j);
-	else
-	  result (i, j) = c;
-      }
+      result (i, j) = xmax (m (i, j), c);
 
   return result;
 }
@@ -301,11 +230,7 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      {
-	double a_elem = a (i, j);
-	double b_elem = b (i, j);
-	result (i, j) = MAX (a_elem, b_elem);
-      }
+      result (i, j) = xmax (a (i, j), b (i, j));
 
   return result;
 }
@@ -336,26 +261,12 @@
       if (columns_are_real_only)
 	{
 	  for (int i = 0; i < nr; i++)
-	    {
-	      double a_elem = real (a (i, j));
-	      double b_elem = real (b (i, j));
-	      if (a_elem > b_elem)
-		result (i, j) = a_elem;
-	      else
-		result (i, j) = b_elem;
-	    }
+	    result (i, j) = xmax (real (a (i, j)), real (b (i, j)));
 	}
       else
 	{
 	  for (int i = 0; i < nr; i++)
-	    {
-	      double abs_a_elem = abs (a (i, j));
-	      double abs_b_elem = abs (b (i, j));
-	      if (abs_a_elem > abs_b_elem)
-		result (i, j) = a (i, j);
-	      else
-		result (i, j) = b (i, j);
-	    }
+	    result (i, j) = xmax (a (i, j), b (i, j));
 	}
     }
 
--- a/src/pr-output.cc	Sat Jun 19 06:51:15 1999 +0000
+++ b/src/pr-output.cc	Tue Jul 13 03:40:17 1999 +0000
@@ -1154,15 +1154,23 @@
     }
 }
 
+static inline void
+do_plus_format (ostream& os, double d)
+{
+  if (d == 0.0)
+    os << " ";
+  else if (d < 0.0)
+    os << "-";
+  else
+    os << "+";
+}
+
 void
 octave_print_internal (ostream& os, double d, bool pr_as_read_syntax)
 {
   if (plus_format)
     {
-      if (d == 0.0)
-	os << " ";
-      else
-	os << "+";
+      do_plus_format (os, d);
     }
   else
     {
@@ -1192,10 +1200,7 @@
 	      if (j == 0)
 		os << "  ";
 
-	      if (m (i, j) == 0.0)
-		os << " ";
-	      else
-		os << "+";
+	      do_plus_format (os, m (i, j));
 	    }
 
 	  if (i < nr - 1)
@@ -1311,16 +1316,32 @@
     }
 }
 
+static inline void
+do_plus_format (ostream& os, const Complex& c)
+{
+  double rp = c.real ();
+  double ip = c.imag ();
+
+  if (rp == 0.0)
+    {
+      if (ip == 0.0)
+	os << " ";
+      else
+	os << "i";
+    }
+  else if (ip == 0.0)
+    do_plus_format (os, rp);
+  else
+    os << "c";
+}
+
 void
 octave_print_internal (ostream& os, const Complex& c,
 		       bool pr_as_read_syntax)
 {
   if (plus_format)
     {
-      if (c == 0.0)
-	os << " ";
-      else
-	os << "+";
+      do_plus_format (os, c);
     }
   else
     {
@@ -1350,10 +1371,7 @@
 	      if (j == 0)
 		os << "  ";
 
-	      if (cm (i, j) == 0.0)
-		os << " ";
-	      else
-		os << "+";
+	      do_plus_format (os, cm (i, j));
 	    }
 
 	  if (i < nr - 1)
--- a/src/sysdep.cc	Sat Jun 19 06:51:15 1999 +0000
+++ b/src/sysdep.cc	Tue Jul 13 03:40:17 1999 +0000
@@ -52,6 +52,10 @@
 LOSE! LOSE!
 #endif
 
+#if defined (HAVE_SYS_IOCTL_H)
+#include <sys/ioctl.h>
+#endif
+
 #if defined (HAVE_FLOATINGPOINT_H)
 #include <floatingpoint.h>
 #endif
--- a/src/variables.cc	Sat Jun 19 06:51:15 1999 +0000
+++ b/src/variables.cc	Tue Jul 13 03:40:17 1999 +0000
@@ -801,27 +801,18 @@
   return retval;
 }
 
-// XXX FIXME XXX -- this should take a list of regular expressions
-// naming the variables to look for.
-
 static octave_value_list
 do_who (int argc, const string_vector& argv)
 {
   octave_value_list retval;
 
   bool show_builtins = false;
-  bool show_functions = (curr_sym_tab == top_level_sym_tab);
-  bool show_variables = true;
+  bool show_functions = false;
+  bool show_variables = false;
   bool show_verbose = false;
 
   string my_name = argv[0];
 
-  if (argc > 1)
-    {
-      show_functions = false;
-      show_variables = false;
-    }
-
   int i;
   for (i = 1; i < argc; i++)
     {
@@ -846,6 +837,15 @@
 	break;
     }
 
+  // If no options were specified to select the type of symbol to
+  // display, then set defaults.
+
+  if (! (show_builtins || show_functions || show_variables))
+    {
+      show_functions = (curr_sym_tab == top_level_sym_tab);
+      show_variables = true;
+    }
+
   int npats = argc - i;
   string_vector pats (npats);
   for (int j = 0; j < npats; j++)