From 5ad19b3d2ec8c80e7fca6948291cbab960c6212b Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Mon, 1 May 2023 14:32:43 +0100 Subject: [PATCH 1/3] Simplify combine_apply_style --- Project.toml | 2 +- src/lazyapplying.jl | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 83a3b726..2b0178d9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "LazyArrays" uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02" -version = "1.0.1" +version = "1.0.2" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/lazyapplying.jl b/src/lazyapplying.jl index 5c6b87ae..beb05521 100644 --- a/src/lazyapplying.jl +++ b/src/lazyapplying.jl @@ -64,14 +64,7 @@ call(_, a) = a.f Applied{Style}(A.f, map(instantiate, A.args)) end -@inline _typesof() = () -@inline _typesof(a, b...) = tuple(typeof(a), _typesof(b...)...) -@inline _typesof(a, b) = tuple(typeof(a), typeof(b)) -@inline _typesof(a, b, c) = tuple(typeof(a), typeof(b), typeof(c)) -@inline combine_apply_style(f) = DefaultApplyStyle() -@inline combine_apply_style(f, a...) = ApplyStyle(f, _typesof(a...)...) -@inline combine_apply_style(f, a, b) = ApplyStyle(f, typeof(a), typeof(b)) -@inline combine_apply_style(f, a, b, c) = ApplyStyle(f, typeof(a), typeof(b), typeof(c)) +@inline @generated combine_apply_style(f, a...) = Expr(:call, :ApplyStyle, :f, a...) @inline Applied(f, args...) = Applied{typeof(combine_apply_style(f, args...))}(f, args) From deac990d34444e4827caa81136e12ddc03e5260b Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Mon, 1 May 2023 21:42:34 +0100 Subject: [PATCH 2/3] Add diagonal * padded --- src/LazyArrays.jl | 2 +- src/lazybroadcasting.jl | 7 +++---- src/padded.jl | 10 +++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/LazyArrays.jl b/src/LazyArrays.jl index ca01fcf3..c7e361c0 100644 --- a/src/LazyArrays.jl +++ b/src/LazyArrays.jl @@ -53,7 +53,7 @@ import ArrayLayouts: MatMulVecAdd, MatMulMatAdd, MulAdd, Lmul, Rmul, Ldiv, Dot, adjointlayout, sub_materialize, mulreduce, check_mul_axes, _mul_eltype, check_ldiv_axes, ldivaxes, colsupport, rowsupport, _fill_lmul!, scalarone, scalarzero, fillzeros, zero!, layout_getindex, _copyto!, - AbstractQLayout, StridedLayout, layout_replace_in_print_matrix + AbstractQLayout, StridedLayout, layout_replace_in_print_matrix, diagonaldata import Base: require_one_based_indexing, oneto diff --git a/src/lazybroadcasting.jl b/src/lazybroadcasting.jl index 6ec9b89e..5e5a2343 100644 --- a/src/lazybroadcasting.jl +++ b/src/lazybroadcasting.jl @@ -20,7 +20,7 @@ struct BroadcastLayout{F} <: AbstractLazyLayout end function _copyto!(_, ::BroadcastLayout, dest::AbstractArray{<:Any,N}, bc::AbstractArray{<:Any,N}) where N - materialize!(dest, _broadcastarray2broadcasted(bc)) + materialize!(dest, _broadcastarray2broadcasted(MemoryLayout(bc), bc)) dest end @@ -66,14 +66,13 @@ BroadcastVector(A::BroadcastVector) = A BroadcastMatrix(A::BroadcastMatrix) = A @inline __broadcastarray2broadcasted() = () -@inline __broadcastarray2broadcasted(a, b...) = tuple(_broadcastarray2broadcasted(a), __broadcastarray2broadcasted(b...)...) +@inline __broadcastarray2broadcasted(a, b...) = tuple(_broadcastarray2broadcasted(MemoryLayout(a), a), __broadcastarray2broadcasted(b...)...) @inline _broadcastarray2broadcasted(lay::BroadcastLayout, a) = broadcasted(call(lay, a), __broadcastarray2broadcasted(arguments(lay, a)...)...) @inline _broadcastarray2broadcasted(lay::BroadcastLayout, a::BroadcastArray) = broadcasted(call(lay, a), __broadcastarray2broadcasted(arguments(lay, a)...)...) @inline _broadcastarray2broadcasted(_, a) = a @inline _broadcastarray2broadcasted(lay, a::BroadcastArray) = error("Overload LazyArrays._broadcastarray2broadcasted(::$(lay), _)") @inline _broadcastarray2broadcasted(::DualLayout{ML}, a) where ML = _broadcastarray2broadcasted(ML(), a) -@inline _broadcastarray2broadcasted(a) = _broadcastarray2broadcasted(MemoryLayout(a), a) -@inline _broadcasted(A) = instantiate(_broadcastarray2broadcasted(A)) +@inline _broadcasted(A) = instantiate(_broadcastarray2broadcasted(MemoryLayout(A), A)) broadcasted(A::BroadcastArray) = _broadcasted(A) broadcasted(A::SubArray{<:Any,N,<:BroadcastArray}) where N = _broadcasted(A) Broadcasted(A::BroadcastArray) = broadcasted(A)::Broadcasted diff --git a/src/padded.jl b/src/padded.jl index e21735c8..49353696 100644 --- a/src/padded.jl +++ b/src/padded.jl @@ -424,7 +424,15 @@ function layout_replace_in_print_matrix(::PaddedLayout{Lay}, f::AbstractVecOrMat end # avoid ambiguity in LazyBandedMatrices -copy(M::Mul{<:DiagonalLayout,<:PaddedLayout}) = copy(Lmul(M)) +function copy(M::Mul{<:DiagonalLayout,<:PaddedLayout}) + d,P = diagonaldata(M.A), paddeddata(M.B) + PaddedArray(Diagonal(d[axes(P,1)]) * P, size(M.B)...) +end + +function copy(M::Mul{<:PaddedLayout,<:DiagonalLayout}) + P,d = paddeddata(M.A),diagonaldata(M.B) + PaddedArray(P * Diagonal(d[axes(P,1)]), size(M.A)...) +end From bbdf2157a6f30c1e434d58987a629b0d03f53726 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Tue, 2 May 2023 21:44:51 +0100 Subject: [PATCH 3/3] Update inv.jl --- src/linalg/inv.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/linalg/inv.jl b/src/linalg/inv.jl index 41b1cc43..bfa8590e 100644 --- a/src/linalg/inv.jl +++ b/src/linalg/inv.jl @@ -115,6 +115,7 @@ end @inline copy(L::Ldiv{<:Any,ApplyLayout{typeof(*)}}) = _copy_ldiv_mul(L.A, arguments(ApplyLayout{typeof(*)}(), L.B)...) @inline copy(L::Ldiv{<:AbstractLazyLayout,ApplyLayout{typeof(*)}}) = _copy_ldiv_mul(L.A, arguments(ApplyLayout{typeof(*)}(), L.B)...) @inline copy(L::Ldiv{ApplyLayout{typeof(*)},ApplyLayout{typeof(*)}}) = _copy_ldiv_mul(L.A, arguments(ApplyLayout{typeof(*)}(), L.B)...) +@inline copy(L::Ldiv{ApplyLayout{typeof(/)},ApplyLayout{typeof(*)}}) = _copy_ldiv_mul(L.A, arguments(ApplyLayout{typeof(*)}(), L.B)...) @inline _copy_ldiv_ldiv(B, A₀) = A₀ \ B @inline _copy_ldiv_ldiv(B, A₀, A₁...) = _copy_ldiv_ldiv(A₀ \ B, A₁...)