Merge pull request #1650 from NilsNemitz/add_clip_scalar_function

Do not use clip_array on scalars (use clip_scalar instead)
This commit is contained in:
Ogi Moore 2021-03-22 11:16:50 -07:00 committed by GitHub
commit 69be66699a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -998,6 +998,9 @@ def solveBilinearTransform(points1, points2):
return matrix
def clip_scalar(val, vmin, vmax):
""" convenience function to avoid using np.clip for scalar values """
return vmin if val < vmin else vmax if val > vmax else val
def clip_array(arr, vmin, vmax, out=None):
# replacement for np.clip due to regression in

View File

@ -679,8 +679,8 @@ class PlotDataItem(GraphicsObject):
# workaround for slowdown from numpy deprecation issues in 1.17 to 1.20+
# x0 = np.clip(int((range.left()-x[0])/dx) - 1*ds, 0, len(x)-1)
# x1 = np.clip(int((range.right()-x[0])/dx) + 2*ds, 0, len(x)-1)
x0 = fn.clip_array(int((range.left()-x[0])/dx) - 1*ds, 0, len(x)-1)
x1 = fn.clip_array(int((range.right()-x[0])/dx) + 2*ds, 0, len(x)-1)
x0 = fn.clip_scalar(int((range.left()-x[0])/dx) - 1*ds, 0, len(x)-1)
x1 = fn.clip_scalar(int((range.right()-x[0])/dx) + 2*ds, 0, len(x)-1)
# if data has been clipped too strongly (in case of non-uniform
# spacing of x-values), refine the clipping region as required
@ -688,11 +688,11 @@ class PlotDataItem(GraphicsObject):
# best case performance: O(1)
if x[x0] > range.left():
x0 = np.searchsorted(x, range.left()) - 1*ds
x0 = fn.clip_array(x0, 0, len(x)) # workaround
x0 = fn.clip_scalar(x0, 0, len(x)) # workaround
# x0 = np.clip(x0, 0, len(x))
if x[x1] < range.right():
x1 = np.searchsorted(x, range.right()) + 2*ds
x1 = fn.clip_array(x1, 0, len(x))
x1 = fn.clip_scalar(x1, 0, len(x))
# x1 = np.clip(x1, 0, len(x))
x = x[x0:x1]
y = y[x0:x1]