changeset 11008:3622db30ff05

simplify some array tests in liboctave
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 21 Sep 2010 13:09:12 +0200
parents ffe58182db89
children 064aaf82222f
files liboctave/CMatrix.cc liboctave/CNDArray.cc liboctave/ChangeLog liboctave/dMatrix.cc liboctave/dNDArray.cc liboctave/fCMatrix.cc liboctave/fCNDArray.cc liboctave/fMatrix.cc liboctave/fNDArray.cc
diffstat 9 files changed, 49 insertions(+), 160 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/CMatrix.cc
+++ b/liboctave/CMatrix.cc
@@ -3052,35 +3052,13 @@
 bool
 ComplexMatrix::any_element_is_nan (void) const
 {
-  octave_idx_type nr = rows ();
-  octave_idx_type nc = cols ();
-
-  for (octave_idx_type j = 0; j < nc; j++)
-    for (octave_idx_type i = 0; i < nr; i++)
-      {
-        Complex val = elem (i, j);
-        if (xisnan (val))
-          return true;
-      }
-
-  return false;
+  return do_mx_check<Complex> (*this, mx_inline_any_nan);
 }
 
 bool
 ComplexMatrix::any_element_is_inf_or_nan (void) const
 {
-  octave_idx_type nr = rows ();
-  octave_idx_type nc = cols ();
-
-  for (octave_idx_type j = 0; j < nc; j++)
-    for (octave_idx_type i = 0; i < nr; i++)
-      {
-        Complex val = elem (i, j);
-        if (xisinf (val) || xisnan (val))
-          return true;
-      }
-
-  return false;
+  return ! do_mx_check<Complex> (*this, mx_inline_all_finite);
 }
 
 // Return true if no elements have imaginary components.
@@ -3088,7 +3066,7 @@
 bool
 ComplexMatrix::all_elements_are_real (void) const
 {
-  return mx_inline_all_real (numel (), data ());
+  return do_mx_check<Complex> (*this, mx_inline_all_real);
 }
 
 // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/CNDArray.cc
+++ b/liboctave/CNDArray.cc
@@ -508,29 +508,13 @@
 bool
 ComplexNDArray::any_element_is_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      Complex val = elem (i);
-      if (xisnan (val))
-        return true;
-    }
-  return false;
+  return do_mx_check<Complex> (*this, mx_inline_any_nan);
 }
 
 bool
 ComplexNDArray::any_element_is_inf_or_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      Complex val = elem (i);
-      if (xisinf (val) || xisnan (val))
-        return true;
-    }
-  return false;
+  return ! do_mx_check<Complex> (*this, mx_inline_all_finite);
 }
 
 // Return true if no elements have imaginary components.
@@ -538,7 +522,7 @@
 bool
 ComplexNDArray::all_elements_are_real (void) const
 {
-  return mx_inline_all_real (numel (), data ());
+  return do_mx_check<Complex> (*this, mx_inline_all_real);
 }
 
 // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,30 @@
+2010-09-21  Jaroslav Hajek  <highegg@gmail.com>
+
+	* dNDArray.cc (NDArray::any_element_is_negative, 
+	NDArray::any_element_is_nan, 
+	NDArray::any_element_is_inf_or_nan): Simplify.
+	* fNDArray.cc (FloatNDArray::any_element_is_negative, 
+	FloatNDArray::any_element_is_nan, 
+	FloatNDArray::any_element_is_inf_or_nan): Simplify.
+	* dMatrix.cc (Matrix::any_element_is_negative, 
+	Matrix::any_element_is_nan, 
+	Matrix::any_element_is_inf_or_nan): Simplify.
+	* fMatrix.cc (FloatMatrix::any_element_is_negative, 
+	FloatMatrix::any_element_is_nan, 
+	FloatMatrix::any_element_is_inf_or_nan): Simplify.
+	* CNDArray.cc (ComplexNDArray::any_element_is_negative, 
+	ComplexNDArray::any_element_is_nan, 
+	ComplexNDArray::any_element_is_inf_or_nan): Simplify.
+	* fCNDArray.cc (FloatComplexNDArray::any_element_is_negative, 
+	FloatComplexNDArray::any_element_is_nan, 
+	FloatComplexNDArray::any_element_is_inf_or_nan): Simplify.
+	* CMatrix.cc (ComplexMatrix::any_element_is_negative, 
+	ComplexMatrix::any_element_is_nan, 
+	ComplexMatrix::any_element_is_inf_or_nan): Simplify.
+	* fCMatrix.cc (FloatComplexMatrix::any_element_is_negative, 
+	FloatComplexMatrix::any_element_is_nan, 
+	FloatComplexMatrix::any_element_is_inf_or_nan): Simplify.
+
 2010-09-21  John W. Eaton  <jwe@octave.org>
 
 	* oct-env.cc (do_get_host_name): Call gnulib::gethostname
--- a/liboctave/dMatrix.cc
+++ b/liboctave/dMatrix.cc
@@ -2630,11 +2630,7 @@
           return true;
     }
   else
-    {
-      for (octave_idx_type i = 0; i < nel; i++)
-        if (elem (i) < 0)
-          return true;
-    }
+    return do_mx_check<double> (*this, mx_inline_any_negative);
 
   return false;
 }
