summaryrefslogtreecommitdiff
path: root/numpy/core/tests
diff options
context:
space:
mode:
authorJaime Fernandez <jaimefrio@google.com>2016-03-28 01:23:42 +0200
committerJaime Fernandez <jaimefrio@google.com>2016-03-28 01:48:08 +0200
commit24b2a2d36a7e8356310cd16dbe60abd9d0e682dc (patch)
treea494cfc40364f889ef39277b11b739170c4d10a2 /numpy/core/tests
parent54c1ff8d0a01dff38532ecd75c81ef229e05c17b (diff)
downloadnumpy-24b2a2d36a7e8356310cd16dbe60abd9d0e682dc.tar.gz
BUG: shift operator cycles, fixes #2449
Diffstat (limited to 'numpy/core/tests')
-rw-r--r--numpy/core/tests/test_scalarmath.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index b8f4388b1..52c9d3bc6 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -525,5 +525,37 @@ class TestAbs(TestCase):
self._test_abs_func(np.abs)
+class TestBitShifts(TestCase):
+
+ def test_left_shift(self):
+ # gh-2449
+ for dt in np.typecodes['AllInteger']:
+ arr = np.array([5, -5], dtype=dt)
+ scl_pos, scl_neg = arr
+ for shift in np.array([arr.dtype.itemsize * 8], dtype=dt):
+ res_pos = scl_pos << shift
+ res_neg = scl_neg << shift
+ assert_equal(res_pos, 0)
+ assert_equal(res_neg, 0)
+ # Result on scalars should be the same as on arrays
+ assert_array_equal(arr << shift, [res_pos, res_neg])
+
+ def test_right_shift(self):
+ # gh-2449
+ for dt in np.typecodes['AllInteger']:
+ arr = np.array([5, -5], dtype=dt)
+ scl_pos, scl_neg = arr
+ for shift in np.array([arr.dtype.itemsize * 8], dtype=dt):
+ res_pos = scl_pos >> shift
+ res_neg = scl_neg >> shift
+ assert_equal(res_pos, 0)
+ if dt in np.typecodes['UnsignedInteger']:
+ assert_equal(res_neg, 0)
+ else:
+ assert_equal(res_neg, -1)
+ # Result on scalars should be the same as on arrays
+ assert_array_equal(arr >> shift, [res_pos, res_neg], dt)
+
+
if __name__ == "__main__":
run_module_suite()