Skip to content

Commit e5b33f1

Browse files
committed
Fix 3-arg dot for empty arrays
1 parent b599095 commit e5b33f1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/generic.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ dot(x, A, y) = dot(x, A*y) # generic fallback for cases that are not covered by
10341034

10351035
function dot(x::AbstractVector, A::AbstractMatrix, y::AbstractVector)
10361036
(axes(x)..., axes(y)...) == axes(A) || throw(DimensionMismatch())
1037+
# outermost zero call to avoid spurious sign ambiguity (like 0.0 - 0.0im)
1038+
any(isempty, (x, y)) && return zero(dot(zero(eltype(x)), zero(eltype(A)), zero(eltype(y))))
10371039
T = typeof(dot(first(x), first(A), first(y)))
10381040
s = zero(T)
10391041
i₁ = first(eachindex(x))

test/generic.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ end
784784
@test dot(x, B', y) dot(B*x, y)
785785
elty <: Real && @test dot(x, transpose(B), y) dot(x, transpose(B)*y)
786786
end
787+
for (m, n) in ((0, 0), (1, 0), (0, 1))
788+
v = zeros(ComplexF64, m); a = zeros(ComplexF64, m, n); w = zeros(Float64, n)
789+
@test dot(v, a, w) === zero(ComplexF64)
790+
end
787791
end
788792

789793
@testset "condskeel #34512" begin

0 commit comments

Comments
 (0)