Skip to content

dot(x::Adjoint, y::AbstractVector) gives inconsistent answer #32395

Open

Description

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:

function dot(x::AbstractArray, y::AbstractArray)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions