Skip to content

Commit 0f651a1

Browse files
committed
fix error types
1 parent e4b6fcf commit 0f651a1

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

base/abstractarray.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ function _typed_hcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T
16511651
for j = 1:nargs
16521652
Aj = A[j]
16531653
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)))"))
16551655
end
16561656
dense &= isa(Aj,Array)
16571657
nd = ndims(Aj)
@@ -1686,7 +1686,7 @@ function _typed_vcat(::Type{T}, A::AbstractVecOrTuple{AbstractVecOrMat}) where T
16861686
ncols = size(A[1], 2)
16871687
for j = 2:nargs
16881688
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)))"))
16901690
end
16911691
end
16921692
B = similar(A[1], T, nrows, ncols)
@@ -2082,16 +2082,16 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat..
20822082
Aj = as[a+j-1]
20832083
szj = size(Aj,2)
20842084
if size(Aj,1) != szi
2085-
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)))"))
20862086
end
20872087
if c-1+szj > nc
2088-
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))"))
20892089
end
20902090
out[r:r-1+szi, c:c-1+szj] = Aj
20912091
c += szj
20922092
end
20932093
if c != nc+1
2094-
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))"))
20952095
end
20962096
r += szi
20972097
a += rows[i]
@@ -2113,7 +2113,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number
21132113
k = 1
21142114
@inbounds for i=1:nr
21152115
if nc != rows[i]
2116-
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]))"))
21172117
end
21182118
for j=1:nc
21192119
a[i,j] = xs[k]
@@ -2149,7 +2149,7 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...) where T
21492149
nc = rows[1]
21502150
for i = 2:nr
21512151
if nc != rows[i]
2152-
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]))"))
21532153
end
21542154
end
21552155
hvcat_fill!(Matrix{T}(undef, nr, nc), xs)
@@ -2317,7 +2317,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
23172317
Ndim += cat_size(as[i], N)
23182318
nd = max(nd, cat_ndims(as[i]))
23192319
for d 1:N - 1
2320-
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"))
23212321
end
23222322
end
23232323

@@ -2344,7 +2344,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
23442344
nd = max(nd, cat_ndims(as[i]))
23452345
for d 1:N-1
23462346
cat_size(as[i], d) == 1 ||
2347-
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"))
23482348
end
23492349
end
23502350

@@ -2461,7 +2461,7 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
24612461
for dd 1:N
24622462
dd == d && continue
24632463
if cat_size(as[startelementi], dd) != cat_size(as[i], dd)
2464-
throw(ArgumentError("incompatible shape in element $i"))
2464+
throw(DimensionMismatch("incompatible shape in element $i"))
24652465
end
24662466
end
24672467
end
@@ -2498,18 +2498,18 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
24982498
elseif currentdims[d] < outdims[d] # dimension in progress
24992499
break
25002500
else # exceeded dimension
2501-
throw(ArgumentError("argument $i has too many elements along axis $d"))
2501+
throw(DimensionMismatch("argument $i has too many elements along axis $d"))
25022502
end
25032503
end
25042504
end
25052505
elseif currentdims[d1] > outdims[d1] # exceeded dimension
2506-
throw(ArgumentError("argument $i has too many elements along axis $d1"))
2506+
throw(DimensionMismatch("argument $i has too many elements along axis $d1"))
25072507
end
25082508
end
25092509

25102510
outlen = prod(outdims)
25112511
elementcount == outlen ||
2512-
throw(ArgumentError("mismatched number of elements; expected $(outlen), got $(elementcount)"))
2512+
throw(DimensionMismatch("mismatched number of elements; expected $(outlen), got $(elementcount)"))
25132513

25142514
# copy into final array
25152515
A = cat_similar(as[1], T, outdims)
@@ -2570,8 +2570,8 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::
25702570
if d == 1 || i == 1 || wasstartblock
25712571
currentdims[d] += dsize
25722572
elseif dsize != cat_size(as[i - 1], ad)
2573-
throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \
2574-
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"))
25752575
end
25762576

