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/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/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) 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/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₁...) 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