Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid vstack() when possible.
In transforms.py, array() is faster -- the changes speeds up the
proposed precision-sensitive version of format_data_short by ~10%
(essentially because we get to skip the calls to np.atleast_2d in
vstack).

Also replace a vstack() call by a concatenate() in path.py, while we're
at it.
  • Loading branch information
anntzer committed Mar 16, 2020
commit 38294171eb4580e713087a3ee0a40ec0ec4b1a94
9 changes: 2 additions & 7 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,8 @@ def make_compound_path(cls, *args):
if not args:
return Path(np.empty([0, 2], dtype=np.float32))

lengths = [len(x) for x in args]
total_length = sum(lengths)

vertices = np.vstack([x.vertices for x in args])
vertices.reshape((total_length, 2))

codes = np.empty(total_length, dtype=cls.code_type)
vertices = np.concatenate([x.vertices for x in args])
codes = np.empty(len(vertices), dtype=cls.code_type)
i = 0
for path in args:
if path.codes is None:
Expand Down
14 changes: 6 additions & 8 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2176,10 +2176,9 @@ def get_affine(self):
else:
x_mtx = self._x.get_affine().get_matrix()
y_mtx = self._y.get_affine().get_matrix()
# This works because we already know the transforms are
# separable, though normally one would want to set b and
# c to zero.
mtx = np.vstack((x_mtx[0], y_mtx[1], [0.0, 0.0, 1.0]))
# We already know the transforms are separable, so we can skip
# setting b and c to zero.
mtx = np.array([x_mtx[0], y_mtx[1], [0.0, 0.0, 1.0]])
self._affine = Affine2D(mtx)
self._invalid = 0
return self._affine
Expand Down Expand Up @@ -2229,10 +2228,9 @@ def get_matrix(self):
else:
x_mtx = self._x.get_matrix()
y_mtx = self._y.get_matrix()
# This works because we already know the transforms are
# separable, though normally one would want to set b and
# c to zero.
self._mtx = np.vstack((x_mtx[0], y_mtx[1], [0.0, 0.0, 1.0]))
# We already know the transforms are separable, so we can skip
# setting b and c to zero.
self._mtx = np.array([x_mtx[0], y_mtx[1], [0.0, 0.0, 1.0]])
self._inverted = None
self._invalid = 0
return self._mtx
Expand Down