Mercurial > hg > octave-shane
changeset 9551:19d298e6f7e5
make ! operator check for NaNs, simplify implementations in liboctave
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 21 Aug 2009 08:18:16 +0200 |
parents | 3d6a9aea2aea |
children | ded32956d660 |
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 src/ChangeLog src/OPERATORS/op-cs-cs.cc src/OPERATORS/op-fcs-fcs.cc src/OPERATORS/op-fs-fs.cc src/OPERATORS/op-s-s.cc |
diffstat | 14 files changed, 66 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -3058,16 +3058,8 @@ boolMatrix ComplexMatrix::operator ! (void) const { - octave_idx_type nr = rows (); - octave_idx_type nc = cols (); - - boolMatrix b (nr, nc); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - b.elem (i, j) = elem (i, j) == 0.0; - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolMatrix, ComplexMatrix> (*this, mx_inline_iszero); } // other operations
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -497,12 +497,8 @@ boolNDArray ComplexNDArray::operator ! (void) const { - boolNDArray b (dims ()); - - for (octave_idx_type i = 0; i < length (); i++) - b.elem (i) = elem (i) == 0.0; - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolNDArray, ComplexNDArray> (*this, mx_inline_iszero); } // FIXME -- this is not quite the right thing.
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,14 @@ +2009-08-20 Jaroslav Hajek <highegg@gmail.com> + + * dMatrix.cc (Matrix::operator!): Simplify & check for NaNs. + * fMatrix.cc (FloatMatrix::operator!): Ditto. + * CMatrix.cc (ComplexMatrix::operator!): Ditto. + * fCMatrix.cc (FloatComplexMatrix::operator!): Ditto. + * dNDArray.cc (NDArray::operator!): Ditto. + * fNDArray.cc (FloatNDArray::operator!): Ditto. + * CNDArray.cc (ComplexNDArray::operator!): Ditto. + * fCNDArray.cc (FloatComplexNDArray::operator!): Ditto. + 2009-08-20 Jaroslav Hajek <highegg@gmail.com> * mx-inlines.cc (mx_inline_add, mx_inline_sub, mx_inline_mul,
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -2567,16 +2567,8 @@ boolMatrix Matrix::operator ! (void) const { - octave_idx_type nr = rows (); - octave_idx_type nc = cols (); - - boolMatrix b (nr, nc); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - b.elem (i, j) = ! elem (i, j); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolMatrix, Matrix> (*this, mx_inline_iszero); } // column vector by row vector -> matrix operations
--- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -538,12 +538,8 @@ boolNDArray NDArray::operator ! (void) const { - boolNDArray b (dims ()); - - for (octave_idx_type i = 0; i < length (); i++) - b.elem (i) = ! elem (i); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolNDArray, NDArray> (*this, mx_inline_iszero); } bool
--- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -3051,16 +3051,8 @@ boolMatrix FloatComplexMatrix::operator ! (void) const { - octave_idx_type nr = rows (); - octave_idx_type nc = cols (); - - boolMatrix b (nr, nc); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - b.elem (i, j) = elem (i, j) == static_cast<float> (0.0); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolMatrix, FloatComplexMatrix> (*this, mx_inline_iszero); } // other operations
--- a/liboctave/fCNDArray.cc +++ b/liboctave/fCNDArray.cc @@ -492,12 +492,8 @@ boolNDArray FloatComplexNDArray::operator ! (void) const { - boolNDArray b (dims ()); - - for (octave_idx_type i = 0; i < length (); i++) - b.elem (i) = elem (i) == static_cast<float> (0.0); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolNDArray, FloatComplexNDArray> (*this, mx_inline_iszero); } // FIXME -- this is not quite the right thing.
--- a/liboctave/fMatrix.cc +++ b/liboctave/fMatrix.cc @@ -2566,16 +2566,8 @@ boolMatrix FloatMatrix::operator ! (void) const { - octave_idx_type nr = rows (); - octave_idx_type nc = cols (); - - boolMatrix b (nr, nc); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - b.elem (i, j) = ! elem (i, j); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolMatrix, FloatMatrix> (*this, mx_inline_iszero); } // column vector by row vector -> matrix operations
--- a/liboctave/fNDArray.cc +++ b/liboctave/fNDArray.cc @@ -496,12 +496,8 @@ boolNDArray FloatNDArray::operator ! (void) const { - boolNDArray b (dims ()); - - for (octave_idx_type i = 0; i < length (); i++) - b.elem (i) = ! elem (i); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op<boolNDArray, FloatNDArray> (*this, mx_inline_iszero); } bool
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-08-21 Jaroslav Hajek <highegg@gmail.com> + + * OPERATORS/op-s-s.cc: Check for NaN in ! operator. + * OPERATORS/op-fs-fs.cc: Ditto. + * OPERATORS/op-cs-cs.cc: Ditto. + * OPERATORS/op-fcs-fcs.cc: Ditto. + 2009-08-17 Jaroslav Hajek <highegg@gmail.com> * ops.h (DEFNDASSIGNOP_FNOP): New macro.
--- a/src/OPERATORS/op-cs-cs.cc +++ b/src/OPERATORS/op-cs-cs.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include "Array-util.h" + #include "gripes.h" #include "oct-obj.h" #include "ov.h" @@ -42,8 +44,10 @@ DEFUNOP (not, complex) { CAST_UNOP_ARG (const octave_complex&); - - return octave_value (v.complex_value () == 0.0); + Complex x = v.complex_value (); + if (xisnan (x)) + gripe_nan_to_logical_conversion (); + return octave_value (x == 0.0); } DEFUNOP_OP (uplus, complex, /* no-op */)
--- a/src/OPERATORS/op-fcs-fcs.cc +++ b/src/OPERATORS/op-fcs-fcs.cc @@ -42,8 +42,10 @@ DEFUNOP (not, float_complex) { CAST_UNOP_ARG (const octave_float_complex&); - - return octave_value (v.float_complex_value () == 0.0); + FloatComplex x = v.float_complex_value (); + if (xisnan (x)) + gripe_nan_to_logical_conversion (); + return octave_value (x == 0.0f); } DEFUNOP_OP (uplus, float_complex, /* no-op */)
--- a/src/OPERATORS/op-fs-fs.cc +++ b/src/OPERATORS/op-fs-fs.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include "Array-util.h" + #include "gripes.h" #include "oct-obj.h" #include "ov.h" @@ -39,7 +41,15 @@ // scalar unary ops. -DEFUNOP_OP (not, float_scalar, !) +DEFUNOP (not, float_scalar) +{ + CAST_UNOP_ARG (const octave_float_scalar&); + float x = v.float_value (); + if (xisnan (x)) + gripe_nan_to_logical_conversion (); + return octave_value (x == 0.0f); +} + DEFUNOP_OP (uplus, float_scalar, /* no-op */) DEFUNOP_OP (uminus, float_scalar, -) DEFUNOP_OP (transpose, float_scalar, /* no-op */)
--- a/src/OPERATORS/op-s-s.cc +++ b/src/OPERATORS/op-s-s.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include "Array-util.h" + #include "gripes.h" #include "oct-obj.h" #include "ov.h" @@ -40,7 +42,15 @@ // scalar unary ops. -DEFUNOP_OP (not, scalar, !) +DEFUNOP (not, scalar) +{ + CAST_UNOP_ARG (const octave_scalar&); + double x = v.scalar_value (); + if (xisnan (x)) + gripe_nan_to_logical_conversion (); + return octave_value (x == 0.0); +} + DEFUNOP_OP (uplus, scalar, /* no-op */) DEFUNOP_OP (uminus, scalar, -) DEFUNOP_OP (transpose, scalar, /* no-op */)