[PATCH] Modify the min/max mappers (1/4)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Modify the min/max mappers (1/4)

Edward Jason Riedy
This is a re-do of the patch I sent previously, plus the modifications
to the min and max interpreter routines.  It's the first of four:

  1. Just modify the mappers.
  2. Factor matrix reduction operations and add ignore_nan opt. arg.
  3. Make the interpreter aware of the "ignore-nan" and "prefer-nan"
     options.
  4. Add a few tests.

The intent is to allow NaNs to be ignored when taking a min or max
reduction.  So min(NaN, 0) == min(NaN, 0, 'ignore-nan') == 0 by
default, while isnan(min([NaN, 0], 'prefer-nan')) is true.  This
isn't fully exposed through Octave until the third patch, so these
don't make too much sense separately, but they're easier to read.

This patch is straight-forward.

BTW, the new BLAS standard officially has no position on the
behavior of NaNs w.r.t. min and max pseudo-operators.  Blah.
So the future idamax (can't recall the new names) are undefined
in the face of NaNs.  sigh...

Jason

OCTAVE-PATCH-MAPPERS
liboctave/ChangeLog
        * lo-mappers.h: Add xmin_nan, xmax_nan declarations.
        * lo-mappers.cc (xmin_nan): Added double and Complex as copy of
        old xmin.
        (xmax_nan): Ditto.
        (xmin): Replaced xisnan(x) with xisnan(y) to prefer returning
        numbers rather than NaNs.
        (xmax): Ditto.

--- octave.orig/liboctave/lo-mappers.cc Thu Sep  9 22:17:01 1999
+++ octave.2/liboctave/lo-mappers.cc Sat Sep  2 20:06:29 2000
@@ -185,12 +185,24 @@
 double
 xmin (double x, double y)
 {
-  return x < y ? x : (xisnan (x) ? x : y);
+  return x < y ? x : (xisnan (y) ? x : y);
 }
 
 double
 xmax (double x, double y)
 {
+  return x > y ? x : (xisnan (y) ? x : y);
+}
+
+double
+xmin_nan (double x, double y)
+{
+  return x < y ? x : (xisnan (x) ? x : y);
+}
+
+double
+xmax_nan (double x, double y)
+{
   return x > y ? x : (xisnan (x) ? x : y);
 }
 
@@ -315,11 +327,23 @@
 Complex
 xmin (const Complex& x, const Complex& y)
 {
-  return abs (x) < abs (y) ? x : (xisnan (x) ? x : y);
+  return abs (x) < abs (y) ? x : (xisnan (y) ? x : y);
 }
 
 Complex
 xmax (const Complex& x, const Complex& y)
+{
+  return abs (x) > abs (y) ? x : (xisnan (y) ? x : y);
+}
+
+Complex
+xmin_nan (const Complex& x, const Complex& y)
+{
+  return abs (x) < abs (y) ? x : (xisnan (x) ? x : y);
+}
+
+Complex
+xmax_nan (const Complex& x, const Complex& y)
 {
   return abs (x) > abs (y) ? x : (xisnan (x) ? x : y);
 }
diff --new-file -r -u octave.orig/liboctave/lo-mappers.h octave.2/liboctave/lo-mappers.h
--- octave.orig/liboctave/lo-mappers.h Mon Jul 12 20:35:32 1999
+++ octave.2/liboctave/lo-mappers.h Sat Sep  2 20:06:29 2000
@@ -41,6 +41,8 @@
 
 extern double xmin (double x, double y);
 extern double xmax (double x, double y);
+extern double xmin_nan (double x, double y);
+extern double xmax_nan (double x, double y);
 
 extern Complex acos (const Complex& x);
 extern Complex acosh (const Complex& x);
@@ -63,6 +65,8 @@
 
 extern Complex xmin (const Complex& x, const Complex& y);
 extern Complex xmax (const Complex& x, const Complex& y);
+extern Complex xmin_nan (const Complex& x, const Complex& y);
+extern Complex xmax_nan (const Complex& x, const Complex& y);
 
 #endif