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

Skip to content

Commit 6c4fd69

Browse files
authored
Merge pull request #10327 from anntzer/fasttransform
Don't call np.identity() in transforms.
2 parents 6d5b1c4 + 6afd28c commit 6c4fd69

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/matplotlib/transforms.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,8 @@ def __init__(self, matrix=None, **kwargs):
19281928
"""
19291929
Affine2DBase.__init__(self, **kwargs)
19301930
if matrix is None:
1931-
matrix = np.identity(3)
1931+
# A bit faster than np.identity(3).
1932+
matrix = IdentityTransform._mtx.copy()
19321933
self._mtx = matrix
19331934
self._invalid = 0
19341935

@@ -1999,13 +2000,14 @@ def identity():
19992000
Unless this transform will be mutated later on, consider using
20002001
the faster :class:`IdentityTransform` class instead.
20012002
"""
2002-
return Affine2D(np.identity(3))
2003+
return Affine2D()
20032004

20042005
def clear(self):
20052006
"""
20062007
Reset the underlying matrix to the identity transform.
20072008
"""
2008-
self._mtx = np.identity(3)
2009+
# A bit faster than np.identity(3).
2010+
self._mtx = IdentityTransform._mtx.copy()
20092011
self.invalidate()
20102012
return self
20112013

0 commit comments

Comments
 (0)