Julia: Dot does not check sizes of matrices

Created on 12 Aug 2018  路  5Comments  路  Source: JuliaLang/julia

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.

linear algebra

Most helpful comment

In my opinion, dot(A::AbstractArray, B::AbstractArray) should throw an error if size(A) != size(B).

All 5 comments

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).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ararslan picture ararslan  路  3Comments

omus picture omus  路  3Comments

Keno picture Keno  路  3Comments

tkoolen picture tkoolen  路  3Comments

TotalVerb picture TotalVerb  路  3Comments