Skip to content

Commit

Permalink
remove cat default, keep only reduce(cat, A)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Abbott committed Oct 24, 2020
1 parent 0faf045 commit 4e10921
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1747,10 +1747,12 @@ an iterable containing several dimensions, this allows one to construct block di
matrices and their higher-dimensional analogues by simultaneously increasing several
dimensions for every new input array and putting zero blocks elsewhere.
When all input arrays are N-dimensional, `dims` has a default value of `N+1`
For a vector of arrays, `reduce(cat, A)` will stack them along a new dimension,
equivalent to `cat(A...; dims = ndims(A[1])+1)`. Like `reduce(hcat, A)` this is done
efficiently for large `A`.
!!! compat "Julia 1.6"
The default value `dims=N+1` requires at least Julia 1.6.
`reduce(cat, A)` requires at least Julia 1.6.
# Examples
```jldoctest
Expand All @@ -1768,7 +1770,7 @@ julia> cat([true], trues(2,2), trues(2,4); dims=(1,2))
0 0 0 1 1 1 1
0 0 0 1 1 1 1
julia> cat([1 1; 1 1], fill(√2,2,2), [4 8; 16 32])
julia> reduce(cat, [[1 1; 1 1], fill(√2,2,2), [4 8; 16 32]])
2×2×3 Array{Float64,3}:
[:, :, 1] =
1.0 1.0
Expand All @@ -1784,7 +1786,6 @@ julia> cat([1 1; 1 1], fill(√2,2,2), [4 8; 16 32])
```
"""
@inline cat(A...; dims) = _cat(dims, A...)
@inline cat(A::AbstractArray{<:Any,N}...; dims=N+1) where {N} = _cat(dims, A...)

_cat(catdims, A::AbstractArray{T}...) where {T} = cat_t(T, A...; dims=catdims)

Expand Down
2 changes: 1 addition & 1 deletion test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ end
for args in ([1:2], [[1, 2]], [1:2, 3:4], [[3, 4, 5], 1:3], [1:2, [3.5, 4.5]],
[[1 2; 3 4], [5 6; 7 8]])
X = reduce(cat, args)
Y = cat(args...)
Y = cat(args...; dims=ndims(args[1])+1)
@test X == Y
@test typeof(X) === typeof(Y)
end
Expand Down

0 comments on commit 4e10921

Please sign in to comment.