Skip to content

Commit

Permalink
Update lazyconcat.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Dec 6, 2024
1 parent 6d3969a commit 89aa42f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/lazyconcat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,10 @@ end
# subarrays
###

sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{Vararg{Union{AbstractUnitRange{Int},Int}}}}) = ApplyLayout{typeof(vcat)}()
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Vararg{Union{AbstractUnitRange{Int},Int}}}}) = ApplyLayout{typeof(hcat)}()
sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{Vararg{Union{AbstractRange{Int},Int}}}}) = ApplyLayout{typeof(vcat)}()
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Vararg{Union{AbstractRange{Int},Int}}}}) = ApplyLayout{typeof(hcat)}()

Check warning on line 790 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L789-L790

Added lines #L789 - L790 were not covered by tests
# a row-slice of an Hcat is equivalent to a Vcat
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Int,AbstractUnitRange{Int}}}) = ApplyLayout{typeof(vcat)}()
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Int,AbstractRange{Int}}}) = ApplyLayout{typeof(vcat)}()

Check warning on line 792 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L792

Added line #L792 was not covered by tests

_vcat_lastinds(sz) = _vcat_cumsum(sz...)
_vcat_firstinds(sz) = (1, (1 .+ Base.front(_vcat_lastinds(sz)))...)
Expand All @@ -800,18 +800,21 @@ _view_vcat(a::Number, kr) = Fill(a,length(kr))
_view_vcat(a::Number, kr, jr) = Fill(a,length(kr), length(jr))
_view_vcat(a, kr...) = _viewifmutable(a, kr...)

function _vcat_sub_arguments(::ApplyLayout{typeof(vcat)}, A, V, kr)
sz = size.(arguments(A),1)
_reverse_if_neg_step(args, kr::AbstractUnitRange) = args
_reverse_if_neg_step(args, kr::AbstractRange) = step(kr) 0 ? args : reverse(args)

Check warning on line 804 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L803-L804

Added lines #L803 - L804 were not covered by tests

function _vcat_sub_arguments(lay::ApplyLayout{typeof(vcat)}, A, V, kr)
sz = size.(arguments(lay, A),1)

Check warning on line 807 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L806-L807

Added lines #L806 - L807 were not covered by tests
skr = intersect.(_argsindices(sz), Ref(kr))
skr2 = broadcast((a,b) -> a .- b .+ 1, skr, _vcat_firstinds(sz))
map(_view_vcat, arguments(A), skr2)
_reverse_if_neg_step(map(_view_vcat, arguments(lay, A), skr2), kr)

Check warning on line 810 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L810

Added line #L810 was not covered by tests
end

function _vcat_sub_arguments(::ApplyLayout{typeof(vcat)}, A, V, kr, jr)
sz = size.(arguments(A),1)
skr = intersect.(_argsindices(sz), Ref(kr))
skr2 = broadcast((a,b) -> a .- b .+ 1, skr, _vcat_firstinds(sz))
_view_vcat.(arguments(A), skr2, Ref(jr))
_reverse_if_neg_step(_view_vcat.(arguments(A), skr2, Ref(jr)), kr)

Check warning on line 817 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L817

Added line #L817 was not covered by tests
end

_vcat_sub_arguments(LAY::ApplyLayout{typeof(vcat)}, A, V) = _vcat_sub_arguments(LAY, A, V, parentindices(V)...)
Expand All @@ -824,21 +827,23 @@ function _vcat_sub_arguments(L::ApplyLayout{typeof(hcat)}, A, V)
sz = size.(args,2)
sjr = intersect.(_argsindices(sz), Ref(jr))
sjr2 = broadcast((a,b) -> a .- b .+ 1, sjr, _vcat_firstinds(sz))
_view_hcat.(args, k, sjr2)
_view_hcat.(_reverse_if_neg_step(args, jr), k, sjr2)

Check warning on line 830 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L830

Added line #L830 was not covered by tests
end

_vcat_sub_arguments(::DualLayout{ML}, A, V) where ML = _vcat_sub_arguments(ML(), A, V)
_vcat_sub_arguments(A, V) = _vcat_sub_arguments(MemoryLayout(typeof(A)), A, V)
arguments(::ApplyLayout{typeof(vcat)}, V::SubArray{<:Any,1}) = _vcat_sub_arguments(parent(V), V)



function arguments(L::ApplyLayout{typeof(vcat)}, V::SubArray{<:Any,2})
A = parent(V)
args = arguments(L, A)
kr,jr = parentindices(V)
sz = size.(args,1)
skr = intersect.(_argsindices(sz), Ref(kr))
skr2 = broadcast((a,b) -> a .- b .+ 1, skr, _vcat_firstinds(sz))
_view_vcat.(args, skr2, Ref(jr))
_view_vcat.(_reverse_if_neg_step(args, kr), skr2, Ref(jr))

Check warning on line 846 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L846

Added line #L846 was not covered by tests
end

@inline _view_hcat(a::Number, kr, jr) = Fill(a,length(kr),length(jr))
Expand Down

0 comments on commit 89aa42f

Please sign in to comment.