From 5a922fadfef083b83d983ac84f49a4460baa42ab Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 13 Jul 2023 14:24:30 -0400 Subject: [PATCH] improve cat design / performance (#49322) This used to make a lot of references to design issues with the SparseArrays package (https://github.com/JuliaLang/julia/issues/2326 / https://github.com/JuliaLang/julia/pull/20815), which result in a non-sensical dispatch arrangement, and contribute to a slow loading experience do to the nonsense Unions that must be checked by subtyping. --- base/abstractarray.jl | 50 +++++++++---------- base/array.jl | 12 ----- .../md5 | 1 - .../sha512 | 1 - .../md5 | 1 + .../sha512 | 1 + stdlib/LinearAlgebra/src/special.jl | 26 ++-------- stdlib/LinearAlgebra/src/uniformscaling.jl | 14 +++--- stdlib/SparseArrays.version | 2 +- test/abstractarray.jl | 50 +++++++++---------- 10 files changed, 63 insertions(+), 95 deletions(-) delete mode 100644 deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/md5 delete mode 100644 deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/sha512 create mode 100644 deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/md5 create mode 100644 deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/sha512 diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 1417987847ec4..cfc5078cb005e 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1651,7 +1651,7 @@ function _typed_hcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T for j = 1:nargs Aj = A[j] if size(Aj, 1) != nrows - throw(ArgumentError("number of rows of each array must match (got $(map(x->size(x,1), A)))")) + throw(DimensionMismatch("number of rows of each array must match (got $(map(x->size(x,1), A)))")) end dense &= isa(Aj,Array) nd = ndims(Aj) @@ -1686,7 +1686,7 @@ function _typed_vcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T ncols = size(A[1], 2) for j = 2:nargs if size(A[j], 2) != ncols - throw(ArgumentError("number of columns of each array must match (got $(map(x->size(x,2), A)))")) + throw(DimensionMismatch("number of columns of each array must match (got $(map(x->size(x,2), A)))")) end end B = similar(A[1], T, nrows, ncols) @@ -1984,16 +1984,14 @@ julia> cat(1, [2], [3;;]; dims=Val(2)) # The specializations for 1 and 2 inputs are important # especially when running with --inline=no, see #11158 -# The specializations for Union{AbstractVecOrMat,Number} are necessary -# to have more specialized methods here than in LinearAlgebra/uniformscaling.jl vcat(A::AbstractArray) = cat(A; dims=Val(1)) vcat(A::AbstractArray, B::AbstractArray) = cat(A, B; dims=Val(1)) vcat(A::AbstractArray...) = cat(A...; dims=Val(1)) -vcat(A::Union{AbstractVecOrMat,Number}...) = cat(A...; dims=Val(1)) +vcat(A::Union{AbstractArray,Number}...) = cat(A...; dims=Val(1)) hcat(A::AbstractArray) = cat(A; dims=Val(2)) hcat(A::AbstractArray, B::AbstractArray) = cat(A, B; dims=Val(2)) hcat(A::AbstractArray...) = cat(A...; dims=Val(2)) -hcat(A::Union{AbstractVecOrMat,Number}...) = cat(A...; dims=Val(2)) +hcat(A::Union{AbstractArray,Number}...) = cat(A...; dims=Val(2)) typed_vcat(T::Type, A::AbstractArray) = _cat_t(Val(1), T, A) typed_vcat(T::Type, A::AbstractArray, B::AbstractArray) = _cat_t(Val(1), T, A, B) @@ -2055,8 +2053,8 @@ julia> hvcat((2,2,2), a,b,c,d,e,f) == hvcat(2, a,b,c,d,e,f) true ``` """ -hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractVecOrMat...) = typed_hvcat(promote_eltype(xs...), rows, xs...) -hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractVecOrMat{T}...) where {T} = typed_hvcat(T, rows, xs...) +hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractArray...) = typed_hvcat(promote_eltype(xs...), rows, xs...) +hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractArray{T}...) where {T} = typed_hvcat(T, rows, xs...) function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat...) where T nbr = length(rows) # number of block rows @@ -2084,16 +2082,16 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat.. Aj = as[a+j-1] szj = size(Aj,2) if size(Aj,1) != szi - throw(ArgumentError("mismatched height in block row $(i) (expected $szi, got $(size(Aj,1)))")) + throw(DimensionMismatch("mismatched height in block row $(i) (expected $szi, got $(size(Aj,1)))")) end if c-1+szj > nc - throw(ArgumentError("block row $(i) has mismatched number of columns (expected $nc, got $(c-1+szj))")) + throw(DimensionMismatch("block row $(i) has mismatched number of columns (expected $nc, got $(c-1+szj))")) end out[r:r-1+szi, c:c-1+szj] = Aj c += szj end if c != nc+1 - throw(ArgumentError("block row $(i) has mismatched number of columns (expected $nc, got $(c-1))")) + throw(DimensionMismatch("block row $(i) has mismatched number of columns (expected $nc, got $(c-1))")) end r += szi a += rows[i] @@ -2115,7 +2113,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number k = 1 @inbounds for i=1:nr if nc != rows[i] - throw(ArgumentError("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))")) + throw(DimensionMismatch("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))")) end for j=1:nc a[i,j] = xs[k] @@ -2144,14 +2142,14 @@ end hvcat(rows::Tuple{Vararg{Int}}, xs::Number...) = typed_hvcat(promote_typeof(xs...), rows, xs...) hvcat(rows::Tuple{Vararg{Int}}, xs...) = typed_hvcat(promote_eltypeof(xs...), rows, xs...) # the following method is needed to provide a more specific one compared to LinearAlgebra/uniformscaling.jl -hvcat(rows::Tuple{Vararg{Int}}, xs::Union{AbstractVecOrMat,Number}...) = typed_hvcat(promote_eltypeof(xs...), rows, xs...) +hvcat(rows::Tuple{Vararg{Int}}, xs::Union{AbstractArray,Number}...) = typed_hvcat(promote_eltypeof(xs...), rows, xs...) function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...) where T nr = length(rows) nc = rows[1] for i = 2:nr if nc != rows[i] - throw(ArgumentError("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))")) + throw(DimensionMismatch("row $(i) has mismatched number of columns (expected $nc, got $(rows[i]))")) end end hvcat_fill!(Matrix{T}(undef, nr, nc), xs) @@ -2319,7 +2317,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N} Ndim += cat_size(as[i], N) nd = max(nd, cat_ndims(as[i])) for d ∈ 1:N - 1 - cat_size(as[1], d) == cat_size(as[i], d) || throw(ArgumentError("mismatched size along axis $d in element $i")) + cat_size(as[1], d) == cat_size(as[i], d) || throw(DimensionMismatch("mismatched size along axis $d in element $i")) end end @@ -2346,7 +2344,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N} nd = max(nd, cat_ndims(as[i])) for d ∈ 1:N-1 cat_size(as[i], d) == 1 || - throw(ArgumentError("all dimensions of element $i other than $N must be of length 1")) + throw(DimensionMismatch("all dimensions of element $i other than $N must be of length 1")) end end @@ -2463,7 +2461,7 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as for dd ∈ 1:N dd == d && continue if cat_size(as[startelementi], dd) != cat_size(as[i], dd) - throw(ArgumentError("incompatible shape in element $i")) + throw(DimensionMismatch("incompatible shape in element $i")) end end end @@ -2500,18 +2498,18 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as elseif currentdims[d] < outdims[d] # dimension in progress break else # exceeded dimension - throw(ArgumentError("argument $i has too many elements along axis $d")) + throw(DimensionMismatch("argument $i has too many elements along axis $d")) end end end elseif currentdims[d1] > outdims[d1] # exceeded dimension - throw(ArgumentError("argument $i has too many elements along axis $d1")) + throw(DimensionMismatch("argument $i has too many elements along axis $d1")) end end outlen = prod(outdims) elementcount == outlen || - throw(ArgumentError("mismatched number of elements; expected $(outlen), got $(elementcount)")) + throw(DimensionMismatch("mismatched number of elements; expected $(outlen), got $(elementcount)")) # copy into final array A = cat_similar(as[1], T, outdims) @@ -2572,8 +2570,8 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as:: if d == 1 || i == 1 || wasstartblock currentdims[d] += dsize elseif dsize != cat_size(as[i - 1], ad) - throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \ - expected $(cat_size(as[i - 1], ad)), got $dsize")) + throw(DimensionMismatch("argument $i has a mismatched number of elements along axis $ad; \ + expected $(cat_size(as[i - 1], ad)), got $dsize")) end wasstartblock = blockcounts[d] == 1 # remember for next dimension @@ -2583,15 +2581,15 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as:: if outdims[d] == -1 outdims[d] = currentdims[d] elseif outdims[d] != currentdims[d] - throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \ - expected $(abs(outdims[d] - (currentdims[d] - dsize))), got $dsize")) + throw(DimensionMismatch("argument $i has a mismatched number of elements along axis $ad; \ + expected $(abs(outdims[d] - (currentdims[d] - dsize))), got $dsize")) end currentdims[d] = 0 blockcounts[d] = 0 shapepos[d] += 1 d > 1 && (blockcounts[d - 1] == 0 || - throw(ArgumentError("shape in level $d is inconsistent; level counts must nest \ - evenly into each other"))) + throw(DimensionMismatch("shape in level $d is inconsistent; level counts must nest \ + evenly into each other"))) end end end diff --git a/base/array.jl b/base/array.jl index b99ec7ee2b015..d3d4750743a91 100644 --- a/base/array.jl +++ b/base/array.jl @@ -2041,18 +2041,6 @@ function vcat(arrays::Vector{T}...) where T end vcat(A::Vector...) = cat(A...; dims=Val(1)) # more special than SparseArrays's vcat -# disambiguation with LinAlg/special.jl -# Union{Number,Vector,Matrix} is for LinearAlgebra._DenseConcatGroup -# VecOrMat{T} is for LinearAlgebra._TypedDenseConcatGroup -hcat(A::Union{Number,Vector,Matrix}...) = cat(A...; dims=Val(2)) -hcat(A::VecOrMat{T}...) where {T} = typed_hcat(T, A...) -vcat(A::Union{Number,Vector,Matrix}...) = cat(A...; dims=Val(1)) -vcat(A::VecOrMat{T}...) where {T} = typed_vcat(T, A...) -hvcat(rows::Tuple{Vararg{Int}}, xs::Union{Number,Vector,Matrix}...) = - typed_hvcat(promote_eltypeof(xs...), rows, xs...) -hvcat(rows::Tuple{Vararg{Int}}, xs::VecOrMat{T}...) where {T} = - typed_hvcat(T, rows, xs...) - _cat(n::Integer, x::Integer...) = reshape([x...], (ntuple(Returns(1), n-1)..., length(x))) ## find ## diff --git a/deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/md5 b/deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/md5 deleted file mode 100644 index 21131a800d4af..0000000000000 --- a/deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/md5 +++ /dev/null @@ -1 +0,0 @@ -0369c2679e8b834009526dd4f402cfd8 diff --git a/deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/sha512 b/deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/sha512 deleted file mode 100644 index df3b4cc3736e1..0000000000000 --- a/deps/checksums/SparseArrays-2c7f4d6d839e9a97027454a037bfa004c1eb34b0.tar.gz/sha512 +++ /dev/null @@ -1 +0,0 @@ -b2573398a8e8f5bcd8195cc3aa68103b2b5ea66c1835d4bc4d808fb1e0d3fbd46cc2caa04a4f49813a4a4a7f88d2f95789fa080d1d940c0291b09416be0fd1e6 diff --git a/deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/md5 b/deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/md5 new file mode 100644 index 0000000000000..55bc533861fc0 --- /dev/null +++ b/deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/md5 @@ -0,0 +1 @@ +e59c1c57b97e17a73eba758d65022bd7 diff --git a/deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/sha512 b/deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/sha512 new file mode 100644 index 0000000000000..2213bfe87ccfc --- /dev/null +++ b/deps/checksums/SparseArrays-b4b0e721ada6e8cf5f6391aff4db307be69b0401.tar.gz/sha512 @@ -0,0 +1 @@ +ad88ebe77aaf1580e6d7ee7649ac5b812a23b9d9bf947f26babe9dd79902f6da11aa69bf63f22f67f6eae92a4c6e665cc3b950bb7c648c623e9cb4b9cb4daac4 diff --git a/stdlib/LinearAlgebra/src/special.jl b/stdlib/LinearAlgebra/src/special.jl index 22567c2a8ef96..885f29fa1417b 100644 --- a/stdlib/LinearAlgebra/src/special.jl +++ b/stdlib/LinearAlgebra/src/special.jl @@ -330,27 +330,11 @@ end ==(A::Bidiagonal, B::SymTridiagonal) = iszero(_evview(B)) && iszero(A.ev) && A.dv == B.dv ==(B::SymTridiagonal, A::Bidiagonal) = A == B -# concatenation -const _SpecialArrays = Union{Diagonal, Bidiagonal, Tridiagonal, SymTridiagonal} -const _Symmetric_DenseArrays{T,A<:Matrix} = Symmetric{T,A} -const _Hermitian_DenseArrays{T,A<:Matrix} = Hermitian{T,A} -const _Triangular_DenseArrays{T,A<:Matrix} = UpperOrLowerTriangular{T,A} -const _Annotated_DenseArrays = Union{_SpecialArrays, _Triangular_DenseArrays, _Symmetric_DenseArrays, _Hermitian_DenseArrays} -const _Annotated_Typed_DenseArrays{T} = Union{_Triangular_DenseArrays{T}, _Symmetric_DenseArrays{T}, _Hermitian_DenseArrays{T}} -const _DenseConcatGroup = Union{Number, Vector, Adjoint{<:Any,<:Vector}, Transpose{<:Any,<:Vector}, Matrix, _Annotated_DenseArrays} -const _TypedDenseConcatGroup{T} = Union{Vector{T}, Adjoint{T,Vector{T}}, Transpose{T,Vector{T}}, Matrix{T}, _Annotated_Typed_DenseArrays{T}} - -promote_to_array_type(::Tuple{Vararg{Union{_DenseConcatGroup,UniformScaling}}}) = Matrix - -Base._cat(dims, xs::_DenseConcatGroup...) = Base._cat_t(dims, promote_eltype(xs...), xs...) -vcat(A::_DenseConcatGroup...) = Base.typed_vcat(promote_eltype(A...), A...) -hcat(A::_DenseConcatGroup...) = Base.typed_hcat(promote_eltype(A...), A...) -hvcat(rows::Tuple{Vararg{Int}}, xs::_DenseConcatGroup...) = Base.typed_hvcat(promote_eltype(xs...), rows, xs...) -# For performance, specially handle the case where the matrices/vectors have homogeneous eltype -Base._cat(dims, xs::_TypedDenseConcatGroup{T}...) where {T} = Base._cat_t(dims, T, xs...) -vcat(A::_TypedDenseConcatGroup{T}...) where {T} = Base.typed_vcat(T, A...) -hcat(A::_TypedDenseConcatGroup{T}...) where {T} = Base.typed_hcat(T, A...) -hvcat(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) where {T} = Base.typed_hvcat(T, rows, xs...) +# TODO: remove these deprecations (used by SparseArrays in the past) +const _DenseConcatGroup = Union{} +const _SpecialArrays = Union{} + +promote_to_array_type(::Tuple) = Matrix # factorizations function cholesky(S::RealHermSymComplexHerm{<:Real,<:SymTridiagonal}, ::NoPivot = NoPivot(); check::Bool = true) diff --git a/stdlib/LinearAlgebra/src/uniformscaling.jl b/stdlib/LinearAlgebra/src/uniformscaling.jl index 21ae8a1bb913a..0b3168113acf7 100644 --- a/stdlib/LinearAlgebra/src/uniformscaling.jl +++ b/stdlib/LinearAlgebra/src/uniformscaling.jl @@ -408,7 +408,7 @@ end # so that we can re-use this code for sparse-matrix hcat etcetera. promote_to_arrays_(n::Int, ::Type, a::Number) = a promote_to_arrays_(n::Int, ::Type{Matrix}, J::UniformScaling{T}) where {T} = Matrix(J, n, n) -promote_to_arrays_(n::Int, ::Type, A::AbstractVecOrMat) = A +promote_to_arrays_(n::Int, ::Type, A::AbstractArray) = A promote_to_arrays(n,k, ::Type) = () promote_to_arrays(n,k, ::Type{T}, A) where {T} = (promote_to_arrays_(n[k], T, A),) promote_to_arrays(n,k, ::Type{T}, A, B) where {T} = @@ -417,17 +417,16 @@ promote_to_arrays(n,k, ::Type{T}, A, B, C) where {T} = (promote_to_arrays_(n[k], T, A), promote_to_arrays_(n[k+1], T, B), promote_to_arrays_(n[k+2], T, C)) promote_to_arrays(n,k, ::Type{T}, A, B, Cs...) where {T} = (promote_to_arrays_(n[k], T, A), promote_to_arrays_(n[k+1], T, B), promote_to_arrays(n,k+2, T, Cs...)...) -promote_to_array_type(A::Tuple{Vararg{Union{AbstractVecOrMat,UniformScaling,Number}}}) = Matrix _us2number(A) = A _us2number(J::UniformScaling) = J.λ for (f, _f, dim, name) in ((:hcat, :_hcat, 1, "rows"), (:vcat, :_vcat, 2, "cols")) @eval begin - @inline $f(A::Union{AbstractVecOrMat,UniformScaling}...) = $_f(A...) + @inline $f(A::Union{AbstractArray,UniformScaling}...) = $_f(A...) # if there's a Number present, J::UniformScaling must be 1x1-dimensional - @inline $f(A::Union{AbstractVecOrMat,UniformScaling,Number}...) = $f(map(_us2number, A)...) - function $_f(A::Union{AbstractVecOrMat,UniformScaling,Number}...; array_type = promote_to_array_type(A)) + @inline $f(A::Union{AbstractArray,UniformScaling,Number}...) = $f(map(_us2number, A)...) + function $_f(A::Union{AbstractArray,UniformScaling,Number}...; array_type = promote_to_array_type(A)) n = -1 for a in A if !isa(a, UniformScaling) @@ -445,9 +444,8 @@ for (f, _f, dim, name) in ((:hcat, :_hcat, 1, "rows"), (:vcat, :_vcat, 2, "cols" end end -hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractVecOrMat,UniformScaling}...) = _hvcat(rows, A...) -hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractVecOrMat,UniformScaling,Number}...) = _hvcat(rows, A...) -function _hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractVecOrMat,UniformScaling,Number}...; array_type = promote_to_array_type(A)) +hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractArray,UniformScaling,Number}...) = _hvcat(rows, A...) +function _hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractArray,UniformScaling,Number}...; array_type = promote_to_array_type(A)) require_one_based_indexing(A...) nr = length(rows) sum(rows) == length(A) || throw(ArgumentError("mismatch between row sizes and number of arguments")) diff --git a/stdlib/SparseArrays.version b/stdlib/SparseArrays.version index b29ce9b0306e1..4290a1d2fc4ca 100644 --- a/stdlib/SparseArrays.version +++ b/stdlib/SparseArrays.version @@ -1,4 +1,4 @@ SPARSEARRAYS_BRANCH = main -SPARSEARRAYS_SHA1 = 2c7f4d6d839e9a97027454a037bfa004c1eb34b0 +SPARSEARRAYS_SHA1 = b4b0e721ada6e8cf5f6391aff4db307be69b0401 SPARSEARRAYS_GIT_URL := https://github.com/JuliaSparse/SparseArrays.jl.git SPARSEARRAYS_TAR_URL = https://api.github.com/repos/JuliaSparse/SparseArrays.jl/tarball/$1 diff --git a/test/abstractarray.jl b/test/abstractarray.jl index b4b0044e8a9cc..47a81bbbf5b66 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -693,8 +693,8 @@ function test_cat(::Type{TestAbstractArray}) @test hcat() == Any[] @test vcat(1, 1.0, 3, 3.0) == [1.0, 1.0, 3.0, 3.0] @test hcat(1, 1.0, 3, 3.0) == [1.0 1.0 3.0 3.0] - @test_throws ArgumentError hcat(B1, B2) - @test_throws ArgumentError vcat(C1, C2) + @test_throws DimensionMismatch hcat(B1, B2) + @test_throws DimensionMismatch vcat(C1, C2) @test vcat(B) == B @test hcat(B) == B @@ -723,9 +723,9 @@ function test_cat(::Type{TestAbstractArray}) end @test_throws ArgumentError hvcat(7, 1:20...) - @test_throws ArgumentError hvcat((2), C1, C3) - @test_throws ArgumentError hvcat((1), C1, C2) - @test_throws ArgumentError hvcat((1), C2, C3) + @test_throws DimensionMismatch hvcat((2), C1, C3) + @test_throws DimensionMismatch hvcat((1), C1, C2) + @test_throws DimensionMismatch hvcat((1), C2, C3) tup = tuple(rand(1:10, i)...) @test hvcat(tup) == [] @@ -734,8 +734,8 @@ function test_cat(::Type{TestAbstractArray}) @test_throws ArgumentError hvcat((2, 2), 1, 2, 3, 4, 5) @test_throws ArgumentError Base.typed_hvcat(Int, (2, 2), 1, 2, 3, 4, 5) # check for # of columns mismatch b/w rows - @test_throws ArgumentError hvcat((3, 2), 1, 2, 3, 4, 5, 6) - @test_throws ArgumentError Base.typed_hvcat(Int, (3, 2), 1, 2, 3, 4, 5, 6) + @test_throws DimensionMismatch hvcat((3, 2), 1, 2, 3, 4, 5, 6) + @test_throws DimensionMismatch Base.typed_hvcat(Int, (3, 2), 1, 2, 3, 4, 5, 6) # 18395 @test isa(Any["a" 5; 2//3 1.0][2,1], Rational{Int}) @@ -1354,7 +1354,7 @@ end @test Int[t...; 3 4] == [1 2; 3 4] @test Int[0 t...; t... 0] == [0 1 2; 1 2 0] - @test_throws ArgumentError Int[t...; 3 4 5] + @test_throws DimensionMismatch Int[t...; 3 4 5] end @testset "issue #39896, modified getindex " begin @@ -1408,15 +1408,15 @@ using Base: typed_hvncat @test [1;;] == fill(1, (1,1)) for v in (1, fill(1), fill(1,1,1), fill(1, 1, 1, 1)) - @test_throws ArgumentError [v; v;; v] - @test_throws ArgumentError [v; v;; v; v; v] - @test_throws ArgumentError [v; v; v;; v; v] - @test_throws ArgumentError [v; v;; v; v;;; v; v;; v; v;; v; v] - @test_throws ArgumentError [v; v;; v; v;;; v; v] - @test_throws ArgumentError [v; v;; v; v;;; v; v; v;; v; v] - @test_throws ArgumentError [v; v;; v; v;;; v; v;; v; v; v] + @test_throws DimensionMismatch [v; v;; v] + @test_throws DimensionMismatch [v; v;; v; v; v] + @test_throws DimensionMismatch [v; v; v;; v; v] + @test_throws DimensionMismatch [v; v;; v; v;;; v; v;; v; v;; v; v] + @test_throws DimensionMismatch [v; v;; v; v;;; v; v] + @test_throws DimensionMismatch [v; v;; v; v;;; v; v; v;; v; v] + @test_throws DimensionMismatch [v; v;; v; v;;; v; v;; v; v; v] # ensure a wrong shape with the right number of elements doesn't pass through - @test_throws ArgumentError [v; v;; v; v;;; v; v; v; v] + @test_throws DimensionMismatch [v; v;; v; v;;; v; v; v; v] @test [v; v;; v; v] == fill(1, ndims(v) == 3 ? (2, 2, 1) : (2,2)) @test [v; v;; v; v;;;] == fill(1, 2, 2, 1) @@ -1484,7 +1484,7 @@ using Base: typed_hvncat end # reject shapes that don't nest evenly between levels (e.g. 1 + 2 does not fit into 2) - @test_throws ArgumentError hvncat(((1, 2, 1), (2, 2), (4,)), true, [1 2], [3], [4], [1 2; 3 4]) + @test_throws DimensionMismatch hvncat(((1, 2, 1), (2, 2), (4,)), true, [1 2], [3], [4], [1 2; 3 4]) # zero-length arrays are handled appropriately @test [zeros(Int, 1, 2, 0) ;;; 1 3] == [1 3;;;] @@ -1499,18 +1499,18 @@ using Base: typed_hvncat for v1 ∈ (zeros(Int, 0, 0), zeros(Int, 0, 0, 0, 0), zeros(Int, 0, 0, 0, 0, 0, 0, 0)) for v2 ∈ (1, [1]) for v3 ∈ (2, [2]) - @test_throws ArgumentError [v1 ;;; v2] - @test_throws ArgumentError [v1 ;;; v2 v3] - @test_throws ArgumentError [v1 v1 ;;; v2 v3] + @test_throws DimensionMismatch [v1 ;;; v2] + @test_throws DimensionMismatch [v1 ;;; v2 v3] + @test_throws DimensionMismatch [v1 v1 ;;; v2 v3] end end end v1 = zeros(Int, 0, 0, 0) for v2 ∈ (1, [1]) for v3 ∈ (2, [2]) - @test_throws ArgumentError [v1 ;;; v2 v3] - @test_throws ArgumentError [v1 ;;; v2] - @test_throws ArgumentError [v1 v1 ;;; v2 v3] + @test_throws DimensionMismatch [v1 ;;; v2 v3] + @test_throws DimensionMismatch [v1 ;;; v2] + @test_throws DimensionMismatch [v1 v1 ;;; v2 v3] end end @@ -1578,8 +1578,8 @@ using Base: typed_hvncat @test Array{Int, 3}(undef, 0, 0, 0) == typed_hvncat(Int, 3) isa Array{Int, 3} # Issue 43933 - semicolon precedence mistake should produce an error - @test_throws ArgumentError [[1 1]; 2 ;; 3 ; [3 4]] - @test_throws ArgumentError [[1 ;;; 1]; 2 ;;; 3 ; [3 ;;; 4]] + @test_throws DimensionMismatch [[1 1]; 2 ;; 3 ; [3 4]] + @test_throws DimensionMismatch [[1 ;;; 1]; 2 ;;; 3 ; [3 ;;; 4]] @test [[1 2; 3 4] [5; 6]; [7 8] 9;;;] == [1 2 5; 3 4 6; 7 8 9;;;]