Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add * mul ambiguities #336

Merged
merged 2 commits into from
Jul 9, 2024
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 = "LazyArrays"
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
version = "2.1.5"
version = "2.1.6"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
36 changes: 19 additions & 17 deletions src/linalg/add.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,26 @@

for op in (:+, :-)
@eval begin
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)}}) = Val(true)
simplifiable(M::Mul{<:Any,<:BroadcastLayout{typeof($op)}}) = Val(true)
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)},<:BroadcastLayout{typeof($op)}}) = simplifiable(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
copy(M::Mul{Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(arguments(Lay(), M.A), M.B)...)
copy(M::Mul{Lay,<:LazyLayouts}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(arguments(Lay(), M.A), M.B)...)
copy(M::Mul{<:Any,Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(M.A, arguments(Lay(), M.B))...)
copy(M::Mul{<:LazyLayouts,Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(M.A, arguments(Lay(), M.B))...)
copy(M::Mul{Lay,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
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
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
simplify(M::Mul{Lay,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(M) # TODO: remove, here for back-compat with QuasiArrays.jl
simplifiable(M::Mul{BroadcastLayout{typeof($op)}}) = Val(true)
simplifiable(M::Mul{<:Any,BroadcastLayout{typeof($op)}}) = Val(true)
simplifiable(M::Mul{BroadcastLayout{typeof($op)},BroadcastLayout{typeof($op)}}) = simplifiable(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
copy(M::Mul{BroadcastLayout{typeof($op)}}) = broadcast($op, _broadcasted_mul(arguments(BroadcastLayout{typeof($op)}(), M.A), M.B)...)
copy(M::Mul{BroadcastLayout{typeof($op)},<:LazyLayouts}) = broadcast($op, _broadcasted_mul(arguments(BroadcastLayout{typeof($op)}(), M.A), M.B)...)
copy(M::Mul{<:Any,BroadcastLayout{typeof($op)}}) = broadcast($op, _broadcasted_mul(M.A, arguments(BroadcastLayout{typeof($op)}(), M.B))...)
copy(M::Mul{<:LazyLayouts,BroadcastLayout{typeof($op)}}) = broadcast($op, _broadcasted_mul(M.A, arguments(BroadcastLayout{typeof($op)}(), M.B))...)
copy(M::Mul{BroadcastLayout{typeof($op)},BroadcastLayout{typeof($op)}}) = copy(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
copy(M::Mul{BroadcastLayout{typeof($op)},ApplyLayout{typeof(*)}}) = copy(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
copy(M::Mul{ApplyLayout{typeof(*)},BroadcastLayout{typeof($op)}}) = copy(Mul{UnknownLayout,BroadcastLayout{typeof($op)}}(M.A, M.B))
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
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
simplify(M::Mul{BroadcastLayout{typeof($op)},BroadcastLayout{typeof($op)}}) = copy(M) # TODO: remove, here for back-compat with QuasiArrays.jl

Check warning on line 117 in src/linalg/add.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/add.jl#L105-L117

Added lines #L105 - L117 were not covered by tests
end
end

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

Check warning on line 122 in src/linalg/add.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/add.jl#L121-L122

Added lines #L121 - L122 were not covered by tests

copy(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
copy(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
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
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
copy(M::Mul{BroadcastLayout{typeof(+)},BroadcastLayout{typeof(-)}}) = copy(Mul{BroadcastLayout{typeof(+)},UnknownLayout}(M.A, M.B))
copy(M::Mul{BroadcastLayout{typeof(-)} ,BroadcastLayout{typeof(+)}}) = copy(Mul{BroadcastLayout{typeof(-)} ,UnknownLayout}(M.A, M.B))
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
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

Check warning on line 127 in src/linalg/add.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/add.jl#L124-L127

Added lines #L124 - L127 were not covered by tests
8 changes: 4 additions & 4 deletions src/padded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@

for op in (:+, :-)
@eval begin
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)},<:Union{PaddedColumns,PaddedLayout}}) = Val(true)
simplifiable(M::Mul{<:DualLayout{<:PaddedRows},<:BroadcastLayout{typeof($op)}}) = Val(true)
copy(M::Mul{Lay,<:Union{PaddedColumns,PaddedLayout}}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
copy(M::Mul{<:DualLayout{<:PaddedRows},Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{UnknownLayout,Lay}(M.A, M.B))
simplifiable(M::Mul{BroadcastLayout{typeof($op)},<:Union{PaddedColumns,PaddedLayout}}) = Val(true)
simplifiable(M::Mul{<:DualLayout{<:PaddedRows},BroadcastLayout{typeof($op)}}) = Val(true)
copy(M::Mul{BroadcastLayout{typeof($op)},<:Union{PaddedColumns,PaddedLayout}}) = copy(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
copy(M::Mul{<:DualLayout{<:PaddedRows},BroadcastLayout{typeof($op)}}) = copy(Mul{UnknownLayout,BroadcastLayout{typeof($op)}}(M.A, M.B))

Check warning on line 531 in src/padded.jl

View check run for this annotation

Codecov / codecov/patch

src/padded.jl#L528-L531

Added lines #L528 - L531 were not covered by tests
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/addtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ import LazyArrays: Add, AddArray, MulAdd, materialize!, MemoryLayout, ApplyLayou
@test B*D ≈ simplify(Mul(B,D)) ≈ Matrix(B)*D
@test D*B ≈ simplify(Mul(D,B)) ≈ D*Matrix(B)
end

@testset "Add * Mul" begin
A = randn(5,5)
B = BroadcastArray(+, A, 2A)
C = BroadcastArray(-, A, 2A)
M = ApplyArray(*, A, A)
@test B*M ≈ Matrix(B)*M
@test C*M ≈ Matrix(C)*M
@test M*B ≈ M*Matrix(B)
@test M*C ≈ M*Matrix(C)
@test simplifiable(*,B,M) == simplifiable(*,C,M) == Val(true)
@test simplifiable(*,M,B) == simplifiable(*,M,C) == Val(true)
end
end
end # testset

Expand Down
Loading