Fix issue easy to fix, hard to find.
@@ -772,8 +772,11 @@ def optimize_layout(
dist_squared = rdist(current, other)
+ if dist_squared > 0.0:
grad_coeff = -2.0 * a * b * pow(dist_squared, b - 1.0)
grad_coeff /= a * pow(dist_squared, b) + 1.0
+ else:
+ grad_coeff = 0.0
for d in range(dim):
grad_d = clip(grad_coeff * (current[d] - other[d]))
@@ -800,9 +803,6 @@ def optimize_layout(
a * pow(dist_squared, b) + 1
)
- if not np.isfinite(grad_coeff):
- grad_coeff = 4.0
-
for d in range(dim):
grad_d = clip(grad_coeff * (current[d] - other[d]))
current[d] += grad_d * alpha
