[math] Improved error message invalid dot products
@@ -1384,6 +1384,7 @@ def dot(x: Tensor,
backend = choose_backend(x_native, y_native)
remaining_shape_x = x.shape.without(x_dims)
remaining_shape_y = y.shape.without(y_dims)
+ assert x_dims.volume == y_dims.volume, f"Failed to reduce {x_dims} against {y_dims} in dot product of {x.shape} and {y.shape}. Sizes do not match."
if remaining_shape_y.only(remaining_shape_x).is_empty: # no shared batch dimensions -> tensordot
result_native = backend.tensordot(x_native, x.shape.indices(x_dims), y_native, y.shape.indices(y_dims))
result_shape = concat_shapes(remaining_shape_x, remaining_shape_y)