25772577
wasstartblock = blockcounts[d] == 1 # remember for next dimension
@@ -2581,15 +2581,15 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::
25812581
if outdims[d] == -1
25822582
outdims[d] = currentdims[d]
25832583
elseif outdims[d] != currentdims[d]
2584-
throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \
2585-
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"))
25862586
end
25872587
currentdims[d] = 0
25882588
blockcounts[d] = 0
25892589
shapepos[d] += 1
25902590
d > 1 && (blockcounts[d - 1] == 0 ||
2591-
throw(ArgumentError("shape in level $d is inconsistent; level counts must nest \
2592-
evenly into each other")))
2591+
throw(DimensionMismatch("shape in level $d is inconsistent; level counts must nest \
2592+
evenly into each other")))
25932593
end
25942594
end
25952595
end

test/abstractarray.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,8 @@ function test_cat(::Type{TestAbstractArray})
683683
@test hcat() == Any[]
684684
@test vcat(1, 1.0, 3, 3.0) == [1.0, 1.0, 3.0, 3.0]
685685
@test hcat(1, 1.0, 3, 3.0) == [1.0 1.0 3.0 3.0]
686-
@test_throws ArgumentError hcat(B1, B2)
687-
@test_throws ArgumentError vcat(C1, C2)
686+
@test_throws DimensionMismatch hcat(B1, B2)
687+
@test_throws DimensionMismatch vcat(C1, C2)
688688

689689
@test vcat(B) == B
690690
@test hcat(B) == B
@@ -713,9 +713,9 @@ function test_cat(::Type{TestAbstractArray})
713713
end
714714

715715
@test_throws ArgumentError hvcat(7, 1:20...)
716-
@test_throws ArgumentError hvcat((2), C1, C3)
717-
@test_throws ArgumentError hvcat((1), C1, C2)
718-
@test_throws ArgumentError hvcat((1), C2, C3)
716+
@test_throws DimensionMismatch hvcat((2), C1, C3)
717+
@test_throws DimensionMismatch hvcat((1), C1, C2)
718+
@test_throws DimensionMismatch hvcat((1), C2, C3)
719719

720720
tup = tuple(rand(1:10, i)...)
721721
@test hvcat(tup) == []
@@ -724,8 +724,8 @@ function test_cat(::Type{TestAbstractArray})
724724
@test_throws ArgumentError hvcat((2, 2), 1, 2, 3, 4, 5)
725725
@test_throws ArgumentError Base.typed_hvcat(Int, (2, 2), 1, 2, 3, 4, 5)
726726
# check for # of columns mismatch b/w rows
727-
@test_throws ArgumentError hvcat((3, 2), 1, 2, 3, 4, 5, 6)
728-
@test_throws ArgumentError Base.typed_hvcat(Int, (3, 2), 1, 2, 3, 4, 5, 6)
727+
@test_throws DimensionMismatch hvcat((3, 2), 1, 2, 3, 4, 5, 6)
728+
@test_throws DimensionMismatch Base.typed_hvcat(Int, (3, 2), 1, 2, 3, 4, 5, 6)
729729

730730
# 18395
731731
@test isa(Any["a" 5; 2//3 1.0][2,1], Rational{Int})
@@ -1344,7 +1344,7 @@ end
13441344

13451345
@test Int[t...; 3 4] == [1 2; 3 4]
13461346
@test Int[0 t...; t... 0] == [0 1 2; 1 2 0]
1347-
@test_throws ArgumentError Int[t...; 3 4 5]
1347+
@test_throws DimensionMismatch Int[t...; 3 4 5]
13481348
end
13491349

13501350
@testset "issue #39896, modified getindex " begin
@@ -1398,15 +1398,15 @@ using Base: typed_hvncat
13981398
@test [1;;] == fill(1, (1,1))
13991399

14001400
for v in (1, fill(1), fill(1,1,1), fill(1, 1, 1, 1))
1401-
@test_throws ArgumentError [v; v;; v]
1402-
@test_throws ArgumentError [v; v;; v; v; v]
1403-
@test_throws ArgumentError [v; v; v;; v; v]
1404-
@test_throws ArgumentError [v; v;; v; v;;; v; v;; v; v;; v; v]
1405-
@test_throws ArgumentError [v; v;; v; v;;; v; v]
1406-
@test_throws ArgumentError [v; v;; v; v;;; v; v; v;; v; v]
1407-
@test_throws ArgumentError [v; v;; v; v;;; v; v;; v; v; v]
1401+
@test_throws DimensionMismatch [v; v;; v]
1402+
@test_throws DimensionMismatch [v; v;; v; v; v]
1403+
@test_throws DimensionMismatch [v; v; v;; v; v]
1404+
@test_throws DimensionMismatch [v; v;; v; v;;; v; v;; v; v;; v; v]
1405+
@test_throws DimensionMismatch [v; v;; v; v;;; v; v]
1406+
@test_throws DimensionMismatch [v; v;; v; v;;; v; v; v;; v; v]
1407+
@test_throws DimensionMismatch [v; v;; v; v;;; v; v;; v; v; v]
14081408
# ensure a wrong shape with the right number of elements doesn't pass through
1409-
@test_throws ArgumentError [v; v;; v; v;;; v; v; v; v]
1409+
@test_throws DimensionMismatch [v; v;; v; v;;; v; v; v; v]
14101410

14111411
@test [v; v;; v; v] == fill(1, ndims(v) == 3 ? (2, 2, 1) : (2,2))
14121412
@test [v; v;; v; v;;;] == fill(1, 2, 2, 1)
@@ -1474,7 +1474,7 @@ using Base: typed_hvncat
14741474
end
14751475

14761476
# reject shapes that don't nest evenly between levels (e.g. 1 + 2 does not fit into 2)
1477-
@test_throws ArgumentError hvncat(((1, 2, 1), (2, 2), (4,)), true, [1 2], [3], [4], [1 2; 3 4])
1477+
@test_throws DimensionMismatch hvncat(((1, 2, 1), (2, 2), (4,)), true, [1 2], [3], [4], [1 2; 3 4])
14781478

14791479
# zero-length arrays are handled appropriately
14801480
@test [zeros(Int, 1, 2, 0) ;;; 1 3] == [1 3;;;]
@@ -1489,18 +1489,18 @@ using Base: typed_hvncat
14891489
for v1 (zeros(Int, 0, 0), zeros(Int, 0, 0, 0, 0), zeros(Int, 0, 0, 0, 0, 0, 0, 0))
14901490
for v2 (1, [1])
14911491
for v3 (2, [2])
1492-
@test_throws ArgumentError [v1 ;;; v2]
1493-
@test_throws ArgumentError [v1 ;;; v2 v3]
1494-
@test_throws ArgumentError [v1 v1 ;;; v2 v3]
1492+
@test_throws DimensionMismatch [v1 ;;; v2]
1493+
@test_throws DimensionMismatch [v1 ;;; v2 v3]
1494+
@test_throws DimensionMismatch [v1 v1 ;;; v2 v3]
14951495
end
14961496
end
14971497
end
14981498
v1 = zeros(Int, 0, 0, 0)
14991499
for v2 (1, [1])
15001500
for v3 (2, [2])
1501-
@test_throws ArgumentError [v1 ;;; v2 v3]
1502-
@test_throws ArgumentError [v1 ;;; v2]
1503-
@test_throws ArgumentError [v1 v1 ;;; v2 v3]
1501+
@test_throws DimensionMismatch [v1 ;;; v2 v3]
1502+
@test_throws DimensionMismatch [v1 ;;; v2]
1503+
@test_throws DimensionMismatch [v1 v1 ;;; v2 v3]
15041504
end
15051505
end
15061506

@@ -1568,8 +1568,8 @@ using Base: typed_hvncat
15681568
@test Array{Int, 3}(undef, 0, 0, 0) == typed_hvncat(Int, 3) isa Array{Int, 3}
15691569

15701570
# Issue 43933 - semicolon precedence mistake should produce an error
1571-
@test_throws ArgumentError [[1 1]; 2 ;; 3 ; [3 4]]
1572-
@test_throws ArgumentError [[1 ;;; 1]; 2 ;;; 3 ; [3 ;;; 4]]
1571+
@test_throws DimensionMismatch [[1 1]; 2 ;; 3 ; [3 4]]
1572+
@test_throws DimensionMismatch [[1 ;;; 1]; 2 ;;; 3 ; [3 ;;; 4]]
15731573

15741574
@test [[1 2; 3 4] [5; 6]; [7 8] 9;;;] == [1 2 5; 3 4 6; 7 8 9;;;]
15751575

0 commit comments

Comments
 (0)