--- a/liboctave/dNDArray.cc
+++ b/liboctave/dNDArray.cc
@@ -556,7 +556,7 @@
           return true;
     }
   else
-    return mx_inline_any_negative (numel (), data ());
+    return do_mx_check<double> (*this, mx_inline_any_negative);
 
   return false;
 }
@@ -564,31 +564,13 @@
 bool
 NDArray::any_element_is_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      double val = elem (i);
-      if (xisnan (val))
-        return true;
-    }
-
-  return false;
+  return do_mx_check<double> (*this, mx_inline_any_nan);
 }
 
 bool
 NDArray::any_element_is_inf_or_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      double val = elem (i);
-      if (xisinf (val) || xisnan (val))
-        return true;
-    }
-
-  return false;
+  return ! do_mx_check<double> (*this, mx_inline_all_finite);
 }
 
 bool
--- a/liboctave/fCMatrix.cc
+++ b/liboctave/fCMatrix.cc
@@ -3045,35 +3045,13 @@
 bool
 FloatComplexMatrix::any_element_is_nan (void) const
 {
-  octave_idx_type nr = rows ();
-  octave_idx_type nc = cols ();
-
-  for (octave_idx_type j = 0; j < nc; j++)
-    for (octave_idx_type i = 0; i < nr; i++)
-      {
-        FloatComplex val = elem (i, j);
-        if (xisnan (val))
-          return true;
-      }
-
-  return false;
+  return do_mx_check<FloatComplex> (*this, mx_inline_any_nan);
 }
 
 bool
 FloatComplexMatrix::any_element_is_inf_or_nan (void) const
 {
-  octave_idx_type nr = rows ();
-  octave_idx_type nc = cols ();
-
-  for (octave_idx_type j = 0; j < nc; j++)
-    for (octave_idx_type i = 0; i < nr; i++)
-      {
-        FloatComplex val = elem (i, j);
-        if (xisinf (val) || xisnan (val))
-          return true;
-      }
-
-  return false;
+  return ! do_mx_check<FloatComplex> (*this, mx_inline_all_finite);
 }
 
 // Return true if no elements have imaginary components.
@@ -3081,7 +3059,7 @@
 bool
 FloatComplexMatrix::all_elements_are_real (void) const
 {
-  return mx_inline_all_real (numel (), data ());
+  return do_mx_check<FloatComplex> (*this, mx_inline_all_real);
 }
 
 // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/fCNDArray.cc
+++ b/liboctave/fCNDArray.cc
@@ -503,29 +503,13 @@
 bool
 FloatComplexNDArray::any_element_is_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      FloatComplex val = elem (i);
-      if (xisnan (val))
-        return true;
-    }
-  return false;
+  return do_mx_check<FloatComplex> (*this, mx_inline_any_nan);
 }
 
 bool
 FloatComplexNDArray::any_element_is_inf_or_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      FloatComplex val = elem (i);
-      if (xisinf (val) || xisnan (val))
-        return true;
-    }
-  return false;
+  return ! do_mx_check<FloatComplex> (*this, mx_inline_all_finite);
 }
 
 // Return true if no elements have imaginary components.
@@ -533,7 +517,7 @@
 bool
 FloatComplexNDArray::all_elements_are_real (void) const
 {
-  return mx_inline_all_real (numel (), data ());
+  return do_mx_check<FloatComplex> (*this, mx_inline_all_real);
 }
 
 // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/fMatrix.cc
+++ b/liboctave/fMatrix.cc
@@ -2629,11 +2629,7 @@
           return true;
     }
   else
-    {
-      for (octave_idx_type i = 0; i < nel; i++)
-        if (elem (i) < 0)
-          return true;
-    }
+    return do_mx_check<float> (*this, mx_inline_any_negative);
 
   return false;
 }
@@ -2641,31 +2637,13 @@
 bool
 FloatMatrix::any_element_is_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      float val = elem (i);
-      if (xisnan (val))
-        return true;
-    }
-
-  return false;
+  return do_mx_check<float> (*this, mx_inline_any_nan);
 }
 
 bool
 FloatMatrix::any_element_is_inf_or_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      float val = elem (i);
-      if (xisinf (val) || xisnan (val))
-        return true;
-    }
-
-  return false;
+  return ! do_mx_check<float> (*this, mx_inline_all_finite);
 }
 
 bool
--- a/liboctave/fNDArray.cc
+++ b/liboctave/fNDArray.cc
@@ -514,7 +514,7 @@
           return true;
     }
   else
-    return mx_inline_any_negative (numel (), data ());
+    return do_mx_check<float> (*this, mx_inline_any_negative);
 
   return false;
 }
@@ -522,31 +522,13 @@
 bool
 FloatNDArray::any_element_is_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      float val = elem (i);
-      if (xisnan (val))
-        return true;
-    }
-
-  return false;
+  return do_mx_check<float> (*this, mx_inline_any_nan);
 }
 
 bool
 FloatNDArray::any_element_is_inf_or_nan (void) const
 {
-  octave_idx_type nel = nelem ();
-
-  for (octave_idx_type i = 0; i < nel; i++)
-    {
-      float val = elem (i);
-      if (xisinf (val) || xisnan (val))
-        return true;
-    }
-
-  return false;
+  return ! do_mx_check<float> (*this, mx_inline_all_finite);
 }
 
 bool