8000 Micro-optimize skew(). · matplotlib/matplotlib@85fa0bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 85fa0bb

Browse files
committed
Micro-optimize skew().
Similarly to what was recently done for rotate().
1 parent d9ef0a7 commit 85fa0bb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/matplotlib/transforms.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,11 +2094,18 @@ def skew(self, xShear, yShear):
20942094
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
20952095
and :meth:`scale`.
20962096
"""
2097-
rotX = math.tan(xShear)
2098-
rotY = math.tan(yShear)
2099-
skew_mtx = np.array(
2100-
[[1.0, rotX, 0.0], [rotY, 1.0, 0.0], [0.0, 0.0, 1.0]], float)
2101-
self._mtx = np.dot(skew_mtx, self._mtx)
2097+
rx = math.tan(xShear)
2098+
ry = math.tan(yShear)
2099+
mtx = self._mtx
2100+
# Operating and assigning one scalar at a time is much faster.
2101+
(xx, xy, x0), (yx, yy, y0), _ = mtx.tolist()
2102+
# mtx = [[1 rx 0], [ry 1 0], [0 0 1]] * mtx
2103+
mtx[0, 0] += rx * yx
2104+
mtx[0, 1] += rx * yy
2105+
mtx[0, 2] += rx * y0
2106+
mtx[1, 0] += ry * xx
2107+
mtx[1, 1] += ry * xy
2108+
mtx[1, 2] += ry * x0
21022109
self.invalidate()
21032110
return self
21042111

0 commit comments

Comments
 (0)
0