Description
openedon Jun 22, 2019
I wanted to get some feedback before maybe submitting a simple PR. I was quite surprised that dot
of an Adjoint
and a Vector
gives the same answer as if I had never done the adjoint:
julia> using LinearAlgebra
julia> v = [1,2]
2-element Array{Int64,1}:
1
2
julia> dot(v,v)
5
julia> dot(adjoint(v),v)
5
I haven't been able to find any discussion explicitly about this, having gone through the many threads about adjoints. Mathematically I think it doesn't make sense and breaks some of the nice mathematical consistency of the existing system. My guess is that its just an unintended consequence of how generic this function is:
julia/stdlib/LinearAlgebra/src/generic.jl
Line 785 in f6049d6
I would propose special-casing the dot product with the following definition:
LinearAlgebra.dot(x::Adjoint{<:Any,<:AbstractVector}, y::AbstractVector) = parent(x)*y
which means that dot(adjoint(v),v)
would be equivalent to v*v
, which for Base vectors is undefined (although users would be free to define this operations for their own custom AbstractVectors
, and I believe everything remains consistent in that case).
Let me know if there's any comments on this and if I should go ahead and make the PR.