JuliennedArrays.jl
JuliennedArrays.True — Type.struct TrueTyped true
JuliennedArrays.False — Type.struct FalseTyped false
JuliennedArrays.Slices — Type.Slices(whole, alongs::TypedBool...)Slice whole into views.
alongs, made of True and False objects, shows which dimensions will be replaced with : when slicing.
julia> using JuliennedArrays
julia> whole = [1 2; 3 4];
julia> slices = Slices(whole, False(), True())
2-element Slices{SubArray{Int64,1,Array{Int64,2},Tuple{Int64,Base.OneTo{Int64}},true},1,Array{Int64,2},Tuple{False,True}}:
[1, 2]
[3, 4]
julia> slices[1] == whole[1, :]
true
julia> slices[1] = [2, 1];
julia> whole
2×2 Array{Int64,2}:
2 1
3 4
julia> larger = rand(5, 5, 5);
julia> larger_slices = Slices(larger, True(), False(), False());
julia> size(first(larger_slices))
(5,)Slices(whole, alongs::Int...)Alternative syntax: alongs is which dimensions will be replaced with : when slicing.
julia> using JuliennedArrays
julia> input = reshape(1:8, 2, 2, 2)
2×2×2 reshape(::UnitRange{Int64}, 2, 2, 2) with eltype Int64:
[:, :, 1] =
1 3
2 4
[:, :, 2] =
5 7
6 8
julia> Slices(input, 1, 3)
2-element Slices{SubArray{Int64,2,Base.ReshapedArray{Int64,3,UnitRange{Int64},Tuple{}},Tuple{Base.OneTo{Int64},Int64,Base.OneTo{Int64}},false},1,Base.ReshapedArray{Int64,3,UnitRange{Int64},Tuple{}},Tuple{True,False,True}}:
[1 5; 2 6]
[3 7; 4 8]JuliennedArrays.Align — Type.Align(slices, alongs::TypedBool...)Align an array of arrays, all with the same size.
alongs, made of True and False objects, shows which dimensions will be taken up by the inner arrays. Inverse of Slices.
julia> using JuliennedArrays
julia> slices = [[1, 2], [3, 4]];
julia> aligned = Align(slices, False(), True())
2×2 Align{Int64,2,Array{Array{Int64,1},1},Tuple{False,True}}:
1 2
3 4
julia> aligned[1, :] == slices[1]
true
julia> aligned[1, 1] = 0;
julia> slices
2-element Array{Array{Int64,1},1}:
[0, 2]
[3, 4]Along(slices, alongs::Int...)Alternative syntax: alongs is which dimensions will be taken up by the inner arrays.
julia> using JuliennedArrays
julia> input = reshape(1:8, 2, 2, 2)
2×2×2 reshape(::UnitRange{Int64}, 2, 2, 2) with eltype Int64:
[:, :, 1] =
1 3
2 4
[:, :, 2] =
5 7
6 8
julia> slices = collect(Slices(input, 1, 3))
2-element Array{SubArray{Int64,2,Base.ReshapedArray{Int64,3,UnitRange{Int64},Tuple{}},Tuple{Base.OneTo{Int64},Int64,Base.OneTo{Int64}},false},1}:
[1 5; 2 6]
[3 7; 4 8]
julia> Align(slices, 1, 3)
2×2×2 Align{Int64,3,Array{SubArray{Int64,2,Base.ReshapedArray{Int64,3,UnitRange{Int64},Tuple{}},Tuple{Base.OneTo{Int64},Int64,Base.OneTo{Int64}},false},1},Tuple{True,False,True}}:
[:, :, 1] =
1 3
2 4
[:, :, 2] =
5 7
6 8