Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50e2157

Browse files
committed
Review comments
1 parent 74ad0c2 commit 50e2157

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,8 @@ def _array_patch_perimeters(x, rstride, cstride):
20302030
"""Extract perimeters of patches from **arr**.
20312031
20322032
Extracted patches are of size (**rstride** + 1) x (**cstride** + 1) and
2033-
share perimeters with their neighbors.
2033+
share perimeters with their neighbors. The ordering of the vertices matches
2034+
that returned by ``_array_perimeter``.
20342035
20352036
Parameters
20362037
----------
@@ -2044,11 +2045,28 @@ def _array_patch_perimeters(x, rstride, cstride):
20442045
assert rstride > 0 and cstride > 0
20452046
assert (x.shape[0] - 1) % rstride == 0
20462047
assert (x.shape[1] - 1) % cstride == 0
2047-
upper = _unfold(x[:-1:rstride, :-1], 1, cstride, cstride)
2048-
lower = _unfold(x[rstride::rstride, 1:], 1, cstride, cstride)[..., ::-1]
2048+
# We build up each perimeter from four half-open intervals. Here is an
2049+
# illustrated explanation for rstride == cstride == 3
2050+
#
2051+
# T T T R
2052+
# L R
2053+
# L R
2054+
# L B B B
2055+
#
2056+
# where T means that this element will be in the top array, R for right,
2057+
# B for bottom and L for left. Each of the arrays below has a shape of:
2058+
#
2059+
# (number of perimeters that can be extracted vertically,
2060+
# number of perimeters that can be extracted horizontally,
2061+
# cstride for top and bottom and rstride for left and right)
2062+
#
2063+
# Note that _unfold doesn't incur any memory copies, so the only costly
2064+
# operation here is the np.concatenate.
2065+
top = _unfold(x[:-1:rstride, :-1], 1, cstride, cstride)
2066+
bottom = _unfold(x[rstride::rstride, 1:], 1, cstride, cstride)[..., ::-1]
20492067
right = _unfold(x[:-1, cstride::cstride], 0, rstride, rstride)
20502068
left = _unfold(x[1:, :-1:cstride], 0, rstride, rstride)[..., ::-1]
2051-
return (np.concatenate((upper, right, lower, left), axis=2)
2069+
return (np.concatenate((top, right, bottom, left), axis=2)
20522070
.reshape(-1, 2 * (rstride + cstride)))
20532071

20542072

lib/matplotlib/tests/test_cbook.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,7 @@ def check(x, rstride, cstride):
610610
x, rstride=rstride, cstride=cstride))
611611

612612
def divisors(n):
613-
for i in range(1, n // 2 + 1):
614-
if n % i == 0:
615-
yield i
616-
yield n
613+
return [i for i in range(1, n + 1) if n % i == 0]
617614

618615
for rows, cols in [(5, 5), (7, 14), (13, 9)]:
619616
x = np.arange(rows * cols).reshape(rows, cols)

0 commit comments

Comments
 (0)