Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ArrayLayouts"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
version = "1.12.3"
version = "1.12.4"
authors = ["Sheehan Olver <solver@mac.com>"]

[deps]
Expand Down
5 changes: 4 additions & 1 deletion src/mul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/test_muladd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading