Skip to content

Commit 7471f3d

Browse files
author
Nicolau Leal Werneck
committed
ndim from type-inference MVP
1 parent f29d999 commit 7471f3d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

base/abstractarray.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,13 +2841,13 @@ end
28412841
catdim_(dims) = (a,b) -> cat(a,b,dims=dims)
28422842

28432843
"""
2844-
lolstack(list_of_lists; ndim=n)
2844+
lolstack(list_of_lists, [ndim=n])
28452845
28462846
Assembles a tensor of order `ndim` from a nested array-of-arrays. Vector sizes must match.
28472847
28482848
# Examples
28492849
```jldoctest
2850-
julia> lolstack([[[1,2],[3,4]], [[5,6],[7,8]]], ndim=3)
2850+
julia> lolstack([[[1,2],[3,4]], [[5,6],[7,8]]])
28512851
2×2×2 Array{Int64, 3}:
28522852
[:, :, 1] =
28532853
1 3
@@ -2857,19 +2857,24 @@ julia> lolstack([[[1,2],[3,4]], [[5,6],[7,8]]], ndim=3)
28572857
5 7
28582858
6 8
28592859
2860-
julia> a = eachcol(reshape(1:6,2,:)) |> collect
2861-
3-element Vector{SubArray{Int64, 1, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}:
2860+
julia> a = eachcol(reshape(1:6,2,:))
2861+
3-element ColumnSlices{Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}, Tuple{Base.OneTo{Int64}}, SubArray{Int64, 1, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}:
28622862
[1, 2]
28632863
[3, 4]
28642864
[5, 6]
28652865
2866-
julia> lolstack(a, ndim=2)
2866+
julia> Base.lolstack(a, ndim=2)
28672867
2×3 Matrix{Int64}:
28682868
1 3 5
28692869
2 4 6
28702870
"""
28712871
lolstack(array_of_arrays; ndim) = lolstack_(ndim, array_of_arrays)
2872-
lolstack(f, c...) = lolstack_(2, map(f, c...))
2872+
lolstack(array_of_arrays::Vector{N}) = lolstack(array_of_arrays, ndim=1)
2873+
lolstack(array_of_arrays::Vector{Vector{N}}) = lolstack(array_of_arrays, ndim=2)
2874+
lolstack(array_of_arrays::Vector{Vector{Vector{N}}}) = lolstack(array_of_arrays, ndim=3)
2875+
lolstack(array_of_arrays::Vector{Vector{Vector{Vector{N}}}}) = lolstack(array_of_arrays, ndim=4)
2876+
lolstack(array_of_arrays::Vector{Vector{Vector{Vector{Vector{N}}}}}) = lolstack(array_of_arrays, ndim=5)
2877+
lolstack(f, c...) = lolstack(map(f, c...))
28732878
function lolstack_(ndim, aoa)
28742879
if ndim == 1
28752880
aoa

base/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ export
446446
sortslices,
447447
dropdims,
448448
awfulstack,
449+
lolstack,
449450
step,
450451
stride,
451452
strides,

0 commit comments

Comments
 (0)