Permalink
Browse files

Merge pull request #2741 from certik/backport477

Backport #477
  • Loading branch information...
2 parents b56f315 + dc0ca35 commit 3a52aa06c50e8901a90d54971b7e33b3afd5410b @certik certik committed Nov 16, 2012
Showing with 18 additions and 2 deletions.
  1. +10 −2 numpy/core/src/multiarray/lowlevel_strided_loops.c.src
  2. +8 −0 numpy/core/tests/test_regression.py
View
12 numpy/core/src/multiarray/lowlevel_strided_loops.c.src
@@ -811,9 +811,17 @@ static void
dst_value[0] = _CONVERT_FN(src_value[0]);
dst_value[1] = _CONVERT_FN(src_value[1]);
# elif !@aligned@
- dst_value = _CONVERT_FN(src_value[0]);
+# if @is_bool2@
+ 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 @is_bool2@
+ *(_TYPE2 *)dst = _CONVERT_FN(src_value[0]) || _CONVERT_FN(src_value[1]);
+# else
+ *(_TYPE2 *)dst = _CONVERT_FN(src_value[0]);
+# endif
# endif
#else
# if @is_complex2@
View
8 numpy/core/tests/test_regression.py
@@ -1459,6 +1459,14 @@ def test_complex_scalar_complex_cast(self):
x = tp(1+2j)
assert_equal(complex(x), 1+2j)
+ def test_complex_boolean_cast(self):
+ """Ticket #2218"""
+ for tp in [np.csingle, np.cdouble, np.clongdouble]:
+ x = np.array([0, 0+0.5j, 0.5+0j], dtype=tp)
+ assert_equal(x.astype(bool), np.array([0, 1, 1], dtype=bool))
+ assert_(np.any(x))
+ assert_(np.all(x[1:]))
+
def test_uint_int_conversion(self):
x = 2**64 - 1
assert_equal(int(np.uint64(x)), x)

0 comments on commit 3a52aa0

Please sign in to comment.