# HG changeset patch # User Jaroslav Hajek # Date 1250835496 -7200 # Node ID 19d298e6f7e5c421792b2cb7aa08a7efbbf0ce34 # Parent 3d6a9aea2aeae1b31d33b7c36b87ea2f99d0ae98 make ! operator check for NaNs, simplify implementations in liboctave diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/CMatrix.cc --- a/liboctave/CMatrix.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/CMatrix.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (*this, mx_inline_iszero); } // other operations diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/CNDArray.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (*this, mx_inline_iszero); } // FIXME -- this is not quite the right thing. diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/ChangeLog --- a/liboctave/ChangeLog Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/ChangeLog Fri Aug 21 08:18:16 2009 +0200 @@ -1,3 +1,14 @@ +2009-08-20 Jaroslav Hajek + + * 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 * mx-inlines.cc (mx_inline_add, mx_inline_sub, mx_inline_mul, diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/dMatrix.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (*this, mx_inline_iszero); } // column vector by row vector -> matrix operations diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/dNDArray.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (*this, mx_inline_iszero); } bool diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/fCMatrix.cc --- a/liboctave/fCMatrix.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/fCMatrix.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (0.0); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op (*this, mx_inline_iszero); } // other operations diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/fCNDArray.cc --- a/liboctave/fCNDArray.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/fCNDArray.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (0.0); - - return b; + ND_LOGICAL_NAN_CHECK (*this); + return do_mx_unary_op (*this, mx_inline_iszero); } // FIXME -- this is not quite the right thing. diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/fMatrix.cc --- a/liboctave/fMatrix.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/fMatrix.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (*this, mx_inline_iszero); } // column vector by row vector -> matrix operations diff -r 3d6a9aea2aea -r 19d298e6f7e5 liboctave/fNDArray.cc --- a/liboctave/fNDArray.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/liboctave/fNDArray.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 (*this, mx_inline_iszero); } bool diff -r 3d6a9aea2aea -r 19d298e6f7e5 src/ChangeLog --- a/src/ChangeLog Wed Aug 19 22:55:15 2009 +0200 +++ b/src/ChangeLog Fri Aug 21 08:18:16 2009 +0200 @@ -1,3 +1,10 @@ +2009-08-21 Jaroslav Hajek + + * 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 * ops.h (DEFNDASSIGNOP_FNOP): New macro. diff -r 3d6a9aea2aea -r 19d298e6f7e5 src/OPERATORS/op-cs-cs.cc --- a/src/OPERATORS/op-cs-cs.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/src/OPERATORS/op-cs-cs.cc Fri Aug 21 08:18:16 2009 +0200 @@ -25,6 +25,8 @@ #include #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 */) diff -r 3d6a9aea2aea -r 19d298e6f7e5 src/OPERATORS/op-fcs-fcs.cc --- a/src/OPERATORS/op-fcs-fcs.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/src/OPERATORS/op-fcs-fcs.cc Fri Aug 21 08:18:16 2009 +0200 @@ -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 */) diff -r 3d6a9aea2aea -r 19d298e6f7e5 src/OPERATORS/op-fs-fs.cc --- a/src/OPERATORS/op-fs-fs.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/src/OPERATORS/op-fs-fs.cc Fri Aug 21 08:18:16 2009 +0200 @@ -25,6 +25,8 @@ #include #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 */) diff -r 3d6a9aea2aea -r 19d298e6f7e5 src/OPERATORS/op-s-s.cc --- a/src/OPERATORS/op-s-s.cc Wed Aug 19 22:55:15 2009 +0200 +++ b/src/OPERATORS/op-s-s.cc Fri Aug 21 08:18:16 2009 +0200 @@ -25,6 +25,8 @@ #include #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 */)