Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc5a64d2

Browse files
committed
Deprecate proj3d.mod.
Having a function named mod that doesn't do % but computes the norm of avector 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 parent0fec7f1 commitc5a64d2

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
``mpl_toolkits.mplot3d.proj3d.mod`` is deprecated; use `numpy.linalg.norm`
5+
instead.

‎lib/matplotlib/quiver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,10 @@ def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
985985
mag=half* (mag/half+0.5).astype(int)
986986

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

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

993993
half_flag=mag>=half
994994
empty_flag=~(half_flag| (num_flags>0)| (num_barb>0))

‎lib/matplotlib/tri/triinterpolate.py

Lines 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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ def get_proj(self):
10301030

10311031
self.eye=E
10321032
self.vvec=R-E
1033-
self.vvec=self.vvec/proj3d.mod(self.vvec)
1033+
self.vvec=self.vvec/np.linalg.norm(self.vvec)
10341034

10351035
ifabs(relev)>np.pi/2:
10361036
# upside down
@@ -1768,9 +1768,9 @@ def _shade_colors(self, color, normals, lightsource=None):
17681768
# chosen for backwards-compatibility
17691769
lightsource=LightSource(azdeg=225,altdeg=19.4712)
17701770

1771-
shade=np.array([np.dot(n/proj3d.mod(n),lightsource.direction)
1772-
ifproj3d.mod(n)elsenp.nan
1773-
forninnormals])
1771+
withnp.errstate(invalid="ignore"):
1772+
shade= ((normals/np.linalg.norm(normals,axis=1,keepdims=True))
1773+
@lightsource.direction)
17741774
mask=~np.isnan(shade)
17751775

17761776
ifmask.any():

‎lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# 3dproj.py
2-
#
31
"""
42
Various transforms used for by the 3D code
53
"""
4+
65
importnumpyasnp
76
importnumpy.linalgaslinalg
87

8+
frommatplotlibimportcbook
9+
910

1011
defline2d(p0,p1):
1112
"""
@@ -62,6 +63,7 @@ def line2d_seg_dist(p1, p2, p0):
6263
returnd
6364

6465

66+
@cbook.deprecated("3.1",alternative="np.linalg.norm")
6567
defmod(v):
6668
"""3d vector length"""
6769
returnnp.sqrt(v[0]**2+v[1]**2+v[2]**2)
@@ -80,9 +82,9 @@ def world_transformation(xmin, xmax,
8082
defview_transformation(E,R,V):
8183
n= (E-R)
8284
## new
83-
# n /=mod(n)
85+
# n /=np.linalg.norm(n)
8486
# u = np.cross(V,n)
85-
# u /=mod(u)
87+
# u /=np.linalg.norm(u)
8688
# v = np.cross(n,u)
8789
# Mr = np.diag([1.]*4)
8890
# Mt = np.diag([1.]*4)
@@ -91,9 +93,9 @@ def view_transformation(E, R, V):
9193
## end new
9294

9395
## old
94-
n=n/mod(n)
96+
n=n/np.linalg.norm(n)
9597
u=np.cross(V,n)
96-
u=u/mod(u)
98+
u=u/np.linalg.norm(u)
9799
v=np.cross(n,u)
98100
Mr= [[u[0],u[1],u[2],0],
99101
[v[0],v[1],v[2],0],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp