diff --git a/src/host/linalg.jl b/src/host/linalg.jl index 536f345b..49b9f37e 100644 --- a/src/host/linalg.jl +++ b/src/host/linalg.jl @@ -449,7 +449,7 @@ function generic_matmatmul!(C::AbstractArray{R}, A::AbstractArray{T}, B::Abstrac throw(DimensionMismatch("result C has dimensions $(size(C)), needs $((size(A,1),size(B,2)))")) end if isempty(A) || isempty(B) - return fill!(C, zero(R)) + return rmul!(C, add.beta) end @kernel function matmatmul_kernel!(C, A, B) diff --git a/test/testsuite/linalg.jl b/test/testsuite/linalg.jl index a7ba91e6..ef8047d5 100644 --- a/test/testsuite/linalg.jl +++ b/test/testsuite/linalg.jl @@ -542,6 +542,16 @@ end @test compare(mul!, AT, rand(T, 2,2), rand(T, 2,1), f(rand(T, 2))) end end + + @testset "$T gemv zero-dim" for T in eltypes + y, A, x = rand(T, 4), rand(T, 4, 0), rand(T, 0) + + @test compare(*, AT, A, x) + @test compare(mul!, AT, y, A, x) + + y = rand(T, 4) + @test compare(mul!, AT, y, A, x, Ref(T(4)), Ref(T(5))) + end end @testsuite "linalg/mul!/matrix-matrix" (AT, eltypes)->begin @@ -556,6 +566,16 @@ end @test compare(mul!, AT, C, f(A), g(B), Ref(T(4)), Ref(T(5))) @test typeof(AT(rand(T, 3, 3)) * AT(rand(T, 3, 3))) <: AbstractMatrix end + + @testset "$T gemm zero-dim" for T in eltypes + A, B, C = rand(T, 4, 0), rand(T, 0, 4), rand(T, 4, 4) + + @test compare(*, AT, A, B) + @test compare(mul!, AT, C, A, B) + + C = rand(T, 4, 4) + @test compare(mul!, AT, C, A, B, Ref(T(4)), Ref(T(5))) + end @testset "$(complex(T)), $(complex(T)), $T gemm C := A * B * a + C * b" for T in filter(T-><:(T, Real) && <:(T, AbstractFloat), eltypes) Tc = complex(T) A, B, C = rand(Tc, 4, 4), rand(T, 4, 4), rand(Tc, 4, 4)