@@ -786,10 +786,10 @@ end
786
786
# subarrays
787
787
# ##
788
788
789
- sublayout (:: ApplyLayout{typeof(vcat)} , :: Type {<: Tuple {Vararg{Union{AbstractVector {Int},Int}}}}) = ApplyLayout {typeof(vcat)} ()
790
- sublayout (:: ApplyLayout{typeof(hcat)} , :: Type {<: Tuple {Vararg{Union{AbstractVector {Int},Int}}}}) = ApplyLayout {typeof(hcat)} ()
789
+ sublayout (:: ApplyLayout{typeof(vcat)} , :: Type {<: Tuple {Vararg{Union{AbstractRange {Int},Int}}}}) = ApplyLayout {typeof(vcat)} ()
790
+ sublayout (:: ApplyLayout{typeof(hcat)} , :: Type {<: Tuple {Vararg{Union{AbstractRange {Int},Int}}}}) = ApplyLayout {typeof(hcat)} ()
791
791
# a row-slice of an Hcat is equivalent to a Vcat
792
- sublayout (:: ApplyLayout{typeof(hcat)} , :: Type{<:Tuple{Int,AbstractVector {Int}}} ) = ApplyLayout {typeof(vcat)} ()
792
+ sublayout (:: ApplyLayout{typeof(hcat)} , :: Type{<:Tuple{Int,AbstractRange {Int}}} ) = ApplyLayout {typeof(vcat)} ()
793
793
794
794
_vcat_lastinds (sz) = _vcat_cumsum (sz... )
795
795
_vcat_firstinds (sz) = (1 , (1 .+ Base. front (_vcat_lastinds (sz))). .. )
@@ -800,18 +800,21 @@ _view_vcat(a::Number, kr) = Fill(a,length(kr))
800
800
_view_vcat (a:: Number , kr, jr) = Fill (a,length (kr), length (jr))
801
801
_view_vcat (a, kr... ) = _viewifmutable (a, kr... )
802
802
803
- function _vcat_sub_arguments (:: ApplyLayout{typeof(vcat)} , A, V, kr)
804
- sz = size .(arguments (A),1 )
803
+ _reverse_if_neg_step (args, kr:: AbstractUnitRange ) = args
804
+ _reverse_if_neg_step (args, kr:: AbstractRange ) = step (kr) ≥ 0 ? args : reverse (args)
805
+
806
+ function _vcat_sub_arguments (lay:: ApplyLayout{typeof(vcat)} , A, V, kr)
807
+ sz = size .(arguments (lay, A),1 )
805
808
skr = intersect .(_argsindices (sz), Ref (kr))
806
809
skr2 = broadcast ((a,b) -> a .- b .+ 1 , skr, _vcat_firstinds (sz))
807
- map (_view_vcat, arguments (A), skr2)
810
+ _reverse_if_neg_step ( map (_view_vcat, arguments (lay, A), skr2), kr )
808
811
end
809
812
810
813
function _vcat_sub_arguments (:: ApplyLayout{typeof(vcat)} , A, V, kr, jr)
811
814
sz = size .(arguments (A),1 )
812
815
skr = intersect .(_argsindices (sz), Ref (kr))
813
816
skr2 = broadcast ((a,b) -> a .- b .+ 1 , skr, _vcat_firstinds (sz))
814
- _view_vcat .(arguments (A), skr2, Ref (jr))
817
+ _reverse_if_neg_step ( _view_vcat .(arguments (A), skr2, Ref (jr)), kr )
815
818
end
816
819
817
820
_vcat_sub_arguments (LAY:: ApplyLayout{typeof(vcat)} , A, V) = _vcat_sub_arguments (LAY, A, V, parentindices (V)... )
@@ -824,21 +827,23 @@ function _vcat_sub_arguments(L::ApplyLayout{typeof(hcat)}, A, V)
824
827
sz = size .(args,2 )
825
828
sjr = intersect .(_argsindices (sz), Ref (jr))
826
829
sjr2 = broadcast ((a,b) -> a .- b .+ 1 , sjr, _vcat_firstinds (sz))
827
- _view_hcat .(args, k, sjr2)
830
+ _view_hcat .(_reverse_if_neg_step ( args, jr) , k, sjr2)
828
831
end
829
832
830
833
_vcat_sub_arguments (:: DualLayout{ML} , A, V) where ML = _vcat_sub_arguments (ML (), A, V)
831
834
_vcat_sub_arguments (A, V) = _vcat_sub_arguments (MemoryLayout (typeof (A)), A, V)
832
835
arguments (:: ApplyLayout{typeof(vcat)} , V:: SubArray{<:Any,1} ) = _vcat_sub_arguments (parent (V), V)
833
836
837
+
838
+
834
839
function arguments (L:: ApplyLayout{typeof(vcat)} , V:: SubArray{<:Any,2} )
835
840
A = parent (V)
836
841
args = arguments (L, A)
837
842
kr,jr = parentindices (V)
838
843
sz = size .(args,1 )
839
844
skr = intersect .(_argsindices (sz), Ref (kr))
840
845
skr2 = broadcast ((a,b) -> a .- b .+ 1 , skr, _vcat_firstinds (sz))
841
- _view_vcat .(args, skr2, Ref (jr))
846
+ _view_vcat .(_reverse_if_neg_step ( args, kr) , skr2, Ref (jr))
842
847
end
843
848
844
849
@inline _view_hcat (a:: Number , kr, jr) = Fill (a,length (kr),length (jr))
@@ -867,11 +872,11 @@ arguments(::ApplyLayout{typeof(vcat)}, V::SubArray{<:Any,2,<:Any,<:Tuple{<:Slice
867
872
arguments (:: ApplyLayout{typeof(hcat)} , V:: SubArray{<:Any,2,<:Any,<:Tuple{<:Any,<:Slice}} ) =
868
873
__view_hcat (arguments (parent (V)), parentindices (V)[1 ], :)
869
874
870
- function sub_materialize (:: ApplyLayout{typeof(vcat)} , V:: AbstractMatrix , _)
875
+ function sub_materialize (lay :: ApplyLayout{typeof(vcat)} , V:: AbstractMatrix , _)
871
876
ret = similar (V)
872
877
n = 0
873
878
_,jr = parentindices (V)
874
- for a in arguments (V)
879
+ for a in arguments (lay, V)
875
880
m = size (a,1 )
876
881
copyto! (view (ret,n+ 1 : n+ m,:), a)
877
882
n += m
0 commit comments