diff --git a/Project.toml b/Project.toml index 2b80ef4..3cbc61f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ArrayLayouts" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -version = "1.12.3" +version = "1.12.4" authors = ["Sheehan Olver "] [deps] diff --git a/src/mul.jl b/src/mul.jl index 0cb89cf..c4cd768 100644 --- a/src/mul.jl +++ b/src/mul.jl @@ -31,7 +31,10 @@ axes(M::Mul) = _mul_axes(axes(M.A), axes(M.B)) # The following design is to support QuasiArrays.jl where indices # may not be `Int` -zeroeltype(M) = zero(eltype(M)) # allow special casing where we know more about zero +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))) 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 dc6a239..84a22c6 100644 --- a/test/test_muladd.jl +++ b/test/test_muladd.jl @@ -92,6 +92,15 @@ Random.seed!(0) @test mul(X,A) == X*A end + @testset "Mul getindex with array eltype" begin + X = reshape([[1 2; 3 4], [5 6; 7 8]], 1, 2) + c = [1, 2] + @test ArrayLayouts.Mul(X, c)[1] == X[1] + 2X[2] + @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] + end + @testset "Diagonal Fill" begin for (A, B) in (([1:4;], [3:6;]), (reshape([1:16;],4,4), reshape(2 .* [1:16;],4,4))) D = Diagonal(Fill(3, 4))