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
4 changes: 2 additions & 2 deletions src/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ function __generic_matvecmul!(f::F, C::AbstractVector, A::AbstractVecOrMat, B::A
@inbounds begin
if length(B) == 0
for k = eachindex(C)
@stable_muladdmul _modify!(MulAddMul(alpha,beta), false, C, k)
@stable_muladdmul _modify!(MulAddMul(alpha,beta), zero(eltype(C)), C, k)
end
else
for k = eachindex(C)
Expand All @@ -955,7 +955,7 @@ function __generic_matvecmul!(::typeof(identity), C::AbstractVector, A::Abstract
if !iszero(beta)
C[i] *= beta
elseif length(B) == 0
C[i] = false
C[i] = zero(eltype(C))
else
C[i] = zero(A[i]*B[1] + A[i]*B[1])
end
Expand Down
17 changes: 17 additions & 0 deletions test/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ using Base: rtoldefault
using Test, LinearAlgebra, Random
using LinearAlgebra: mul!, Symmetric, Hermitian

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
using .Main.SizedArrays

## Test Julia fallbacks to BLAS routines

mul_wrappers = [
Expand Down Expand Up @@ -1176,4 +1181,16 @@ end
end
end

@testset "zero-length generic matvec" begin
m = SizedArrays.SizedArray{(2,2)}(ones(2,2))
A = fill(m, 2, 0)
v = fill(m, size(A,2))
w = similar(v, size(A,1))
mul!(w, A, v)
@test all(iszero, w)
A = fill(m, 0, 2)
mul!(w, A', v)
@test all(iszero, w)
end

end # module TestMatmul