Skip to content

Commit 4653153

Browse files
committed
Destination zeros from eltype in zero-length generic_matvecmul
1 parent 38273fd commit 4653153

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/matmul.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ function __generic_matvecmul!(::typeof(identity), C::AbstractVector, A::Abstract
955955
if !iszero(beta)
956956
C[i] *= beta
957957
elseif length(B) == 0
958-
C[i] = false
958+
C[i] = zero(eltype(C))
959959
else
960960
C[i] = zero(A[i]*B[1] + A[i]*B[1])
961961
end

test/matmul.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ using Base: rtoldefault
66
using Test, LinearAlgebra, Random
77
using LinearAlgebra: mul!, Symmetric, Hermitian
88

9+
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
10+
11+
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
12+
using .Main.SizedArrays
13+
914
## Test Julia fallbacks to BLAS routines
1015

1116
mul_wrappers = [
@@ -1168,4 +1173,13 @@ end
11681173
end
11691174
end
11701175

1176+
@testset "zero-length generic matvec" begin
1177+
m = SizedArrays.SizedArray{(2,2)}(reshape(1:4, 2, 2))
1178+
A = fill(m, 2, 0)
1179+
v = fill(m, size(A,2))
1180+
w = similar(v, size(A,1))
1181+
mul!(w, A, v)
1182+
@test all(iszero, w)
1183+
end
1184+
11711185
end # module TestMatmul

0 commit comments

Comments
 (0)