-
-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
It seems that for non-empty zero vectors, dot consistently returns the zero element of the target type:
julia> x = Complex{Float64}[0]; y = Float64[0];
julia> dot(x, y), dot(-x, y), dot(conj(x), y), dot(x, -y)
(0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im)
For empty vectors, however, this is not always the case:
julia> v = Complex{Float64}[]; w = Float64[];
julia> dot(v, w)
0.0 - 0.0im
The reason are the lines
LinearAlgebra.jl/src/generic.jl
Lines 995 to 997 in b599095
| if lx == 0 | |
| return dot(zero(eltype(x)), zero(eltype(y))) | |
| end |
in
dot(x::AbstractArray, y::AbstractArray). Wouldn't it be more consistent to use zero(dot(zero(eltype(x)), zero(eltype(y)))) zero(eltype(x))*zero(eltype(y))By the way, the above examples also show that the claim
dotis semantically equivalent tosum(dot(vx,vy) for (vx,vy) in zip(x, y))
in the docstring is not correct:
julia> sum(dot(vx,vy) for (vx,vy) in zip(x, y))
0.0 - 0.0im
julia> sum(dot(vx,vy) for (vx,vy) in zip(v, w))
ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Metadata
Metadata
Assignees
Labels
No labels