diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2019-09-22 17:42:14 -0700 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2019-09-22 17:45:31 -0700 |
commit | 7aee2ef21ef25a81f75392e0dfffd64455c1e6b5 (patch) | |
tree | e30e802c54228111efc266086f6bfdaca6d8dfc1 /numpy/lib/tests/test_index_tricks.py | |
parent | c8fdb4491b527fed144f7a88f3248a809f8ede4d (diff) | |
download | numpy-7aee2ef21ef25a81f75392e0dfffd64455c1e6b5.tar.gz |
BUG: Add missing check for 0-sized array in ravel_multi_index
In wrap and clip modes ravel_multi_index crashes or gave
invalid results if input arrays were empty but the shape not.
Diffstat (limited to 'numpy/lib/tests/test_index_tricks.py')
-rw-r--r-- | numpy/lib/tests/test_index_tricks.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index a5cdda074..dbe445c2c 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -175,6 +175,24 @@ class TestRavelUnravelIndex(object): assert_raises_regex( ValueError, "out of bounds", np.unravel_index, [1], ()) + @pytest.mark.parametrize("mode", ["clip", "wrap", "raise"]) + def test_empty_array_ravel(self, mode): + res = np.ravel_multi_index( + np.zeros((3, 0), dtype=np.intp), (2, 1, 0), mode=mode) + assert(res.shape == (0,)) + + with assert_raises(ValueError): + np.ravel_multi_index( + np.zeros((3, 1), dtype=np.intp), (2, 1, 0), mode=mode) + + def test_empty_array_unravel(self): + res = np.unravel_index(np.zeros(0, dtype=np.intp), (2, 1, 0)) + # res is a tuple of three empty arrays + assert(len(res) == 3) + assert(all(a.shape == (0,) for a in res)) + + with assert_raises(ValueError): + np.unravel_index([1], (2, 1, 0)) class TestGrid(object): def test_basic(self): |