"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "numpy/lib/tests/test_arraypad.py" between
numpy-1.17.1.tar.gz and numpy-1.17.2.tar.gz

About: NumPy is the fundamental package for scientific computing with Python.

test_arraypad.py  (numpy-1.17.1):test_arraypad.py  (numpy-1.17.2)
"""Tests for the array padding functions. """Tests for the array padding functions.
""" """
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from itertools import chain
import pytest import pytest
import numpy as np import numpy as np
from numpy.testing import assert_array_equal, assert_allclose, assert_equal from numpy.testing import assert_array_equal, assert_allclose, assert_equal
from numpy.lib.arraypad import _as_pairs from numpy.lib.arraypad import _as_pairs
_numeric_dtypes = (
np.sctypes["uint"]
+ np.sctypes["int"]
+ np.sctypes["float"]
+ np.sctypes["complex"]
)
_all_modes = { _all_modes = {
'constant': {'constant_values': 0}, 'constant': {'constant_values': 0},
'edge': {}, 'edge': {},
'linear_ramp': {'end_values': 0}, 'linear_ramp': {'end_values': 0},
'maximum': {'stat_length': None}, 'maximum': {'stat_length': None},
'mean': {'stat_length': None}, 'mean': {'stat_length': None},
'median': {'stat_length': None}, 'median': {'stat_length': None},
'minimum': {'stat_length': None}, 'minimum': {'stat_length': None},
'reflect': {'reflect_type': 'even'}, 'reflect': {'reflect_type': 'even'},
'symmetric': {'reflect_type': 'even'}, 'symmetric': {'reflect_type': 'even'},
skipping to change at line 712 skipping to change at line 717
assert_equal(actual, expected) assert_equal(actual, expected)
def test_end_values(self): def test_end_values(self):
"""Ensure that end values are exact.""" """Ensure that end values are exact."""
a = np.pad(np.ones(10).reshape(2, 5), (223, 123), mode="linear_ramp") a = np.pad(np.ones(10).reshape(2, 5), (223, 123), mode="linear_ramp")
assert_equal(a[:, 0], 0.) assert_equal(a[:, 0], 0.)
assert_equal(a[:, -1], 0.) assert_equal(a[:, -1], 0.)
assert_equal(a[0, :], 0.) assert_equal(a[0, :], 0.)
assert_equal(a[-1, :], 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): class TestReflect(object):
def test_check_simple(self): def test_check_simple(self):
a = np.arange(100) a = np.arange(100)
a = np.pad(a, (25, 20), 'reflect') a = np.pad(a, (25, 20), 'reflect')
b = np.array( b = np.array(
[25, 24, 23, 22, 21, 20, 19, 18, 17, 16, [25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6,
5, 4, 3, 2, 1, 5, 4, 3, 2, 1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
skipping to change at line 1288 skipping to change at line 1311
assert_equal(result[2:-3, 2:-3], arr) assert_equal(result[2:-3, 2:-3], arr)
@pytest.mark.parametrize("mode", _all_modes.keys()) @pytest.mark.parametrize("mode", _all_modes.keys())
def test_memory_layout_persistence(mode): def test_memory_layout_persistence(mode):
"""Test if C and F order is preserved for all pad modes.""" """Test if C and F order is preserved for all pad modes."""
x = np.ones((5, 10), order='C') x = np.ones((5, 10), order='C')
assert np.pad(x, 5, mode).flags["C_CONTIGUOUS"] assert np.pad(x, 5, mode).flags["C_CONTIGUOUS"]
x = np.ones((5, 10), order='F') x = np.ones((5, 10), order='F')
assert np.pad(x, 5, mode).flags["F_CONTIGUOUS"] assert np.pad(x, 5, mode).flags["F_CONTIGUOUS"]
@pytest.mark.parametrize("dtype", chain( @pytest.mark.parametrize("dtype", _numeric_dtypes)
# 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("mode", _all_modes.keys()) @pytest.mark.parametrize("mode", _all_modes.keys())
def test_dtype_persistence(dtype, mode): def test_dtype_persistence(dtype, mode):
arr = np.zeros((3, 2, 1), dtype=dtype) arr = np.zeros((3, 2, 1), dtype=dtype)
result = np.pad(arr, 1, mode=mode) result = np.pad(arr, 1, mode=mode)
assert result.dtype == dtype assert result.dtype == dtype
 End of changes. 4 change blocks. 
8 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)