From 5c74871d8db7f4ff4a8eff3e20a34cbe4fec2fcc Mon Sep 17 00:00:00 2001 From: Daniel Bruegmann Date: Fri, 26 Feb 2021 09:32:12 +0100 Subject: [PATCH] LinearAlgebra._generic_matmul! : Avoid division by zero for tile_size. (#39790) --- stdlib/LinearAlgebra/src/matmul.jl | 2 +- stdlib/LinearAlgebra/test/matmul.jl | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/matmul.jl b/stdlib/LinearAlgebra/src/matmul.jl index 4fed8a577bd638..27bd9c2f23b153 100644 --- a/stdlib/LinearAlgebra/src/matmul.jl +++ b/stdlib/LinearAlgebra/src/matmul.jl @@ -823,7 +823,7 @@ function _generic_matmatmul!(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVecOrMat tile_size = 0 if isbitstype(R) && isbitstype(T) && isbitstype(S) && (tA == 'N' || tB != 'N') - tile_size = floor(Int, sqrt(tilebufsize / max(sizeof(R), sizeof(S), sizeof(T)))) + tile_size = floor(Int, sqrt(tilebufsize / max(sizeof(R), sizeof(S), sizeof(T), 1))) end @inbounds begin if tile_size > 0 diff --git a/stdlib/LinearAlgebra/test/matmul.jl b/stdlib/LinearAlgebra/test/matmul.jl index 6a81222174e1fe..107c579ba1f942 100644 --- a/stdlib/LinearAlgebra/test/matmul.jl +++ b/stdlib/LinearAlgebra/test/matmul.jl @@ -720,6 +720,16 @@ end @test D ≈ C end +@testset "size zero types in matrix mult (see issue 39362)" begin + A = [missing missing; missing missing] + v = [missing, missing] + @test (A * v == v) === missing + M = fill(1.0, 2, 2) + a = fill(missing, 2, 1) + @test (a' * M * a == fill(missing,1,1)) === missing +end + + @testset "multiplication of empty matrices without calling zero" begin r, c = rand(0:9, 2) A = collect(Number, rand(r, c))