diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2019-09-05 11:25:19 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-05 11:25:19 -0600 |
commit | 4da9256cd8e0cfc82d27530526857bc70a6c2309 (patch) | |
tree | 6aa24a03fc2a2acd164158fd9cd3e87f5e8bdc7c /numpy/lib/tests/test_arraypad.py | |
parent | 3dccd841476d26b5807156b904b55c04c6a3d370 (diff) | |
parent | 5c55d2b3d2946c1d581dcea252d6cea0e1602217 (diff) | |
download | numpy-4da9256cd8e0cfc82d27530526857bc70a6c2309.tar.gz |
Merge pull request #14209 from lagru/fix-linear-ramp
BUG: Fix uint-overflow if padding with linear_ramp and negative gain
Diffstat (limited to 'numpy/lib/tests/test_arraypad.py')
-rw-r--r-- | numpy/lib/tests/test_arraypad.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index b6dd3b31c..65593dd29 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -2,7 +2,6 @@ """ from __future__ import division, absolute_import, print_function -from itertools import chain import pytest @@ -11,6 +10,12 @@ from numpy.testing import assert_array_equal, assert_allclose, assert_equal from numpy.lib.arraypad import _as_pairs +_numeric_dtypes = ( + np.sctypes["uint"] + + np.sctypes["int"] + + np.sctypes["float"] + + np.sctypes["complex"] +) _all_modes = { 'constant': {'constant_values': 0}, 'edge': {}, @@ -738,6 +743,24 @@ class TestLinearRamp(object): assert_equal(a[0, :], 0.) assert_equal(a[-1, :], 0.) + @pytest.mark.parametrize("dtype", _numeric_dtypes) + def test_negative_difference(self, dtype): + """ + Check correct behavior of unsigned dtypes if there is a negative + difference between the edge to pad and `end_values`. Check both cases + to be independent of implementation. Test behavior for all other dtypes + in case dtype casting interferes with complex dtypes. See gh-14191. + """ + x = np.array([3], dtype=dtype) + result = np.pad(x, 3, mode="linear_ramp", end_values=0) + expected = np.array([0, 1, 2, 3, 2, 1, 0], dtype=dtype) + assert_equal(result, expected) + + x = np.array([0], dtype=dtype) + result = np.pad(x, 3, mode="linear_ramp", end_values=3) + expected = np.array([3, 2, 1, 0, 1, 2, 3], dtype=dtype) + assert_equal(result, expected) + class TestReflect(object): def test_check_simple(self): @@ -1330,13 +1353,7 @@ def test_memory_layout_persistence(mode): assert np.pad(x, 5, mode).flags["F_CONTIGUOUS"] -@pytest.mark.parametrize("dtype", chain( - # Skip "other" dtypes as they are not supported by all modes - np.sctypes["int"], - np.sctypes["uint"], - np.sctypes["float"], - np.sctypes["complex"] -)) +@pytest.mark.parametrize("dtype", _numeric_dtypes) @pytest.mark.parametrize("mode", _all_modes.keys()) def test_dtype_persistence(dtype, mode): arr = np.zeros((3, 2, 1), dtype=dtype) |