# HG changeset patch # User Jaroslav Hajek # Date 1250849545 -7200 # Node ID 0c72d928408776cfc4fc7ab6495357dce1f1b4af # Parent ded32956d66070d6de10a8520035817b4f941e3b further bool ops tweaks diff -r ded32956d660 -r 0c72d9284087 liboctave/CMatrix.cc --- a/liboctave/CMatrix.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/CMatrix.cc Fri Aug 21 12:12:25 2009 +0200 @@ -3058,8 +3058,7 @@ boolMatrix ComplexMatrix::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } // other operations diff -r ded32956d660 -r 0c72d9284087 liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/CNDArray.cc Fri Aug 21 12:12:25 2009 +0200 @@ -497,8 +497,7 @@ boolNDArray ComplexNDArray::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } // FIXME -- this is not quite the right thing. diff -r ded32956d660 -r 0c72d9284087 liboctave/ChangeLog --- a/liboctave/ChangeLog Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/ChangeLog Fri Aug 21 12:12:25 2009 +0200 @@ -1,3 +1,20 @@ +2009-08-20 Jaroslav Hajek + + * mx-inlines.cc (logical_value): New overloaded template. + (DEFMXBOOL_OP): Use it in definitions. + (mx_inline_not): Also use logical_value. + * mx-op-defs.h (ND_LOGICAL_NAN_CHECK, SC_LOGICAL_NAN_CHECK): Remove + (also from all macros). + + * CMatrix.cc (operator !): Simply call mx_inline_not. + * CNDArray.cc: Ditto. + * dMatrix.cc: Ditto. + * dNDArray.cc: Ditto. + * fCMatrix.cc: Ditto. + * fCNDArray.cc: Ditto. + * fMatrix.cc: Ditto. + * fNDArray.cc: Ditto. + 2009-08-20 Jaroslav Hajek * dMatrix.cc (Matrix::operator!): Simplify & check for NaNs. diff -r ded32956d660 -r 0c72d9284087 liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/dMatrix.cc Fri Aug 21 12:12:25 2009 +0200 @@ -2567,8 +2567,7 @@ boolMatrix Matrix::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } // column vector by row vector -> matrix operations diff -r ded32956d660 -r 0c72d9284087 liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/dNDArray.cc Fri Aug 21 12:12:25 2009 +0200 @@ -538,8 +538,7 @@ boolNDArray NDArray::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } bool diff -r ded32956d660 -r 0c72d9284087 liboctave/fCMatrix.cc --- a/liboctave/fCMatrix.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/fCMatrix.cc Fri Aug 21 12:12:25 2009 +0200 @@ -3051,8 +3051,7 @@ boolMatrix FloatComplexMatrix::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } // other operations diff -r ded32956d660 -r 0c72d9284087 liboctave/fCNDArray.cc --- a/liboctave/fCNDArray.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/fCNDArray.cc Fri Aug 21 12:12:25 2009 +0200 @@ -492,8 +492,7 @@ boolNDArray FloatComplexNDArray::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } // FIXME -- this is not quite the right thing. diff -r ded32956d660 -r 0c72d9284087 liboctave/fMatrix.cc --- a/liboctave/fMatrix.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/fMatrix.cc Fri Aug 21 12:12:25 2009 +0200 @@ -2566,8 +2566,7 @@ boolMatrix FloatMatrix::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } // column vector by row vector -> matrix operations diff -r ded32956d660 -r 0c72d9284087 liboctave/fNDArray.cc --- a/liboctave/fNDArray.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/fNDArray.cc Fri Aug 21 12:12:25 2009 +0200 @@ -496,8 +496,7 @@ boolNDArray FloatNDArray::operator ! (void) const { - ND_LOGICAL_NAN_CHECK (*this); - return do_mx_unary_op (*this, mx_inline_iszero); + return do_mx_unary_op (*this, mx_inline_not); } bool diff -r ded32956d660 -r 0c72d9284087 liboctave/mx-inlines.cc --- a/liboctave/mx-inlines.cc Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/mx-inlines.cc Fri Aug 21 12:12:25 2009 +0200 @@ -48,7 +48,6 @@ { for (size_t i = 0; i < n; i++) r[i] = OP x[i]; } DEFMXUNOP (mx_inline_uminus, -) -DEFMXUNOP (mx_inline_not, !) #define DEFMXUNBOOLOP(F, OP) \ template \ @@ -119,36 +118,57 @@ inline void F (size_t n, bool *r, X x, const std::complex *y) \ { for (size_t i = 0; i < n; i++) r[i] = x OP real (y[i]); } -#define DEFMXBOOLOP(F, EQ1, OP, EQ2) \ +// Convert to logical value, for logical op purposes. +template inline bool logical_value (T x) { return x; } +template inline bool logical_value (const octave_int& x) +{ return x.value (); } + +// NaNs in real data should generate an error. Doing it on-the-fly is faster. + +#define DEFLOGCHKNAN(ARG, ZERO) \ +inline bool logical_value (ARG x) \ +{ if (xisnan (x)) gripe_nan_to_logical_conversion (); return x != ZERO; } + +DEFLOGCHKNAN (double, 0.0) +DEFLOGCHKNAN (const Complex&, 0.0) +DEFLOGCHKNAN (float, 0.0f) +DEFLOGCHKNAN (const FloatComplex&, 0.0f) + +template +void mx_inline_not (size_t n, bool *r, const X* x) +{ + for (size_t i = 0; i < n; i++) + r[i] = ! logical_value (x[i]); +} + +#define DEFMXBOOLOP(F, NOT1, OP, NOT2) \ template \ inline void F (size_t n, bool *r, const X *x, const Y *y) \ { \ - const X xzero = X(); \ - const Y yzero = Y(); \ for (size_t i = 0; i < n; i++) \ - r[i] = (x[i] EQ1 xzero) OP (y[i] EQ2 yzero); \ + r[i] = (NOT1 logical_value (x[i])) OP (NOT2 logical_value (y[i])); \ } \ template \ inline void F (size_t n, bool *r, const X *x, Y y) \ { \ - const X xzero = X(); \ - const bool yy = y EQ2 Y(); \ - for (size_t i = 0; i < n; i++) r[i] = (x[i] EQ1 xzero) OP yy; \ + const bool yy = (NOT2 logical_value (y)); \ + for (size_t i = 0; i < n; i++) \ + r[i] = (NOT1 logical_value (x[i])) OP yy; \ } \ template \ inline void F (size_t n, bool *r, X x, const Y *y) \ { \ - const bool xx = x EQ1 X(); \ - const Y yzero = Y(); \ - for (size_t i = 0; i < n; i++) r[i] = xx OP (y[i] EQ2 yzero); \ + const bool xx = (NOT1 logical_value (x)); \ + for (size_t i = 0; i < n; i++) \ + r[i] = xx OP (NOT2 logical_value (y[i])); \ } -DEFMXBOOLOP (mx_inline_and, !=, &, !=) -DEFMXBOOLOP (mx_inline_or, !=, |, !=) -DEFMXBOOLOP (mx_inline_not_and, ==, &, !=) -DEFMXBOOLOP (mx_inline_not_or, ==, |, !=) -DEFMXBOOLOP (mx_inline_and_not, !=, &, ==) -DEFMXBOOLOP (mx_inline_or_not, !=, |, ==) +DEFMXBOOLOP (mx_inline_and, , &, ) +DEFMXBOOLOP (mx_inline_or, , |, ) +DEFMXBOOLOP (mx_inline_not_and, !, &, ) +DEFMXBOOLOP (mx_inline_not_or, !, |, ) +DEFMXBOOLOP (mx_inline_and_not, , &, !) +DEFMXBOOLOP (mx_inline_or_not, , |, !) template inline bool diff -r ded32956d660 -r 0c72d9284087 liboctave/mx-op-defs.h --- a/liboctave/mx-op-defs.h Fri Aug 21 10:13:53 2009 +0200 +++ b/liboctave/mx-op-defs.h Fri Aug 21 12:12:25 2009 +0200 @@ -28,14 +28,6 @@ #include "mx-op-decl.h" #include "mx-inlines.cc" -#define ND_LOGICAL_NAN_CHECK(X) \ -if (mx_inline_any_nan ((X).numel (), (X).data ())) \ - gripe_nan_to_logical_conversion () - -#define SC_LOGICAL_NAN_CHECK(X) \ - if (xisnan(X)) \ - gripe_nan_to_logical_conversion () - // vector by scalar operations. #define VS_BIN_OP(R, F, OP, V, S) \ @@ -158,8 +150,6 @@ boolMatrix \ F (const M& m, const S& s) \ { \ - ND_LOGICAL_NAN_CHECK (m); \ - SC_LOGICAL_NAN_CHECK (s); \ return do_ms_binary_op (m, s, OP); \ } @@ -215,8 +205,6 @@ boolMatrix \ F (const S& s, const M& m) \ { \ - SC_LOGICAL_NAN_CHECK (s); \ - ND_LOGICAL_NAN_CHECK (m); \ return do_sm_binary_op (s, m, OP); \ } @@ -277,8 +265,6 @@ boolMatrix \ F (const M1& m1, const M2& m2) \ { \ - ND_LOGICAL_NAN_CHECK(m1); \ - ND_LOGICAL_NAN_CHECK(m2); \ return do_mm_binary_op (m1, m2, OP, #F); \ } @@ -381,8 +367,6 @@ boolNDArray \ F (const ND& m, const S& s) \ { \ - ND_LOGICAL_NAN_CHECK (m); \ - SC_LOGICAL_NAN_CHECK (s); \ return do_ms_binary_op (m, s, OP); \ } @@ -487,8 +471,6 @@ boolNDArray \ F (const S& s, const ND& m) \ { \ - SC_LOGICAL_NAN_CHECK (s); \ - ND_LOGICAL_NAN_CHECK (m); \ return do_sm_binary_op (s, m, OP); \ } @@ -549,8 +531,6 @@ boolNDArray \ F (const ND1& m1, const ND2& m2) \ { \ - ND_LOGICAL_NAN_CHECK(m1); \ - ND_LOGICAL_NAN_CHECK(m2); \ return do_mm_binary_op (m1, m2, OP, #F); \ }