Skip to content

Commit 240c041

Browse files
3d calculation speedups
_to_unmasked_float_array updates Linting and tweaks mean zsort small perf gain linting Fix tests Linting and tweaks mean zsort small perf gain linting Fix tests Update lib/matplotlib/collections.py Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com> remove Path __slots__ Code review suggestions
1 parent bcca610 commit 240c041

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

lib/matplotlib/cbook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,9 @@ def _to_unmasked_float_array(x):
13401340
values are converted to nans.
13411341
"""
13421342
if hasattr(x, 'mask'):
1343-
return np.ma.asarray(x, float).filled(np.nan)
1343+
return np.ma.asanyarray(x, float).filled(np.nan)
13441344
else:
1345-
return np.asarray(x, float)
1345+
return np.asanyarray(x, float)
13461346

13471347

13481348
def _check_1d(x):

lib/matplotlib/collections.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,15 +1242,14 @@ def set_verts(self, verts, closed=True):
12421242
return
12431243

12441244
# Fast path for arrays
1245-
if isinstance(verts, np.ndarray) and len(verts.shape) == 3:
1245+
if isinstance(verts, np.ndarray) and len(verts.shape) == 3 and verts.size:
12461246
verts_pad = np.concatenate((verts, verts[:, :1]), axis=1)
1247-
# Creating the codes once is much faster than having Path do it
1248-
# separately each time by passing closed=True.
1249-
example_path = mpath.Path(verts_pad[0], closed=True)
1250-
# Looking up the values once speeds up the iteration a bit
1247+
# It's faster to create the codes and internal flags once in a
1248+
# template path and reuse them.
1249+
template_path = mpath.Path(verts_pad[0], closed=True)
1250+
codes = template_path.codes
12511251
_make_path = mpath.Path._fast_from_codes_and_verts
1252-
codes = example_path.codes
1253-
self._paths = [_make_path(xy, codes, internals_from=example_path)
1252+
self._paths = [_make_path(xy, codes, internals_from=template_path)
12541253
for xy in verts_pad]
12551254
return
12561255

lib/matplotlib/path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class Path:
7676
made up front in the constructor that will not change when the
7777
data changes.
7878
"""
79-
8079
code_type = np.uint8
8180

8281
# Path codes

lib/matplotlib/tests/test_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ def test_transformed_path():
988988
atol=1e-15)
989989

990990
# Changing the path does not change the result (it's cached).
991-
path.points = [(0, 0)] * 4
991+
path._vertices = [(0, 0)] * 4
992992
assert_allclose(trans_path.get_fully_transformed_path().vertices,
993993
[(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)],
994994
atol=1e-15)

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ def _zalpha(colors, zs):
13671367
# Should really normalize against the viewing depth.
13681368
if len(colors) == 0 or len(zs) == 0:
13691369
return np.zeros((0, 4))
1370-
norm = Normalize(min(zs), max(zs))
1370+
norm = Normalize(np.min(zs), np.max(zs))
13711371
sats = 1 - norm(zs) * 0.7
13721372
rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4))
13731373
return np.column_stack([rgba[:, :3], rgba[:, 3] * sats])

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ def _proj_transform_vectors(vecs, M):
164164

165165
def _proj_transform_vec_clip(vec, M, focal_length):
166166
vecw = np.dot(M, vec.data)
167-
w = vecw[3]
168-
txs, tys, tzs = vecw[0] / w, vecw[1] / w, vecw[2] / w
167+
txs, tys, tzs = vecw[0:3] / vecw[3]
169168
if np.isinf(focal_length): # don't clip orthographic projection
170169
tis = np.ones(txs.shape, dtype=bool)
171170
else:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy