# HG changeset patch # User Jaroslav Hajek # Date 1285067352 -7200 # Node ID 3622db30ff05451581054c7fe000dae8f05fef28 # Parent ffe58182db893fe1b1a8dcd1d7681c03ff69f586 simplify some array tests in liboctave diff --git a/liboctave/CMatrix.cc b/liboctave/CMatrix.cc --- 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 (*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 (*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 (*this, mx_inline_all_real); } // Return nonzero if any element of CM has a non-integer real or diff --git a/liboctave/CNDArray.cc b/liboctave/CNDArray.cc --- 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 (*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 (*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 (*this, mx_inline_all_real); } // Return nonzero if any element of CM has a non-integer real or diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,30 @@ +2010-09-21 Jaroslav Hajek + + * 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 * oct-env.cc (do_get_host_name): Call gnulib::gethostname diff --git a/liboctave/dMatrix.cc b/liboctave/dMatrix.cc --- 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 (*this, mx_inline_any_negative); return false; } diff --git a/liboctave/dNDArray.cc b/liboctave/dNDArray.cc --- 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 (*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 (*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 (*this, mx_inline_all_finite); } bool diff --git a/liboctave/fCMatrix.cc b/liboctave/fCMatrix.cc --- 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 (*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 (*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 (*this, mx_inline_all_real); } // Return nonzero if any element of CM has a non-integer real or diff --git a/liboctave/fCNDArray.cc b/liboctave/fCNDArray.cc --- 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 (*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 (*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 (*this, mx_inline_all_real); } // Return nonzero if any element of CM has a non-integer real or diff --git a/liboctave/fMatrix.cc b/liboctave/fMatrix.cc --- 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 (*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 (*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 (*this, mx_inline_all_finite); } bool diff --git a/liboctave/fNDArray.cc b/liboctave/fNDArray.cc --- 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 (*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 (*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 (*this, mx_inline_all_finite); } bool