Skip to content

Commit 8ee041b

Browse files
authored
add * mul ambiguities (#336)
* add * mul ambiguities * Update padded.jl
1 parent a7bd760 commit 8ee041b

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LazyArrays"
22
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
3-
version = "2.1.5"
3+
version = "2.1.6"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/linalg/add.jl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,26 @@ _broadcasted_mul(A::AbstractMatrix, B::Tuple{AbstractMatrix,Vararg{Any}}) = (siz
102102

103103
for op in (:+, :-)
104104
@eval begin
105-
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)}}) = Val(true)
106-
simplifiable(M::Mul{<:Any,<:BroadcastLayout{typeof($op)}}) = Val(true)
107-
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)},<:BroadcastLayout{typeof($op)}}) = simplifiable(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
108-
copy(M::Mul{Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(arguments(Lay(), M.A), M.B)...)
109-
copy(M::Mul{Lay,<:LazyLayouts}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(arguments(Lay(), M.A), M.B)...)
110-
copy(M::Mul{<:Any,Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(M.A, arguments(Lay(), M.B))...)
111-
copy(M::Mul{<:LazyLayouts,Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(M.A, arguments(Lay(), M.B))...)
112-
copy(M::Mul{Lay,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
113-
simplify(M::Mul{Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
114-
simplify(M::Mul{<:Any,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{UnknownLayout,Lay}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
115-
simplify(M::Mul{Lay,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(M) # TODO: remove, here for back-compat with QuasiArrays.jl
105+
simplifiable(M::Mul{BroadcastLayout{typeof($op)}}) = Val(true)
106+
simplifiable(M::Mul{<:Any,BroadcastLayout{typeof($op)}}) = Val(true)
107+
simplifiable(M::Mul{BroadcastLayout{typeof($op)},BroadcastLayout{typeof($op)}}) = simplifiable(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
108+
copy(M::Mul{BroadcastLayout{typeof($op)}}) = broadcast($op, _broadcasted_mul(arguments(BroadcastLayout{typeof($op)}(), M.A), M.B)...)
109+
copy(M::Mul{BroadcastLayout{typeof($op)},<:LazyLayouts}) = broadcast($op, _broadcasted_mul(arguments(BroadcastLayout{typeof($op)}(), M.A), M.B)...)
110+
copy(M::Mul{<:Any,BroadcastLayout{typeof($op)}}) = broadcast($op, _broadcasted_mul(M.A, arguments(BroadcastLayout{typeof($op)}(), M.B))...)
111+
copy(M::Mul{<:LazyLayouts,BroadcastLayout{typeof($op)}}) = broadcast($op, _broadcasted_mul(M.A, arguments(BroadcastLayout{typeof($op)}(), M.B))...)
112+
copy(M::Mul{BroadcastLayout{typeof($op)},BroadcastLayout{typeof($op)}}) = copy(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
113+
copy(M::Mul{BroadcastLayout{typeof($op)},ApplyLayout{typeof(*)}}) = copy(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
114+
copy(M::Mul{ApplyLayout{typeof(*)},BroadcastLayout{typeof($op)}}) = copy(Mul{UnknownLayout,BroadcastLayout{typeof($op)}}(M.A, M.B))
115+
simplify(M::Mul{BroadcastLayout{typeof($op)}}) = copy(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
116+
simplify(M::Mul{<:Any,BroadcastLayout{typeof($op)}}) = copy(Mul{UnknownLayout,BroadcastLayout{typeof($op)}}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
117+
simplify(M::Mul{BroadcastLayout{typeof($op)},BroadcastLayout{typeof($op)}}) = copy(M) # TODO: remove, here for back-compat with QuasiArrays.jl
116118
end
117119
end
118120

119-
simplifiable(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = simplifiable(Mul{Lay,UnknownLayout}(M.A, M.B))
120-
simplifiable(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = simplifiable(Mul{Lay,UnknownLayout}(M.A, M.B))
121+
simplifiable(M::Mul{BroadcastLayout{typeof(+)},BroadcastLayout{typeof(-)}}) = simplifiable(Mul{BroadcastLayout{typeof(+)},UnknownLayout}(M.A, M.B))
122+
simplifiable(M::Mul{BroadcastLayout{typeof(-)},BroadcastLayout{typeof(+)}}) = simplifiable(Mul{BroadcastLayout{typeof(-)},UnknownLayout}(M.A, M.B))
121123

122-
copy(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
123-
copy(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
124-
simplify(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
125-
simplify(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
124+
copy(M::Mul{BroadcastLayout{typeof(+)},BroadcastLayout{typeof(-)}}) = copy(Mul{BroadcastLayout{typeof(+)},UnknownLayout}(M.A, M.B))
125+
copy(M::Mul{BroadcastLayout{typeof(-)} ,BroadcastLayout{typeof(+)}}) = copy(Mul{BroadcastLayout{typeof(-)} ,UnknownLayout}(M.A, M.B))
126+
simplify(M::Mul{BroadcastLayout{typeof(+)},BroadcastLayout{typeof(-)}}) = copy(Mul{BroadcastLayout{typeof(+)},UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
127+
simplify(M::Mul{BroadcastLayout{typeof(-)} ,BroadcastLayout{typeof(+)}}) = copy(Mul{BroadcastLayout{typeof(-)} ,UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl

src/padded.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@ end
525525

526526
for op in (:+, :-)
527527
@eval begin
528-
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)},<:Union{PaddedColumns,PaddedLayout}}) = Val(true)
529-
simplifiable(M::Mul{<:DualLayout{<:PaddedRows},<:BroadcastLayout{typeof($op)}}) = Val(true)
530-
copy(M::Mul{Lay,<:Union{PaddedColumns,PaddedLayout}}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
531-
copy(M::Mul{<:DualLayout{<:PaddedRows},Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{UnknownLayout,Lay}(M.A, M.B))
528+
simplifiable(M::Mul{BroadcastLayout{typeof($op)},<:Union{PaddedColumns,PaddedLayout}}) = Val(true)
529+
simplifiable(M::Mul{<:DualLayout{<:PaddedRows},BroadcastLayout{typeof($op)}}) = Val(true)
530+
copy(M::Mul{BroadcastLayout{typeof($op)},<:Union{PaddedColumns,PaddedLayout}}) = copy(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
531+
copy(M::Mul{<:DualLayout{<:PaddedRows},BroadcastLayout{typeof($op)}}) = copy(Mul{UnknownLayout,BroadcastLayout{typeof($op)}}(M.A, M.B))
532532
end
533533
end
534534

test/addtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,19 @@ import LazyArrays: Add, AddArray, MulAdd, materialize!, MemoryLayout, ApplyLayou
330330
@test B*D simplify(Mul(B,D)) Matrix(B)*D
331331
@test D*B simplify(Mul(D,B)) D*Matrix(B)
332332
end
333+
334+
@testset "Add * Mul" begin
335+
A = randn(5,5)
336+
B = BroadcastArray(+, A, 2A)
337+
C = BroadcastArray(-, A, 2A)
338+
M = ApplyArray(*, A, A)
339+
@test B*M Matrix(B)*M
340+
@test C*M Matrix(C)*M
341+
@test M*B M*Matrix(B)
342+
@test M*C M*Matrix(C)
343+
@test simplifiable(*,B,M) == simplifiable(*,C,M) == Val(true)
344+
@test simplifiable(*,M,B) == simplifiable(*,M,C) == Val(true)
345+
end
333346
end
334347
end # testset
335348

0 commit comments

Comments
 (0)