@@ -1651,7 +1651,7 @@ function _typed_hcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T
1651
1651
for j = 1 : nargs
1652
1652
Aj = A[j]
1653
1653
if size (Aj, 1 ) != nrows
1654
- throw (ArgumentError (" number of rows of each array must match (got $(map (x-> size (x,1 ), A)) )" ))
1654
+ throw (DimensionMismatch (" number of rows of each array must match (got $(map (x-> size (x,1 ), A)) )" ))
1655
1655
end
1656
1656
dense &= isa (Aj,Array)
1657
1657
nd = ndims (Aj)
@@ -1686,7 +1686,7 @@ function _typed_vcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T
1686
1686
ncols = size (A[1 ], 2 )
1687
1687
for j = 2 : nargs
1688
1688
if size (A[j], 2 ) != ncols
1689
- throw (ArgumentError (" number of columns of each array must match (got $(map (x-> size (x,2 ), A)) )" ))
1689
+ throw (DimensionMismatch (" number of columns of each array must match (got $(map (x-> size (x,2 ), A)) )" ))
1690
1690
end
1691
1691
end
1692
1692
B = similar (A[1 ], T, nrows, ncols)
@@ -1984,16 +1984,14 @@ julia> cat(1, [2], [3;;]; dims=Val(2))
1984
1984
1985
1985
# The specializations for 1 and 2 inputs are important
1986
1986
# especially when running with --inline=no, see #11158
1987
- # The specializations for Union{AbstractVecOrMat,Number} are necessary
1988
- # to have more specialized methods here than in LinearAlgebra/uniformscaling.jl
1989
1987
vcat (A:: AbstractArray ) = cat (A; dims= Val (1 ))
1990
1988
vcat (A:: AbstractArray , B:: AbstractArray ) = cat (A, B; dims= Val (1 ))
1991
1989
vcat (A:: AbstractArray... ) = cat (A... ; dims= Val (1 ))
1992
- vcat (A:: Union{AbstractVecOrMat ,Number} ...) = cat (A... ; dims= Val (1 ))
1990
+ vcat (A:: Union{AbstractArray ,Number} ...) = cat (A... ; dims= Val (1 ))
1993
1991
hcat (A:: AbstractArray ) = cat (A; dims= Val (2 ))
1994
1992
hcat (A:: AbstractArray , B:: AbstractArray ) = cat (A, B; dims= Val (2 ))
1995
1993
hcat (A:: AbstractArray... ) = cat (A... ; dims= Val (2 ))
1996
- hcat (A:: Union{AbstractVecOrMat ,Number} ...) = cat (A... ; dims= Val (2 ))
1994
+ hcat (A:: Union{AbstractArray ,Number} ...) = cat (A... ; dims= Val (2 ))
1997
1995
1998
1996
typed_vcat (T:: Type , A:: AbstractArray ) = _cat_t (Val (1 ), T, A)
1999
1997
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)
2055
2053
true
2056
2054
```
2057
2055
"""
2058
- hvcat (rows:: Tuple{Vararg{Int}} , xs:: AbstractVecOrMat ... ) = typed_hvcat (promote_eltype (xs... ), rows, xs... )
2059
- hvcat (rows:: Tuple{Vararg{Int}} , xs:: AbstractVecOrMat {T} ...) where {T} = typed_hvcat (T, rows, xs... )
2056
+ hvcat (rows:: Tuple{Vararg{Int}} , xs:: AbstractArray ... ) = typed_hvcat (promote_eltype (xs... ), rows, xs... )
2057
+ hvcat (rows:: Tuple{Vararg{Int}} , xs:: AbstractArray {T} ...) where {T} = typed_hvcat (T, rows, xs... )
2060
2058
2061
2059
function typed_hvcat (:: Type{T} , rows:: Tuple{Vararg{Int}} , as:: AbstractVecOrMat... ) where T
2062
2060
nbr = length (rows) # number of block rows
@@ -2084,16 +2082,16 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat..
2084
2082
Aj = as[a+ j- 1 ]
2085
2083
szj = size (Aj,2 )
2086
2084
if size (Aj,1 ) != szi
2087
- throw (ArgumentError (" mismatched height in block row $(i) (expected $szi , got $(size (Aj,1 )) )" ))
2085
+ throw (DimensionMismatch (" mismatched height in block row $(i) (expected $szi , got $(size (Aj,1 )) )" ))
2088
2086
end
2089
2087
if c- 1 + szj > nc
2090
- throw (ArgumentError (" block row $(i) has mismatched number of columns (expected $nc , got $(c- 1 + szj) )" ))
2088
+ throw (DimensionMismatch (" block row $(i) has mismatched number of columns (expected $nc , got $(c- 1 + szj) )" ))
2091
2089
end
2092
2090
out[r: r- 1 + szi, c: c- 1 + szj] = Aj
2093
2091
c += szj
2094
2092
end
2095
2093
if c != nc+ 1
2096
- throw (ArgumentError (" block row $(i) has mismatched number of columns (expected $nc , got $(c- 1 ) )" ))
2094
+ throw (DimensionMismatch (" block row $(i) has mismatched number of columns (expected $nc , got $(c- 1 ) )" ))
2097
2095
end
2098
2096
r += szi
2099
2097
a += rows[i]
@@ -2115,7 +2113,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number
2115
2113
k = 1
2116
2114
@inbounds for i= 1 : nr
2117
2115
if nc != rows[i]
2118
- throw (ArgumentError (" row $(i) has mismatched number of columns (expected $nc , got $(rows[i]) )" ))
2116
+ throw (DimensionMismatch (" row $(i) has mismatched number of columns (expected $nc , got $(rows[i]) )" ))
2119
2117
end
2120
2118
for j= 1 : nc
2121
2119
a[i,j] = xs[k]
@@ -2144,14 +2142,14 @@ end
2144
2142
hvcat (rows:: Tuple{Vararg{Int}} , xs:: Number... ) = typed_hvcat (promote_typeof (xs... ), rows, xs... )
2145
2143
hvcat (rows:: Tuple{Vararg{Int}} , xs... ) = typed_hvcat (promote_eltypeof (xs... ), rows, xs... )
2146
2144
# the following method is needed to provide a more specific one compared to LinearAlgebra/uniformscaling.jl
2147
- hvcat (rows:: Tuple{Vararg{Int}} , xs:: Union{AbstractVecOrMat ,Number} ...) = typed_hvcat (promote_eltypeof (xs... ), rows, xs... )
2145
+ hvcat (rows:: Tuple{Vararg{Int}} , xs:: Union{AbstractArray ,Number} ...) = typed_hvcat (promote_eltypeof (xs... ), rows, xs... )
2148
2146
2149
2147
function typed_hvcat (:: Type{T} , rows:: Tuple{Vararg{Int}} , xs:: Number... ) where T
2150
2148
nr = length (rows)
2151
2149
nc = rows[1 ]
2152
2150
for i = 2 : nr
2153
2151
if nc != rows[i]
2154
- throw (ArgumentError (" row $(i) has mismatched number of columns (expected $nc , got $(rows[i]) )" ))
2152
+ throw (DimensionMismatch (" row $(i) has mismatched number of columns (expected $nc , got $(rows[i]) )" ))
2155
2153
end
2156
2154
end
2157
2155
hvcat_fill! (Matrix {T} (undef, nr, nc), xs)
@@ -2319,7 +2317,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
2319
2317
Ndim += cat_size (as[i], N)
2320
2318
nd = max (nd, cat_ndims (as[i]))
2321
2319
for d ∈ 1 : N - 1
2322
- cat_size (as[1 ], d) == cat_size (as[i], d) || throw (ArgumentError (" mismatched size along axis $d in element $i " ))
2320
+ cat_size (as[1 ], d) == cat_size (as[i], d) || throw (DimensionMismatch (" mismatched size along axis $d in element $i " ))
2323
2321
end
2324
2322
end
2325
2323
@@ -2346,7 +2344,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
2346
2344
nd = max (nd, cat_ndims (as[i]))
2347
2345
for d ∈ 1 : N- 1
2348
2346
cat_size (as[i], d) == 1 ||
2349
- throw (ArgumentError (" all dimensions of element $i other than $N must be of length 1" ))
2347
+ throw (DimensionMismatch (" all dimensions of element $i other than $N must be of length 1" ))
2350
2348
end
2351
2349
end
2352
2350
@@ -2463,7 +2461,7 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
2463
2461
for dd ∈ 1 : N
2464
2462
dd == d && continue
2465
2463
if cat_size (as[startelementi], dd) != cat_size (as[i], dd)
2466
- throw (ArgumentError (" incompatible shape in element $i " ))
2464
+ throw (DimensionMismatch (" incompatible shape in element $i " ))
2467
2465
end
2468
2466
end
2469
2467
end
@@ -2500,18 +2498,18 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
2500
2498
elseif currentdims[d] < outdims[d] # dimension in progress
2501
2499
break
2502
2500
else # exceeded dimension
2503
- throw (ArgumentError (" argument $i has too many elements along axis $d " ))
2501
+ throw (DimensionMismatch (" argument $i has too many elements along axis $d " ))
2504
2502
end
2505
2503
end
2506
2504
end
2507
2505
elseif currentdims[d1] > outdims[d1] # exceeded dimension
2508
- throw (ArgumentError (" argument $i has too many elements along axis $d1 " ))
2506
+ throw (DimensionMismatch (" argument $i has too many elements along axis $d1 " ))
2509
2507
end
2510
2508
end
2511
2509
2512
2510
outlen = prod (outdims)
2513
2511
elementcount == outlen ||
2514
- throw (ArgumentError (" mismatched number of elements; expected $(outlen) , got $(elementcount) " ))
2512
+ throw (DimensionMismatch (" mismatched number of elements; expected $(outlen) , got $(elementcount) " ))
2515
2513
2516
2514
# copy into final array
2517
2515
A = cat_similar (as[1 ], T, outdims)
@@ -2572,8 +2570,8 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::
2572
2570
if d == 1 || i == 1 || wasstartblock
2573
2571
currentdims[d] += dsize
2574
2572
elseif dsize != cat_size (as[i - 1 ], ad)
2575
- throw (ArgumentError (" argument $i has a mismatched number of elements along axis $ad ; \
2576
- expected $(cat_size (as[i - 1 ], ad)) , got $dsize " ))
2573
+ throw (DimensionMismatch (" argument $i has a mismatched number of elements along axis $ad ; \
2574
+ expected $(cat_size (as[i - 1 ], ad)) , got $dsize " ))
2577
2575
end
2578
2576
2579
2577
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::
2583
2581
if outdims[d] == - 1
2584
2582
outdims[d] = currentdims[d]
2585
2583
elseif outdims[d] != currentdims[d]
2586
- throw (ArgumentError (" argument $i has a mismatched number of elements along axis $ad ; \
2587
- expected $(abs (outdims[d] - (currentdims[d] - dsize))) , got $dsize " ))
2584
+ throw (DimensionMismatch (" argument $i has a mismatched number of elements along axis $ad ; \
2585
+ expected $(abs (outdims[d] - (currentdims[d] - dsize))) , got $dsize " ))
2588
2586
end
2589
2587
currentdims[d] = 0
2590
2588
blockcounts[d] = 0
2591
2589
shapepos[d] += 1
2592
2590
d > 1 && (blockcounts[d - 1 ] == 0 ||
2593
- throw (ArgumentError (" shape in level $d is inconsistent; level counts must nest \
2594
- evenly into each other" )))
2591
+ throw (DimensionMismatch (" shape in level $d is inconsistent; level counts must nest \
2592
+ evenly into each other" )))
2595
2593
end
2596
2594
end
2597
2595
end
0 commit comments