FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Optimize Poly3DCollection.get_vector for ndarray arguments by apaszke · Pull Request #16680 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
27 changes: 21 additions & 6 deletions lib/mpl_toolkits/mplot3d/art3d.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,28 @@ def set_zsort(self, zsort):
def get_vector(self, segments3d):
"""Optimize points for projection."""
if len(segments3d):
xs, ys, zs = np.row_stack(segments3d).T
# row_stack would split and re-concatenate all rows, and so it's
# much faster to reshape if the data is already in the right format
if isinstance(segments3d, np.ndarray):
segments3d_t = segments3d.reshape(-1, segments3d.shape[-1]).T
else:
segments3d_t = np.row_stack(segments3d).T
ones = np.broadcast_to(np.ones((1,), dtype=segments3d_t.dtype),
shape=(1, segments3d_t.shape[-1],))
self._vec = np.concatenate((segments3d_t, ones), axis=0)
else: # row_stack can't stack zero arrays.
xs, ys, zs = [], [], []
ones = np.ones(len(xs))
self._vec = np.array([xs, ys, zs, ones])

indices = [0, *np.cumsum([len(segment) for segment in segments3d])]
self._vec = np.ndarray(shape=(0, 4))

# range is much faster than np.cumsum with a list argument, so we
# use it whenever the faces have a constant number of vertices.
if isinstance(segments3d, np.ndarray):
face_vertices = segments3d.shape[1]
segment_ends = range(face_vertices,
face_vertices * len(segments3d) + 1,
face_vertices)
else:
segment_ends = np.cumsum([len(segment) for segment in segments3d])
indices = [0, *segment_ends]
self._segslices = [*map(slice, indices[:-1], indices[1:])]

def set_verts(self, verts, closed=True):
Expand Down

Back | FazBrowse Home | New Git URL