diff --git a/src/bidiag.jl b/src/bidiag.jl index 88b5a763..fe20ab42 100644 --- a/src/bidiag.jl +++ b/src/bidiag.jl @@ -1292,7 +1292,7 @@ function dot(x::AbstractVector, B::Bidiagonal, y::AbstractVector) nx, ny = length(x), length(y) (nx == size(B, 1) == ny) || throw(DimensionMismatch()) if nx ≤ 1 - nx == 0 && return dot(zero(eltype(x)), zero(eltype(B)), zero(eltype(y))) + nx == 0 && return zero(dot(zero(eltype(x)), zero(eltype(B)), zero(eltype(y)))) return dot(x[1], B.dv[1], y[1]) end ev, dv = B.ev, B.dv diff --git a/src/generic.jl b/src/generic.jl index 70bbf8f6..b1ec10db 100644 --- a/src/generic.jl +++ b/src/generic.jl @@ -1034,6 +1034,8 @@ dot(x, A, y) = dot(x, A*y) # generic fallback for cases that are not covered by function dot(x::AbstractVector, A::AbstractMatrix, y::AbstractVector) (axes(x)..., axes(y)...) == axes(A) || throw(DimensionMismatch()) + # outermost zero call to avoid spurious sign ambiguity (like 0.0 - 0.0im) + any(isempty, (x, y)) && return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y)))) T = typeof(dot(first(x), first(A), first(y))) s = zero(T) i₁ = first(eachindex(x)) diff --git a/src/hessenberg.jl b/src/hessenberg.jl index 36450160..9c5e2e40 100644 --- a/src/hessenberg.jl +++ b/src/hessenberg.jl @@ -404,7 +404,7 @@ function dot(x::AbstractVector, H::UpperHessenberg, y::AbstractVector) m = size(H, 1) (length(x) == m == length(y)) || throw(DimensionMismatch()) if iszero(m) - return dot(zero(eltype(x)), zero(eltype(H)), zero(eltype(y))) + return zero(dot(zero(eltype(x)), zero(eltype(H)), zero(eltype(y)))) end x₁ = x[1] r = dot(x₁, H[1,1], y[1]) diff --git a/src/symmetric.jl b/src/symmetric.jl index fd4b9ada..079fb305 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -774,6 +774,7 @@ function dot(x::AbstractVector, A::HermOrSym, y::AbstractVector) require_one_based_indexing(x, y) n = length(x) (n == length(y) == size(A, 1)) || throw(DimensionMismatch()) + iszero(n) && return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y)))) data = A.data s = dot(first(x), first(A), first(y)) r = zero(s+s) diff --git a/src/triangular.jl b/src/triangular.jl index d82ddd87..75c721bc 100644 --- a/src/triangular.jl +++ b/src/triangular.jl @@ -893,7 +893,7 @@ function dot(x::AbstractVector, A::UpperTriangular, y::AbstractVector) m = size(A, 1) (length(x) == m == length(y)) || throw(DimensionMismatch()) if iszero(m) - return dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y))) + return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y)))) end x₁ = x[1] r = dot(x₁, A[1,1], y[1]) @@ -914,7 +914,7 @@ function dot(x::AbstractVector, A::UnitUpperTriangular, y::AbstractVector) m = size(A, 1) (length(x) == m == length(y)) || throw(DimensionMismatch()) if iszero(m) - return dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y))) + return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y)))) end x₁ = first(x) r = dot(x₁, y[1]) @@ -936,7 +936,7 @@ function dot(x::AbstractVector, A::LowerTriangular, y::AbstractVector) m = size(A, 1) (length(x) == m == length(y)) || throw(DimensionMismatch()) if iszero(m) - return dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y))) + return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y)))) end r = zero(typeof(dot(first(x), first(A), first(y)))) @inbounds for j in axes(A, 2) @@ -956,7 +956,7 @@ function dot(x::AbstractVector, A::UnitLowerTriangular, y::AbstractVector) m = size(A, 1) (length(x) == m == length(y)) || throw(DimensionMismatch()) if iszero(m) - return dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y))) + return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y)))) end r = zero(typeof(dot(first(x), first(y)))) @inbounds for j in axes(A, 2) diff --git a/src/tridiag.jl b/src/tridiag.jl index a0e3d821..2357ecc1 100644 --- a/src/tridiag.jl +++ b/src/tridiag.jl @@ -253,7 +253,7 @@ function dot(x::AbstractVector, S::SymTridiagonal, y::AbstractVector) nx, ny = length(x), length(y) (nx == size(S, 1) == ny) || throw(DimensionMismatch("dot")) if nx ≤ 1 - nx == 0 && return dot(zero(eltype(x)), zero(eltype(S)), zero(eltype(y))) + nx == 0 && return zero(dot(zero(eltype(x)), zero(eltype(S)), zero(eltype(y)))) return dot(x[1], S.dv[1], y[1]) end dv, ev = S.dv, S.ev @@ -1022,7 +1022,7 @@ function dot(x::AbstractVector, A::Tridiagonal, y::AbstractVector) nx, ny = length(x), length(y) (nx == size(A, 1) == ny) || throw(DimensionMismatch()) if nx ≤ 1 - nx == 0 && return dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y))) + nx == 0 && return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y)))) return dot(x[1], A.d[1], y[1]) end @inbounds begin diff --git a/test/generic.jl b/test/generic.jl index 5de19446..986bb552 100644 --- a/test/generic.jl +++ b/test/generic.jl @@ -784,6 +784,10 @@ end @test dot(x, B', y) ≈ dot(B*x, y) elty <: Real && @test dot(x, transpose(B), y) ≈ dot(x, transpose(B)*y) end + for (m, n) in ((0, 0), (1, 0), (0, 1)) + v = zeros(ComplexF64, m); a = zeros(ComplexF64, m, n); w = zeros(Float64, n) + @test dot(v, a, w) === zero(ComplexF64) + end end @testset "condskeel #34512" begin