See discussion at https://discourse.julialang.org/t/efficient-trace-of-product-of-matrices/13313/12
Mwe :
julia> A = rand(4,4);
julia> B = rand(8,2);
julia> dot(A,B)
3.8210283956714974
It is debatable what should be done here, but I think the current behavior is surprising, and can easily be gotten with vec if needed. It seems more prudent to error.
As mentioned on discourse, I always understood this to be intentional, but I am having difficulty finding smoking-gun evidence that it is (at the moment, at least). Related to discussion in #25565 and #27401.
cc @ranocha @stevengj
While I strongly prefer allowing the computation of the Hilbert Schmidt scalar product via dot (and corresponding norm via norm), I cannot imagine a real application using something as dot( rand(4,4), rand(2,8) ). Thus, I think this behaviour feels like a bug.
Thanks! What, then, is your opinion on dot(rand(4,4), rand(16))? Should the dot product be allowed if one argument but not both is an AbstractVector? Or should an explicit vec be necessary around the first argument in this example?
In my opinion, dot(A::AbstractArray, B::AbstractArray) should throw an error if size(A) != size(B).
Most helpful comment
In my opinion,
dot(A::AbstractArray, B::AbstractArray)should throw an error ifsize(A) != size(B).