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

Adjoint times Diagonal times Vector for n = 0 #714

Closed
ettersi opened this issue Apr 10, 2020 · 2 comments · Fixed by JuliaLang/julia#35557
Closed

Adjoint times Diagonal times Vector for n = 0 #714

ettersi opened this issue Apr 10, 2020 · 2 comments · Fixed by JuliaLang/julia#35557
Labels
bug Something isn't working

Comments

@ettersi
Copy link

ettersi commented Apr 10, 2020

# This works
julia> zeros(0)'*zeros(0)
0.0

# This does not, which is inconsistent
julia> zeros(0)'*Diagonal(zeros(0))*zeros(0)
ERROR: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
 [1] _empty_reduce_error() at ./reduce.jl:212
 [2] mapreduce_empty(::Function, ::Function, ::Type) at ./reduce.jl:246
 [3] mapreduce_empty_iter(::Function, ::Function, ::Base.Iterators.Zip{Tuple{Adjoint{Float64,Array{Float64,1}},Array{Float64,1},Array{Float64,1}}}, ::Base.HasEltype) at ./reduce.jl:254
 [4] mapfoldl_impl at ./reduce.jl:57 [inlined]
 [5] #mapfoldl#186 at ./reduce.jl:72 [inlined]
 [6] mapfoldl at ./reduce.jl:72 [inlined]
 [7] #mapreduce#194 at ./reduce.jl:200 [inlined]
 [8] mapreduce at ./reduce.jl:200 [inlined]
 [9] *(::Adjoint{Float64,Array{Float64,1}}, ::Diagonal{Float64,Array{Float64,1}}, ::Array{Float64,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/LinearAlgebra/src/diagonal.jl:640
 [10] top-level scope at none:0
@StefanKarpinski StefanKarpinski added the bug Something isn't working label Apr 10, 2020
@MasonProtter
Copy link
Contributor

The bug seems to come from 3 argument multiplication:

julia> Diagonal(zeros(0))*zeros(0)
0-element Array{Float64,1}

julia> zeros(0)'Diagonal(zeros(0))*zeros(0)
0.0

julia> zeros(0)'*Diagonal(zeros(0))*zeros(0)
ERROR: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
 [1] _empty_reduce_error() at ./reduce.jl:295
 [2] mapreduce_empty(::Function, ::Base.BottomRF{typeof(+)}, ::Type{T} where T) at ./reduce.jl:334
 [3] reduce_empty(::Base.MappingRF{LinearAlgebra.var"#160#161",Base.BottomRF{typeof(+)}}, ::Type{T} where T) at ./reduce.jl:321
 [4] reduce_empty_iter at ./reduce.jl:347 [inlined]
 [5] reduce_empty_iter at ./reduce.jl:346 [inlined]
 [6] foldl_impl at ./reduce.jl:46 [inlined]
 [7] mapfoldl_impl at ./reduce.jl:41 [inlined]
 [8] #mapfoldl#189 at ./reduce.jl:157 [inlined]
 [9] mapfoldl at ./reduce.jl:157 [inlined]
 [10] #mapreduce#193 at ./reduce.jl:283 [inlined]
 [11] mapreduce at ./reduce.jl:283 [inlined]
 [12] *(::Adjoint{Float64,Array{Float64,1}}, ::Diagonal{Float64,Array{Float64,1}}, ::Array{Float64,1}) at /home/mason/julia/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/diagonal.jl:647
 [13] top-level scope at REPL[7]:1
 [14] eval(::Module, ::Any) at ./boot.jl:331
 [15] eval_user_input(::Any, ::REPL.REPLBackend) at /home/mason/julia/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [16] run_backend(::REPL.REPLBackend) at /home/mason/.julia/packages/Revise/Pcs5V/src/Revise.jl:1073
 [17] top-level scope at none:0

@dkarrasch
Copy link
Member

Yes

julia> @which zeros(0)'Diagonal(zeros(0))*zeros(0)
*(u::Adjoint{T,#s662} where #s662<:(AbstractArray{T,1} where T) where T, v::AbstractArray{T,1} where T) in LinearAlgebra at /Applications/Julia-1.4.app/Contents/Resources/julia/share/julia/stdlib/v1.4/LinearAlgebra/src/adjtrans.jl:245

julia> @which zeros(0)'*Diagonal(zeros(0))*zeros(0)
*(x::Adjoint{#s662,#s661} where #s661<:(AbstractArray{T,1} where T) where #s662, D::Diagonal, y::AbstractArray{T,1} where T) in LinearAlgebra at /Applications/Julia-1.4.app/Contents/Resources/julia/share/julia/stdlib/v1.4/LinearAlgebra/src/diagonal.jl:647

The diagonal.jl version (the second) needs to be expanded to handle the length-0 case. I'm a bit surprised though that the first is not parsed like the second...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants