From 4e1092100698ed6c4162b1cafb469097a83dc60d Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Sat, 24 Oct 2020 17:52:48 +0200 Subject: [PATCH] remove cat default, keep only reduce(cat, A) --- base/abstractarray.jl | 9 +++++---- test/reduce.jl | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 6810a69162b9c..80f2b5f9ff00e 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -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 @@ -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 @@ -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) diff --git a/test/reduce.jl b/test/reduce.jl index cd1bb32507511..aa555f2bbe076 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -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