Skip to content

Commit 7a4b27e

Browse files
authored
Make dot with Bool-arrays type-stable (#1456)
Fixes #1430.
2 parents 5af75df + 6fe77f8 commit 7a4b27e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/generic.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,8 @@ function dot(x, y) # arbitrary iterables
996996
return s
997997
end
998998

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

10011002
function dot(x::AbstractArray, y::AbstractArray)
10021003
lx = length(x)

test/generic.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,16 @@ end
755755
end
756756

757757
@testset "generalized dot #32739" begin
758-
for elty in (Int, Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat})
758+
for elty in (Bool, Int, Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat})
759759
n = 10
760760
if elty <: Int
761761
A = rand(-n:n, n, n)
762762
x = rand(-n:n, n)
763763
y = rand(-n:n, n)
764+
elseif elty <: Bool
765+
A = rand(elty, n, n)
766+
x = rand(elty, n)
767+
y = rand(elty, n)
764768
elseif elty <: Real
765769
A = convert(Matrix{elty}, randn(n,n))
766770
x = rand(elty, n)
@@ -770,7 +774,7 @@ end
770774
x = rand(elty, n)
771775
y = rand(elty, n)
772776
end
773-
@test dot(x, A, y) dot(A'x, y) *(x', A, y) (x'A)*y
777+
@test (@inferred dot(x, A, y)) dot(A'x, y) *(x', A, y) (x'A)*y
774778
@test dot(x, A', y) dot(A*x, y) *(x', A', y) (x'A')*y
775779
elty <: Real && @test dot(x, transpose(A), y) dot(x, transpose(A)*y) *(x', transpose(A), y) (x'*transpose(A))*y
776780
B = reshape([A], 1, 1)

0 commit comments

Comments
 (0)