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

should matrix-vector mul! also protect against aliasing? #1073

Open
daviehh opened this issue May 22, 2024 · 2 comments
Open

should matrix-vector mul! also protect against aliasing? #1073

daviehh opened this issue May 22, 2024 · 2 comments

Comments

@daviehh
Copy link

daviehh commented May 22, 2024

As per the documentation for mul!,

https://github.com/JuliaLang/julia/blob/263928f9ad450a28d601c3f185040987e0bc45d5/stdlib/LinearAlgebra/src/matmul.jl#L266-L268

The mwe

a = rand(3, 3); v = rand(3);
mul!(a, a, a)

is 'protected' against wrong inputs for matrix-matrix product and errors w/

ERROR: ArgumentError: output matrix must not be aliased with input matrix

https://github.com/JuliaLang/julia/blob/263928f9ad450a28d601c3f185040987e0bc45d5/stdlib/LinearAlgebra/src/matmul.jl#L653-L655

however, the matrix-vector product a * v is not 'protected' against C == A || C == B

julia> mul!(v, a, v)
3-element Vector{Float64}:
 0.0
 0.0
 0.0

should a similar alias check be applied for matrix-vector mul! at the gemv! or generic_matvecmul! methods?

@jishnub
Copy link
Collaborator

jishnub commented May 22, 2024

I think it should, as it's a common footgun. Also, matrix-matrix multiplication doesn't protect against this either other than the 2x2 and 3x3 cases.

@dkarrasch
Copy link
Member

... and in gemm_wrapper!. Maybe those aliasing tests got lost a bit over the recent rearrangements?

@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

3 participants