Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 114209a

Browse filesBrowse files
committed
Deprecate proj3d.mod.
Having a function named mod that doesn't do % but computes the norm of a vector is just a good way to trip the reader (yes, I know about the term "modulus of a vector", but still). Also vectorize a normals calculation. Also we can use % instead of np.mod elsewhere.
1 parent b6e8c19 commit 114209a
Copy full SHA for 114209a

File tree

Expand file treeCollapse file tree

4 files changed

+14
-20
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+14
-20
lines changed

‎lib/matplotlib/quiver.py

Copy file name to clipboardExpand all lines: lib/matplotlib/quiver.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,10 @@ def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
983983
mag = half * (mag / half + 0.5).astype(int)
984984

985985
num_flags = np.floor(mag / flag).astype(int)
986-
mag = np.mod(mag, flag)
986+
mag = mag % flag
987987

988988
num_barb = np.floor(mag / full).astype(int)
989-
mag = np.mod(mag, full)
989+
mag = mag % full
990990

991991
half_flag = mag >= half
992992
empty_flag = ~(half_flag | (num_flags > 0) | (num_barb > 0))

‎lib/matplotlib/tri/triinterpolate.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tri/triinterpolate.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ def compute_geom_weights(self):
11351135
alpha2 = np.arctan2(p2[:, 1]-p0[:, 1], p2[:, 0]-p0[:, 0])
11361136
# In the below formula we could take modulo 2. but
11371137
# modulo 1. is safer regarding round-off errors (flat triangles).
1138-
angle = np.abs(np.mod((alpha2-alpha1) / np.pi, 1.))
1138+
angle = np.abs(((alpha2-alpha1) / np.pi) % 1)
11391139
# Weight proportional to angle up np.pi/2; null weight for
11401140
# degenerated cases 0 and np.pi (note that `angle` is normalized
11411141
# by np.pi).

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ def get_proj(self):
10271027

10281028
self.eye = E
10291029
self.vvec = R - E
1030-
self.vvec = self.vvec / proj3d._mod(self.vvec)
1030+
self.vvec = self.vvec / np.linalg.norm(self.vvec)
10311031

10321032
if abs(relev) > np.pi/2:
10331033
# upside down
@@ -1762,9 +1762,9 @@ def _shade_colors(self, color, normals, lightsource=None):
17621762
# chosen for backwards-compatibility
17631763
lightsource = LightSource(azdeg=225, altdeg=19.4712)
17641764

1765-
shade = np.array([np.dot(n / proj3d._mod(n), lightsource.direction)
1766-
if proj3d._mod(n) else np.nan
1767-
for n in normals])
1765+
with np.errstate(invalid="ignore"):
1766+
shade = ((normals / np.linalg.norm(normals, axis=1, keepdims=True))
1767+
@ lightsource.direction)
17681768
mask = ~np.isnan(shade)
17691769

17701770
if mask.any():

‎lib/mpl_toolkits/mplot3d/proj3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/proj3d.py
+7-13Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# 3dproj.py
2-
#
31
"""
42
Various transforms used for by the 3D code
53
"""
4+
65
import numpy as np
76
import numpy.linalg as linalg
87

@@ -79,15 +78,10 @@ def line2d_seg_dist(p1, p2, p0):
7978
return _line2d_seg_dist(p1, p2, p0)
8079

8180

82-
def _mod(v):
83-
"""3d vector length"""
84-
return np.sqrt(v[0]**2+v[1]**2+v[2]**2)
85-
86-
87-
@cbook.deprecated("3.1")
81+
@cbook.deprecated("3.1", alternative="np.linalg.norm")
8882
def mod(v):
8983
"""3d vector length"""
90-
return _mod(v)
84+
return np.sqrt(v[0]**2+v[1]**2+v[2]**2)
9185

9286

9387
def world_transformation(xmin, xmax,
@@ -103,9 +97,9 @@ def world_transformation(xmin, xmax,
10397
def view_transformation(E, R, V):
10498
n = (E - R)
10599
## new
106-
# n /= mod(n)
100+
# n /= np.linalg.norm(n)
107101
# u = np.cross(V,n)
108-
# u /= mod(u)
102+
# u /= np.linalg.norm(u)
109103
# v = np.cross(n,u)
110104
# Mr = np.diag([1.]*4)
111105
# Mt = np.diag([1.]*4)
@@ -114,9 +108,9 @@ def view_transformation(E, R, V):
114108
## end new
115109

116110
## old
117-
n = n / _mod(n)
111+
n = n / np.linalg.norm(n)
118112
u = np.cross(V, n)
119-
u = u / _mod(u)
113+
u = u / np.linalg.norm(u)
120114
v = np.cross(n, u)
121115
Mr = [[u[0], u[1], u[2], 0],
122116
[v[0], v[1], v[2], 0],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.