Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Backport #477 #2741

Merged
merged 2 commits into from

2 participants

@certik
Owner

No description provided.

@certik
Owner

Tests pass and this was already reviewed in master -> merging.

@certik certik merged commit 3a52aa0 into numpy:maintenance/1.7.x

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2012
  1. @seberg @certik

    BUG: Fix complex to bool conversion in lowlevel_strided_loops

    seberg authored certik committed
    Closes "Ticket 2218".
  2. @seberg @certik

    TST: Complex to bool conversion (Ticket 2218)

    seberg authored certik committed
This page is out of date. Refresh to see the latest.
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)
Something went wrong with that request. Please try again.