Skip to content
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
19 changes: 19 additions & 0 deletions src/interlace.jl
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion src/lazyconcat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
Expand Down Expand Up @@ -770,7 +772,7 @@ function rowsupport(lay::ApplyLayout{typeof(hcat)}, M::AbstractArray, k)
end

include("padded.jl")

include("interlace.jl")


###
Expand Down
16 changes: 16 additions & 0 deletions test/interlacetests.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down