Skip to content

Commit 75a0bc9

Browse files
authored
Fix mul with quasi-arrays (#292)
1 parent 2ce23fb commit 75a0bc9

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎Project.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
3-
version = "1.16.1"
3+
version = "1.16"
44
authors = ["Sheehan Olver <solver@mac.com>"]
55

66
[deps]

‎src/mul.jl‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ axes(M::Mul) = _mul_axes(axes(M.A), axes(M.B))
3333

3434
zeroeltype(M) = _zeroeltype(eltype(M), M) # allow special casing where we know more about zero
3535
_zeroeltype(::Type{T}, M) where T = zero(T)
36-
# zero(T) is not defined for arrays like Vector{Float64} so use the entries to determine the size
37-
_zeroeltype(::Type{T}, M::Mul) where T<:AbstractArray = convert(T, zero(first(M.A) * first(M.B)))
36+
# zero(T) is not defined for arrays like Vector{Float64} so use the entries to determine the size.
37+
# Prefer zero(T) when it exists (e.g. SVector) since first may not be defined (e.g. quasi-arrays)
38+
_zeroeltype(::Type{T}, M::Mul) where T<:AbstractArray = applicable(zero, T) ? zero(T) : convert(T, zero(first(M.A) * first(M.B)))
3839
zeroeltype(M::Mul{<:Any,<:Any,<:SubArray}) = zeroeltype(Mul(parent(M.A), M.B))
3940

4041
function _getindex(::Type{Tuple{AA}}, M::Mul, (k,)::Tuple{AA}) where AA

‎test/test_muladd.jl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Random.seed!(0)
9999
@test ArrayLayouts.Mul(X, reshape(c,2,1))[1,1] == X[1] + 2X[2]
100100
v = reshape([[1.0, 2.0], [3.0, 4.0]], 1, 2)
101101
@test ArrayLayouts.Mul(v, c)[1] == [7.0, 10.0]
102+
# eltypes with zero(T) should not need any entries
103+
S = Matrix{SVector{2,Float64}}(undef, 1, 0)
104+
@test ArrayLayouts.Mul(S, Float64[])[1] === zero(SVector{2,Float64})
102105
end
103106

104107
@testset "Diagonal Fill" begin

0 commit comments

Comments
 (0)