diff options
author | Jaime Fernandez <jaimefrio@google.com> | 2016-03-28 01:23:42 +0200 |
---|---|---|
committer | Jaime Fernandez <jaimefrio@google.com> | 2016-03-28 01:48:08 +0200 |
commit | 24b2a2d36a7e8356310cd16dbe60abd9d0e682dc (patch) | |
tree | a494cfc40364f889ef39277b11b739170c4d10a2 /numpy/core/tests | |
parent | 54c1ff8d0a01dff38532ecd75c81ef229e05c17b (diff) | |
download | numpy-24b2a2d36a7e8356310cd16dbe60abd9d0e682dc.tar.gz |
BUG: shift operator cycles, fixes #2449
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_scalarmath.py | 32 |
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() |