Skip to content

Commit

Permalink
Optimized batch norm evaluation. Speedup on tangent evaluation x30
Browse files Browse the repository at this point in the history
  • Loading branch information
VikingScientist authored and TheBB committed May 31, 2021
1 parent 9827d63 commit 9d0225e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions splipy/Curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def binormal(self, t, above=True):
return result / np.linalg.norm(result)

# normalize
magnitude = np.apply_along_axis(np.linalg.norm, 1, result)
magnitude = np.linalg.norm(result, axis=1)
magnitude = magnitude.reshape(-1,1)

return result / magnitude
Expand Down Expand Up @@ -224,9 +224,9 @@ def curvature(self, t, above=True):
magnitude = np.abs(w)
else:
# for 3D, it is vectors
magnitude = np.apply_along_axis(np.linalg.norm, -1, w)
magnitude = np.linalg.norm( w, axis= -1)

speed = np.apply_along_axis(np.linalg.norm, -1, v)
speed = np.linalg.norm( v, axis=-1)

return magnitude / np.power(speed,3)

Expand Down Expand Up @@ -261,7 +261,7 @@ def torsion(self, t, above=True):
magnitude = np.linalg.norm(w)
nominator = np.dot(w, a)
else: # multiple evaluation points
magnitude = np.apply_along_axis(np.linalg.norm, -1, w)
magnitude = np.linalg.norm( w, axis=-1)
nominator = np.array([np.dot(w1,da1) for (w1,da1) in zip(w, da)])

return nominator / np.power(magnitude, 2)
Expand Down
4 changes: 2 additions & 2 deletions splipy/SplineObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def tangent(self, *params, **kwargs):
if len(v.shape)==1:
speed = np.linalg.norm(v)
else:
speed = np.apply_along_axis(np.linalg.norm, -1, v)
speed = np.linalg.norm( v, axis=-1)
speed = np.reshape(speed, speed.shape +(1,))
# store in result tuple
result += (v/speed,)
Expand All @@ -354,7 +354,7 @@ def tangent(self, *params, **kwargs):
if len(v.shape)==1:
speed = np.linalg.norm(v)
else:
speed = np.apply_along_axis(np.linalg.norm, -1, v)
speed = np.linalg.norm( v, axis=-1)
speed = np.reshape(speed, speed.shape +(1,))

return v / speed
Expand Down
2 changes: 1 addition & 1 deletion splipy/Surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def normal(self, u, v, above=(True,True), tensor=True):
# normalize output
if len(du.shape) == 1:
return normals / np.linalg.norm(normals)
magnitude = np.apply_along_axis(np.linalg.norm, -1, normals)
magnitude = np.linalg.norm( normals, axis=-1)
magnitude = magnitude.reshape(magnitude.shape + (1,))
return normals / magnitude
else:
Expand Down

0 comments on commit 9d0225e

Please sign in to comment.