Mercurial > hg > octave-max
changeset 9825:7483fe200fab
narrow complex values with negative zero imaginary parts
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 13 Nov 2009 12:34:46 +0100 |
parents | 6631c61a4a4e |
children | b2a282c37217 |
files | liboctave/CDiagMatrix.cc liboctave/CMatrix.cc liboctave/CNDArray.cc liboctave/CSparse.cc liboctave/ChangeLog liboctave/fCDiagMatrix.cc liboctave/fCMatrix.cc liboctave/fCNDArray.cc src/ChangeLog src/ov-complex.cc src/ov-cx-mat.cc src/ov-flt-complex.cc src/ov-flt-cx-mat.cc |
diffstat | 13 files changed, 45 insertions(+), 125 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CDiagMatrix.cc +++ b/liboctave/CDiagMatrix.cc @@ -412,16 +412,7 @@ bool ComplexDiagMatrix::all_elements_are_real (void) const { - octave_idx_type len = length (); - for (octave_idx_type i = 0; i < len; i++) - { - double ip = std::imag (elem (i, i)); - - if (ip != 0.0 || lo_ieee_signbit (ip)) - return false; - } - - return true; + return mx_inline_all_real (length (), data ()); } // diagonal matrix by diagonal matrix -> diagonal matrix operations
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -3118,21 +3118,7 @@ bool ComplexMatrix::all_elements_are_real (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++) - { - double ip = std::imag (elem (i, j)); - - if (ip != 0.0 || lo_ieee_signbit (ip)) - return false; - } - } - - return true; + return mx_inline_all_real (numel (), data ()); } // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -538,17 +538,7 @@ bool ComplexNDArray::all_elements_are_real (void) const { - octave_idx_type nel = nelem (); - - for (octave_idx_type i = 0; i < nel; i++) - { - double ip = std::imag (elem (i)); - - if (ip != 0.0 || lo_ieee_signbit (ip)) - return false; - } - - return true; + return mx_inline_all_real (numel (), data ()); } // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/CSparse.cc +++ b/liboctave/CSparse.cc @@ -53,6 +53,7 @@ #include "Sparse-diag-op-defs.h" #include "Sparse-perm-op-defs.h" +#include "mx-inlines.cc" // Define whether to use a basic QR solver or one that uses a Dulmange // Mendelsohn factorization to seperate the problem into under-determined, @@ -7268,17 +7269,7 @@ bool SparseComplexMatrix::all_elements_are_real (void) const { - octave_idx_type nel = nnz (); - - for (octave_idx_type i = 0; i < nel; i++) - { - double ip = std::imag (data (i)); - - if (ip != 0.0 || lo_ieee_signbit (ip)) - return false; - } - - return true; + return mx_inline_all_real (nnz (), data ()); } // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,15 @@ +2009-11-13 Jaroslav Hajek <highegg@gmail.com> + + * CNDArray.cc (ComplexNDArray::all_elements_are_real): + Use mx_inline_all_real. + * CMatrix.cc (ComplexMatrix::all_elements_are_real): Ditto. + * fCNDArray.cc (FloatComplexNDArray::all_elements_are_real): + Use mx_inline_all_real. + * fCMatrix.cc (FloatComplexMatrix::all_elements_are_real): Ditto. + * CDiagMatrix.cc (ComplexDiagMatrix::all_elements_are_real): Ditto. + * fCDiagMatrix.cc (FloatComplexDiagMatrix::all_elements_are_real): Ditto. + * CSparse.cc (SparseComplexMatrix::all_elements_are_real): Ditto. + 2009-11-17 Jaroslav Hajek <highegg@gmail.com> * base-aepbal.h (permuting_vector): Fix lower part swapping.
--- a/liboctave/fCDiagMatrix.cc +++ b/liboctave/fCDiagMatrix.cc @@ -412,16 +412,7 @@ bool FloatComplexDiagMatrix::all_elements_are_real (void) const { - octave_idx_type len = length (); - for (octave_idx_type i = 0; i < len; i++) - { - float ip = std::imag (elem (i, i)); - - if (ip != 0.0 || lo_ieee_signbit (ip)) - return false; - } - - return true; + return mx_inline_all_real (length (), data ()); } // diagonal matrix by diagonal matrix -> diagonal matrix operations
--- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -3111,21 +3111,7 @@ bool FloatComplexMatrix::all_elements_are_real (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++) - { - float ip = std::imag (elem (i, j)); - - if (ip != 0.0 || lo_ieee_signbit (ip)) - return false; - } - } - - return true; + return mx_inline_all_real (numel (), data ()); } // Return nonzero if any element of CM has a non-integer real or
--- a/liboctave/fCNDArray.cc +++ b/liboctave/fCNDArray.cc @@ -533,17 +533,7 @@ bool FloatComplexNDArray::all_elements_are_real (void) const { - octave_idx_type nel = nelem (); - - for (octave_idx_type i = 0; i < nel; i++) - { - float ip = std::imag (elem (i)); - - if (ip != 0.0 || lo_ieee_signbit (ip)) - return false; - } - - return true; + return mx_inline_all_real (numel (), data ()); } // Return nonzero if any element of CM has a non-integer real or
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2009-11-13 Jaroslav Hajek <highegg@gmail.com> + + * ov-complex.cc (octave_complex::try_narrowing_conversion): Don't + check signbit. + * ov-flt-complex.cc (octave_float_complex::try_narrowing_conversion): + Ditto. + * ov-cx-mat.cc (octave_complex_matrix::try_narrowing_conversion): + Simplify. Don't check signbit. + * ov-flt-cx-mat.cc + (octave_float_complex_matrix::try_narrowing_conversion): Ditto. + 2009-11-17 Jaroslav Hajek <highegg@gmail.com> * ov-re-mat.cc (do_rc_map): New static function.
--- a/src/ov-complex.cc +++ b/src/ov-complex.cc @@ -77,7 +77,7 @@ double im = std::imag (scalar); - if (im == 0.0 && ! lo_ieee_signbit (im)) + if (im == 0.0) retval = new octave_scalar (std::real (scalar)); return retval;
--- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -82,28 +82,14 @@ { octave_base_value *retval = 0; - if (matrix.ndims () == 2) + if (matrix.numel () == 1) { - ComplexMatrix cm = matrix.matrix_value (); - - octave_idx_type nr = cm.rows (); - octave_idx_type nc = cm.cols (); - - if (nr == 1 && nc == 1) - { - Complex c = matrix (0, 0); + Complex c = matrix (0); - double im = std::imag (c); - - if (im == 0.0 && ! lo_ieee_signbit (im)) - retval = new octave_scalar (std::real (c)); - else - retval = new octave_complex (c); - } - else if (nr == 0 || nc == 0) - retval = new octave_matrix (Matrix (nr, nc)); - else if (cm.all_elements_are_real ()) - retval = new octave_matrix (::real (cm)); + if (std::imag (c) == 0.0) + retval = new octave_scalar (std::real (c)); + else + retval = new octave_complex (c); } else if (matrix.all_elements_are_real ()) retval = new octave_matrix (::real (matrix));
--- a/src/ov-flt-complex.cc +++ b/src/ov-flt-complex.cc @@ -62,7 +62,7 @@ float im = std::imag (scalar); - if (im == 0.0 && ! lo_ieee_signbit (im)) + if (im == 0.0) retval = new octave_float_scalar (std::real (scalar)); return retval;
--- a/src/ov-flt-cx-mat.cc +++ b/src/ov-flt-cx-mat.cc @@ -71,28 +71,14 @@ { octave_base_value *retval = 0; - if (matrix.ndims () == 2) + if (matrix.numel () == 1) { - FloatComplexMatrix cm = matrix.matrix_value (); - - octave_idx_type nr = cm.rows (); - octave_idx_type nc = cm.cols (); - - if (nr == 1 && nc == 1) - { - FloatComplex c = matrix (0, 0); + FloatComplex c = matrix (0); - float im = std::imag (c); - - if (im == 0.0 && ! lo_ieee_signbit (im)) - retval = new octave_float_scalar (std::real (c)); - else - retval = new octave_float_complex (c); - } - else if (nr == 0 || nc == 0) - retval = new octave_float_matrix (FloatMatrix (nr, nc)); - else if (cm.all_elements_are_real ()) - retval = new octave_float_matrix (::real (cm)); + if (std::imag (c) == 0.0) + retval = new octave_float_scalar (std::real (c)); + else + retval = new octave_float_complex (c); } else if (matrix.all_elements_are_real ()) retval = new octave_float_matrix (::real (matrix));