Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ function dot(x, y) # arbitrary iterables
return s
end

dot(x::Number, y::Number) = conj(x) * y
# the unary + is for type promotion in the Boolean case, mimicking the reduction in usual dot
dot(x::Number, y::Number) = +(conj(x) * y)

function dot(x::AbstractArray, y::AbstractArray)
lx = length(x)
Expand Down
8 changes: 6 additions & 2 deletions test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,16 @@ end
end

@testset "generalized dot #32739" begin
for elty in (Int, Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat})
for elty in (Bool, Int, Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat})
n = 10
if elty <: Int
A = rand(-n:n, n, n)
x = rand(-n:n, n)
y = rand(-n:n, n)
elseif elty <: Bool
A = rand(elty, n, n)
x = rand(elty, n)
y = rand(elty, n)
elseif elty <: Real
A = convert(Matrix{elty}, randn(n,n))
x = rand(elty, n)
Expand All @@ -770,7 +774,7 @@ end
x = rand(elty, n)
y = rand(elty, n)
end
@test dot(x, A, y) ≈ dot(A'x, y) ≈ *(x', A, y) ≈ (x'A)*y
@test (@inferred dot(x, A, y)) ≈ dot(A'x, y) ≈ *(x', A, y) ≈ (x'A)*y
@test dot(x, A', y) ≈ dot(A*x, y) ≈ *(x', A', y) ≈ (x'A')*y
elty <: Real && @test dot(x, transpose(A), y) ≈ dot(x, transpose(A)*y) ≈ *(x', transpose(A), y) ≈ (x'*transpose(A))*y
B = reshape([A], 1, 1)
Expand Down