Closed numpy-gitbot closed 12 years ago
atmention:charris wrote on 2012-09-25
Definitely a bug.
Milestone changed to NumPy 1.7
by atmention:charris on 2012-09-25
atmention:charris wrote on 2012-09-25
Looks to be a problem in the ufunc reduce method for complex:
In [15]: a = ones(5)*1j
In [16]: logical_or(a,a)
Out[16]: array([ True, True, True, True, True], dtype=bool)
In [17]: logical_or.reduce(a)
Out[17]: False
atmention:charris wrote on 2012-09-25
I expect the problem arises from the fact that the output type is not the same as the input type.
One way to fix this would be to use a special functions for the any and all methods instead of the ufunc.
trac user seberg wrote on 2012-10-01
Puh... I checked this a bit, and this seems to fix it, but i have really no idea whatsoever if this is the correct way to fix it or if there is more to fix... already puzzles me when those conversion functions from array_types.c.src get actually called. (Note that .astype(bool) also failed here.)
--- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src +++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src atmention:atmention: -811,9 +811,17 atmention:atmention: static void dst_value[0] = _CONVERT_FN(src_value[0]); dst_value[1] = _CONVERT_FN(src_value[1]);
trac user seberg wrote on 2012-10-01
Sorry forgot formatting :/...
--- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
+++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
atmention:atmention: -811,9 +811,17 atmention:atmention: static void
dst_value[0] = _CONVERT_FN(src_value[0]);
dst_value[1] = _CONVERT_FN(src_value[1]);
# elif !atmention:alignedatmention:
- dst_value = _CONVERT_FN(src_value[0]);
+# if atmention:is_bool2atmention:
+ dst_value = _CONVERT_FN(src_value[0]) || _CONVERT_FN(src_value[1]);
+# else
+ dst_value = _CONVERT_FN(src_value[0]);
+# endif
# else
- *(_TYPE2 *)dst = _CONVERT_FN(src_value[0]);
+# if atmention:is_bool2atmention:
+ *(_TYPE2 *)dst = _CONVERT_FN(src_value[0]) || _CONVERT_FN(src_value[1]);
+# else
+ *(_TYPE2 *)dst = _CONVERT_FN(src_value[0]);
+# endif
# endif
#else
# if atmention:is_complex2atmention:
atmention:charris wrote on 2012-10-04
Should be fixed in mainline.
Original ticket http://projects.scipy.org/numpy/ticket/2218 on 2012-09-25 by trac user mike.wimmer, assigned to unknown.
In numpy versions 1.6.1, 1.6.2 and the latest git version (those I tried), numpy.any ignores the imaginary part of arrays completely:
whereas
Now, since
I think this is a genuine bug.
Note that in numpy 1.5.1 all of the above returned True, i.e. the imaginary part was taken into account then.