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

Simplify combine_apply_style #249

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 = "1.0.1"
version = "1.0.2"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
2 changes: 1 addition & 1 deletion src/LazyArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 1 addition & 8 deletions src/lazyapplying.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/lazybroadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linalg/inv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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₁...)
Expand Down
10 changes: 9 additions & 1 deletion src/padded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down