Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot does not check sizes of matrices #549

Open
antoine-levitt opened this issue Aug 12, 2018 · 7 comments
Open

Dot does not check sizes of matrices #549

antoine-levitt opened this issue Aug 12, 2018 · 7 comments

Comments

@antoine-levitt
Copy link
Collaborator

antoine-levitt commented Aug 12, 2018

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.

@garrison
Copy link
Member

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 #496 and JuliaLang/julia#27401.

@andreasnoack
Copy link
Member

cc @ranocha @stevengj

@ranocha
Copy link
Member

ranocha commented Aug 13, 2018

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.

@garrison
Copy link
Member

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?

@ranocha
Copy link
Member

ranocha commented Aug 14, 2018

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

@User-764Q
Copy link

Hi, I tried to recreate this issue in Julia 1.6.2 and got an error.

Perhaps this issue can be closed.

Matt

julia> A = rand(4,4)
4×4 Matrix{Float64}:
 0.788663   0.537215  0.811606    0.257814
 0.626794   0.529819  0.680855    0.557777
 0.0729996  0.892597  0.00195477  0.492219
 0.102279   0.429933  0.0287495   0.987619

julia> B = rand(8,2)
8×2 Matrix{Float64}:
 0.0245051  0.174716
 0.0531426  0.618903
 0.418906   0.259336
 0.112058   0.0676434
 0.102453   0.674323
 0.0483346  0.632437
 0.716796   0.930625
 0.232      0.794265

julia> dot(A,B)
ERROR: UndefVarError: dot not defined
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

julia> 

@ViralBShah
Copy link
Member

Still an error. The example above has not done using LinearAlgebra.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants