Skip to content

Commit 8bf603d

Browse files
Fix dimensions for row view of a vcat (#388)
* Clearer sublayout for concat * special case for row view of Vcat * Add a test * Case where k is not in args range * v2.9.2 --------- Co-authored-by: Daniel VandenHeuvel <[email protected]>
1 parent aa47b65 commit 8bf603d

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LazyArrays"
22
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
3-
version = "2.9.1"
3+
version = "2.9.2"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/lazyconcat.jl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,16 @@ end
791791
# subarrays
792792
###
793793

794-
sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{Vararg{Union{AbstractRange{Int},Int}}}}) = ApplyLayout{typeof(vcat)}()
795-
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Vararg{Union{AbstractRange{Int},Int}}}}) = ApplyLayout{typeof(hcat)}()
794+
sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{AbstractRange{Int}}}) = ApplyLayout{typeof(vcat)}()
795+
sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{AbstractRange{Int},Int}}) = ApplyLayout{typeof(vcat)}()
796+
sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{AbstractRange{Int},AbstractRange{Int}}}) = ApplyLayout{typeof(vcat)}()
797+
sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{Int,AbstractRange{Int}}}) = ApplyLayout{typeof(vcat)}() # a Vcat but with only 1 argument
798+
799+
796800
# a row-slice of an Hcat is equivalent to a Vcat
797801
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Int,AbstractRange{Int}}}) = ApplyLayout{typeof(vcat)}()
802+
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{AbstractRange{Int},Int}}) = ApplyLayout{typeof(hcat)}()
803+
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{AbstractRange{Int},AbstractRange{Int}}}) = ApplyLayout{typeof(hcat)}()
798804

799805
_vcat_lastinds(sz) = _vcat_cumsum(sz...)
800806
_vcat_firstinds(sz) = (1, (1 .+ Base.front(_vcat_lastinds(sz)))...)
@@ -816,13 +822,25 @@ function _vcat_sub_arguments(lay::ApplyLayout{typeof(vcat)}, A, V, kr)
816822
_reverse_if_neg_step(map(_view_vcat, arguments(lay, A), skr2), kr)
817823
end
818824

819-
function _vcat_sub_arguments(::ApplyLayout{typeof(vcat)}, A, V, kr, jr)
820-
sz = size.(arguments(A),1)
825+
function _vcat_sub_arguments(lay::ApplyLayout{typeof(vcat)}, A, V, kr, jr)
826+
sz = size.(arguments(lay, A),1)
821827
skr = intersect.(_argsindices(sz), Ref(kr))
822828
skr2 = broadcast((a,b) -> a .- b .+ 1, skr, _vcat_firstinds(sz))
823829
_reverse_if_neg_step(_view_vcat.(arguments(A), skr2, Ref(jr)), kr)
824830
end
825831

832+
function _vcat_sub_arguments(lay::ApplyLayout{typeof(vcat)}, A, V, k::Int, jr)
833+
args = arguments(lay, A)
834+
sz = size.(args,1)
835+
for (a,inds, firstind) in zip(args, _argsindices(sz), _vcat_firstinds(sz))
836+
if k in inds
837+
return (_view_vcat(a, k - firstind + 1, jr),)
838+
end
839+
end
840+
841+
() # no args
842+
end
843+
826844
_vcat_sub_arguments(LAY::ApplyLayout{typeof(vcat)}, A, V) = _vcat_sub_arguments(LAY, A, V, parentindices(V)...)
827845

828846

test/concattests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,18 @@ import LazyArrays: MemoryLayout, DenseColumnMajor, materialize!, call, paddeddat
698698
@test copy(view(V,2:-1:1,1:-1:1)) == [2 ; 1 ;;]
699699
@test copy(view(H,1:-1:1,2:-1:1)) == [2 1]
700700
end
701+
702+
@testset "Vcat arguments with integer-range view" begin
703+
A = Vcat([1, 2, 3, 4, 5]', [6, 7, 8, 9, 10]')
704+
V = view(A, 1, 1:3)
705+
args = arguments(V)
706+
@test length(args) == 1
707+
@test args[1] == [1, 2, 3]
708+
@test args[1] isa SubArray{Int, 1, Vector{Int}}
709+
710+
args = LazyArrays._vcat_sub_arguments(MemoryLayout(V), V, (), 0, 1:3)
711+
@test args == ()
712+
end
701713
end
702714

703715
end # module

0 commit comments

Comments
 (0)