Skip to content

Commit 6af6818

Browse files
committed
Review comments
1 parent 8e57a9a commit 6af6818

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

lib/matplotlib/cbook/__init__.py

+40-6
Original file line numberDiff line numberDiff line change
@@ -2003,18 +2003,46 @@ def _array_perimeter(arr):
20032003

20042004

20052005
def _unfold(arr, axis, size, step):
2006-
"""Append an extra dimension containing sliding windows along **axis**.
2006+
"""
2007+
Append an extra dimension containing sliding windows along *axis*.
20072008
2008-
All windows are of size **size** and begin with every **step** elements.
2009+
All windows are of size *size* and begin with every *step* elements.
20092010
20102011
Parameters
20112012
----------
20122013
arr : ndarray, shape (N_1, ..., N_k)
20132014
The input array
2015+
axis : int
2016+
Axis along which the windows are extracted
2017+
size : int
2018+
Size of the windows
2019+
step : int
2020+
Stride between first elements of subsequent windows.
20142021
20152022
Returns
20162023
-------
20172024
windows : ndarray, shape (N_1, ..., 1 + (N_axis-size)/step, ..., N_k, size)
2025+
2026+
Examples
2027+
--------
2028+
>>> i, j = np.ogrid[:3,:7]
2029+
>>> a = i*10 + j
2030+
>>> a
2031+
array([[ 0, 1, 2, 3, 4, 5, 6],
2032+
[10, 11, 12, 13, 14, 15, 16],
2033+
[20, 21, 22, 23, 24, 25, 26]])
2034+
>>> _unfold(a, axis=1, size=3, step=2)
2035+
array([[[ 0, 1, 2],
2036+
[ 2, 3, 4],
2037+
[ 4, 5, 6]],
2038+
2039+
[[10, 11, 12],
2040+
[12, 13, 14],
2041+
[14, 15, 16]],
2042+
2043+
[[20, 21, 22],
2044+
[22, 23, 24],
2045+
[24, 25, 26]]])
20182046
"""
20192047
new_shape = [*arr.shape, size]
20202048
new_strides = [*arr.strides, arr.strides[axis]]
@@ -2027,19 +2055,25 @@ def _unfold(arr, axis, size, step):
20272055

20282056

20292057
def _array_patch_perimeters(x, rstride, cstride):
2030-
"""Extract perimeters of patches from **arr**.
2058+
"""
2059+
Extract perimeters of patches from *arr*.
20312060
2032-
Extracted patches are of size (**rstride** + 1) x (**cstride** + 1) and
2061+
Extracted patches are of size (*rstride* + 1) x (*cstride* + 1) and
20332062
share perimeters with their neighbors. The ordering of the vertices matches
20342063
that returned by ``_array_perimeter``.
20352064
20362065
Parameters
20372066
----------
2038-
arr : ndarray, shape (N, M)
2067+
x : ndarray, shape (N, M)
2068+
Input array
2069+
rstride : int
2070+
Vertical (row) stride between corresponding elements of each patch
2071+
cstride : int
2072+
Horizontal (column) stride between corresponding elements of each patch
20392073
20402074
Returns
20412075
-------
2042-
patches : ndarray, shape (N / rstride * M / cstride, 2(rstride + cstride))
2076+
patches : ndarray, shape (N/rstride * M/cstride, 2 * (rstride + cstride))
20432077
"""
20442078
assert rstride > 0 and cstride > 0
20452079
assert (x.shape[0] - 1) % rstride == 0

lib/matplotlib/tests/test_cbook.py

+2
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ def test_warn_external(recwarn):
594594

595595

596596
def test_array_patch_perimeters():
597+
# This compares the old implementation as a reference for the
598+
# vectorized one.
597599
def check(x, rstride, cstride):
598600
rows, cols = x.shape
599601
row_inds = [*range(0, rows-1, rstride), rows-1]

0 commit comments

Comments
 (0)