Avoid division by zero in tensordot, allowing 0-length arrays
@@ -189,8 +189,9 @@ def tensordot(a, b, axes=2):
ret_shape = a.shape[sum_ndim:] + b.shape[sum_ndim:]
k = internal.prod(a.shape[:sum_ndim])
- n = a.size // k
- m = b.size // k
+ # Avoid division by zero, allowing 0-length dimensions to work
+ n = a.size // k if k != 0 else 0
+ m = b.size // k if k != 0 else 0
return core.tensordot_core(a, b, None, n, m, k, ret_shape)
