JuliennedArrays.jl

JuliennedArrays.jl

flatten(a::AbstractArray{<:AbstractArray}, code = default_code(a))

Align an array of slices into a larger array. Code should be a tuple with an entry for each dimension of the desired output. Slices will slide into dimensions coded by :, while * indicates dimensions taken up by the container array. Each slice should be EXACTLY the same size. The default code will be * for each outer dimension followed by : for each inner dimension.

julia> using JuliennedArrays, MappedArrays

julia> code = (*, :);

julia> array = [5 6 4; 1 3 2]
2×3 Array{Int64,2}:
 5  6  4
 1  3  2

julia> f = mappedarray(sort, julienne(array, code)) |> flatten
2×3 JuliennedArrays.FlattenedArray{Int64,2,ReadonlyMappedArray{Array{Int64,1},1,JuliennedArrays.Views{SubArray{Int64,1,Array{Int64,2},Tuple{Int64,Base.OneTo{Int64}},true},1,Array{Int64,2},JuliennedArrays.JulienneIndexer{Tuple{Int64,Base.OneTo{Int64}},1,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}},Tuple{Keys.True,Keys.False}}},typeof(sort)},Tuple{Keys.True,Keys.False}}:
 4  5  6
 1  2  3

julia> collect(f)
2×3 Array{Int64,2}:
 4  5  6
 1  2  3
source
julienne(array, code)

Slice array and create views. The code should a tuple of length ndims(array), where : indicates an axis parallel to slices and * axes an axis perpendicular to slices.

julia> using JuliennedArrays

julia> array = [5 6 4; 1 3 2; 7 9 8]
3×3 Array{Int64,2}:
 5  6  4
 1  3  2
 7  9  8

julia> map(sum, julienne(array, (*, :)))
3-element Array{Int64,1}:
 15
  6
 24
source