diff --git a/src/interlace.jl b/src/interlace.jl new file mode 100644 index 00000000..46bb5f45 --- /dev/null +++ b/src/interlace.jl @@ -0,0 +1,19 @@ +struct InterlaceLayout end + +reshapedlayout(::ApplyLayout{typeof(vcat)}, _) = InterlaceLayout() +function arguments(::InterlaceLayout, A::ReshapedArray) + args = arguments(ApplyLayout{typeof(Vcat)}(), parent(A)) + map(_permutedims, args) +end + +function _copyto!(_, ::InterlaceLayout, dest::AbstractVector, A::AbstractVector) + args = arguments(InterlaceLayout(), A) + _interlace_copyto!(1, length(args), dest, args...) +end + +function _interlace_copyto!(k, st, dest, a, b...) + copyto!(view(dest, k:st:length(dest)), a) + _interlace_copyto!(k+1, st, dest, b...) +end + +_interlace_copyto!(k, st, dest) = dest \ No newline at end of file diff --git a/src/lazyconcat.jl b/src/lazyconcat.jl index 9c73fe27..adf8d853 100644 --- a/src/lazyconcat.jl +++ b/src/lazyconcat.jl @@ -463,6 +463,8 @@ copy(f::Transpose{<:Any,<:Union{Vcat,Hcat}}) = transpose(copy(parent(f))) _permutedims(a) = a _permutedims(a::AbstractArray) = permutedims(a) +_permutedims(a::Transpose{<:Number}) = parent(a) +_permutedims(a::Adjoint{<:Real}) = parent(a) permutedims(A::Hcat{T}) where T = Vcat{T}(map(_permutedims,A.args)...) permutedims(A::Vcat{T}) where T = Hcat{T}(map(_permutedims,A.args)...) @@ -770,7 +772,7 @@ function rowsupport(lay::ApplyLayout{typeof(hcat)}, M::AbstractArray, k) end include("padded.jl") - +include("interlace.jl") ### diff --git a/test/interlacetests.jl b/test/interlacetests.jl new file mode 100644 index 00000000..a12b148e --- /dev/null +++ b/test/interlacetests.jl @@ -0,0 +1,16 @@ +using LazyArrays, ArrayLayouts, Test +import LazyArrays: InterlaceLayout, arguments + +@testset "Interlace" begin + n = 10 + a = 1:n + b = n+1:2n + A = Vcat(a', b') + v = vec(A) + @test MemoryLayout(v) isa InterlaceLayout + @test arguments(v) == (a,b) + @test ArrayLayouts._copyto!(zeros(2n), v) == vec(Matrix(A)) + + v = view(A, 1:2n) + MemoryLayout(v) +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index b5e92dbe..90b76eb5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -53,6 +53,7 @@ include("macrotests.jl") include("lazymultests.jl") include("concattests.jl") include("paddedtests.jl") +include("interlacetests.jl") include("broadcasttests.jl") include("cachetests.jl")