JuliaLang / JuliaLang/LinearAlgebra.jl
matvecmul via 5-arg mul! true, true with arrays of arrays errors
- Dominant language
- Julia
- Stars
- 77
- Forks
- 65
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 10
Description
I never asked for this.
But apparently people do this kind of thing.
because this came-up in trying to fix https://github.com/FluxML/Zygote.jl/issues/837
where they do do this thing.
Consider the following where 3 arg `mul` works but 5-arg doesn't.
```julia
julia> using LinearAlgebra
julia> f = Diagonal([1,2]);
julia> mul!(deepcopy([f,f]), reshape([f,f,f,f], 2,2), [f,f], true, true)
ERROR: MethodError: no method matching +(::Diagonal{Int64, Vector{Int64}}, ::Bool)
For element-wise addition, use broadcasting with dot syntax: array .+ scalar
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:540
+(::Rational, ::Integer) at rational.jl:288
+(::T, ::Integer) where T<:AbstractChar at char.jl:223
...
Stacktrace:
[1] MulAddMul
@ /usr/local/src/julia/julia-master/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/generic.jl:58 [inlined]
[2] generic_matvecmul!(C::Vector{Diagonal{Int64, Vector{Int64}}}, tA::Char, A::Matrix{Diagonal{Int64, Vector{Int64}}}, B::Vector{Diagonal{Int64, Vector{Int64}}}, _add::LinearAlgebra.MulAddMul{true, false, Bool, Bool})
@ LinearAlgebra /usr/local/src/julia/julia-master/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/matmul.jl:744
[3] mul!(y::Vector{Diagonal{Int64, Vector{Int64}}}, A::Matrix{Diagonal{Int64, Vector{Int64}}}, x::Vector{Diagonal{Int64, Vector{Int64}}}, alpha::Bool, beta::Bool)
@ LinearAlgebra /usr/local/src/julia/julia-master/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/matmul.jl:81
[4] top-level scope
@ REPL[3]:1
julia> mul!(deepcopy([f,f]), reshape([f,f,f,f], 2,2), [f,f])
2-element Vector{Diagonal{Int64, Vector{Int64}}}:
[2 0; 0 8]
[2 0; 0 8]
```
I don't really know what is going on but i suspect it is somewhere in this code
https://github.com/JuliaLang/julia/blob/af0006e1edd25b67891bb86330e294e41a036b3d/stdlib/LinearAlgebra/src/generic.jl#L54-L59
what is assuming the elements of the array is scalar.
I am always surprised that how often our code for linear algebra works for arrays of arrays.
like in this case where it does work for all options of 5-arg mul, except true, true.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reproducer in the issue, then inspect stdlib/LinearAlgebra/src/generic.jl around MulAddMul and stdlib/LinearAlgebra/src/matmul.jl around generic_matvecmul!. Compare the failing five-argument mul! call with the working three-argument and other five-argument cases. Done means the true, true array-of-arrays matvecmul! case works and has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100