diff --git a/Project.toml b/Project.toml index cea885ea..7b9bea05 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ArrayLayouts" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -version = "1.16.1" +version = "1.16" authors = ["Sheehan Olver "] [deps] diff --git a/src/mul.jl b/src/mul.jl index c4cd7680..a76e10f2 100644 --- a/src/mul.jl +++ b/src/mul.jl @@ -33,8 +33,9 @@ axes(M::Mul) = _mul_axes(axes(M.A), axes(M.B)) zeroeltype(M) = _zeroeltype(eltype(M), M) # allow special casing where we know more about zero _zeroeltype(::Type{T}, M) where T = zero(T) -# zero(T) is not defined for arrays like Vector{Float64} so use the entries to determine the size -_zeroeltype(::Type{T}, M::Mul) where T<:AbstractArray = convert(T, zero(first(M.A) * first(M.B))) +# zero(T) is not defined for arrays like Vector{Float64} so use the entries to determine the size. +# Prefer zero(T) when it exists (e.g. SVector) since first may not be defined (e.g. quasi-arrays) +_zeroeltype(::Type{T}, M::Mul) where T<:AbstractArray = applicable(zero, T) ? zero(T) : convert(T, zero(first(M.A) * first(M.B))) zeroeltype(M::Mul{<:Any,<:Any,<:SubArray}) = zeroeltype(Mul(parent(M.A), M.B)) function _getindex(::Type{Tuple{AA}}, M::Mul, (k,)::Tuple{AA}) where AA diff --git a/test/test_muladd.jl b/test/test_muladd.jl index 84a22c68..d2896723 100644 --- a/test/test_muladd.jl +++ b/test/test_muladd.jl @@ -99,6 +99,9 @@ Random.seed!(0) @test ArrayLayouts.Mul(X, reshape(c,2,1))[1,1] == X[1] + 2X[2] v = reshape([[1.0, 2.0], [3.0, 4.0]], 1, 2) @test ArrayLayouts.Mul(v, c)[1] == [7.0, 10.0] + # eltypes with zero(T) should not need any entries + S = Matrix{SVector{2,Float64}}(undef, 1, 0) + @test ArrayLayouts.Mul(S, Float64[])[1] === zero(SVector{2,Float64}) end @testset "Diagonal Fill" begin