Skip to content

Commit 4e207ac

Browse files
committed
BoundsError does not take a string
fix error reporting conditions for BLAS.axpy!, BLAS.copy!, diag and getindex of Tridiagonal and SymTridiagonal, and umfpack
1 parent 5b1b0c5 commit 4e207ac

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

base/linalg/blas.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ function axpy!{T<:BlasFloat,Ta<:Number,Ti<:Integer}(alpha::Ta, x::Array{T}, rx::
314314
throw(DimensionMismatch("ranges of differing lengths"))
315315
end
316316
if minimum(rx) < 1 || maximum(rx) > length(x)
317-
throw(BoundsError("range out of bounds for x, of length $(length(x))"))
317+
throw(ArgumentError("range out of bounds for x, of length $(length(x))"))
318318
end
319319
if minimum(ry) < 1 || maximum(ry) > length(y)
320-
throw(BoundsError("range out of bounds for y, of length $(length(y))"))
320+
throw(ArgumentError("range out of bounds for y, of length $(length(y))"))
321321
end
322322
axpy!(length(rx), convert(T, alpha), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry))
323323
y
@@ -1307,10 +1307,10 @@ end # module
13071307
function copy!{T<:BlasFloat,Ti<:Integer}(dest::Array{T}, rdest::Union{UnitRange{Ti},Range{Ti}},
13081308
src::Array{T}, rsrc::Union{UnitRange{Ti},Range{Ti}})
13091309
if minimum(rdest) < 1 || maximum(rdest) > length(dest)
1310-
throw(BoundsError("range out of bounds for dest, of length $(length(dest))"))
1310+
throw(ArgumentError("range out of bounds for dest, of length $(length(dest))"))
13111311
end
13121312
if minimum(rsrc) < 1 || maximum(rsrc) > length(src)
1313-
throw(BoundsError("range out of bounds for src, of length $(length(src))"))
1313+
throw(ArgumentError("range out of bounds for src, of length $(length(src))"))
13141314
end
13151315
if length(rdest) != length(rsrc)
13161316
throw(DimensionMismatch("ranges must be of the same length"))

base/linalg/tridiag.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function diag{T}(M::SymTridiagonal{T}, n::Integer=0)
7777
elseif absn<size(M,1)
7878
return zeros(T,size(M,1)-absn)
7979
else
80-
throw(BoundsError("$n-th diagonal of a $(size(M)) matrix doesn't exist!"))
80+
throw(ArgumentError("$n-th diagonal of a $(size(M)) matrix doesn't exist!"))
8181
end
8282
end
8383

@@ -257,7 +257,7 @@ det(A::SymTridiagonal) = det_usmani(A.ev, A.dv, A.ev)
257257

258258
function getindex{T}(A::SymTridiagonal{T}, i::Integer, j::Integer)
259259
if !(1 <= i <= size(A,2) && 1 <= j <= size(A,2))
260-
throw(BoundsError("(i,j) = ($i,$j) not within matrix of size $(size(A))"))
260+
throw(BoundsError(A, (i,j)))
261261
end
262262
if i == j
263263
return A.dv[i]
@@ -362,13 +362,13 @@ function diag{T}(M::Tridiagonal{T}, n::Integer=0)
362362
elseif abs(n) < size(M,1)
363363
return zeros(T,size(M,1)-abs(n))
364364
else
365-
throw(BoundsError("$n-th diagonal of a $(size(M)) matrix doesn't exist!"))
365+
throw(ArgumentError("$n-th diagonal of a $(size(M)) matrix doesn't exist!"))
366366
end
367367
end
368368

369369
function getindex{T}(A::Tridiagonal{T}, i::Integer, j::Integer)
370370
if !(1 <= i <= size(A,2) && 1 <= j <= size(A,2))
371-
throw(BoundsError("(i,j) = ($i,$j) not within matrix of size $(size(A))"))
371+
throw(BoundsError(A, (i,j)))
372372
end
373373
if i == j
374374
return A.d[i]

base/sparse/umfpack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function umferror(status::Integer)
3333
elseif status==UMFPACK_ERROR_argument_missing
3434
throw(ArgumentError("a required argument to UMFPack is missing"))
3535
elseif status==UMFPACK_ERROR_n_nonpositive
36-
throw(BoundsError("the number of rows or columns of the matrix must be greater than zero"))
36+
throw(ArgumentError("the number of rows or columns of the matrix must be greater than zero"))
3737
elseif status==UMFPACK_ERROR_invalid_matrix
3838
throw(ArgumentError("invalid matrix"))
3939
elseif status==UMFPACK_ERROR_different_pattern

test/blas.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ for elty in [Float32, Float64, Complex64, Complex128]
8484
@test_approx_eq BLAS.axpy!(α,copy(x1),copy(x2)) x2 + α*x1
8585
@test_throws DimensionMismatch BLAS.axpy!(α, copy(x1), rand(elty, n + 1))
8686
@test_throws DimensionMismatch BLAS.axpy!(α, copy(x1), 1:div(n,2), copy(x2), 1:n)
87-
@test_throws BoundsError BLAS.axpy!(α, copy(x1), 0:div(n,2), copy(x2), 1:(div(n, 2) + 1))
88-
@test_throws BoundsError BLAS.axpy!(α, copy(x1), 1:div(n,2), copy(x2), 0:(div(n, 2) - 1))
87+
@test_throws ArgumentError BLAS.axpy!(α, copy(x1), 0:div(n,2), copy(x2), 1:(div(n, 2) + 1))
88+
@test_throws ArgumentError BLAS.axpy!(α, copy(x1), 1:div(n,2), copy(x2), 0:(div(n, 2) - 1))
8989
@test_approx_eq BLAS.axpy!(α,copy(x1),1:n,copy(x2),1:n) x2 + α*x1
9090
else
9191
z1 = convert(Vector{elty}, complex(randn(n), randn(n)))
@@ -94,8 +94,8 @@ for elty in [Float32, Float64, Complex64, Complex128]
9494
@test_approx_eq BLAS.axpy!(α, copy(z1), copy(z2)) z2 + α * z1
9595
@test_throws DimensionMismatch BLAS.axpy!(α, copy(z1), rand(elty, n + 1))
9696
@test_throws DimensionMismatch BLAS.axpy!(α, copy(z1), 1:div(n, 2), copy(z2), 1:(div(n, 2) + 1))
97-
@test_throws BoundsError BLAS.axpy!(α, copy(z1), 0:div(n,2), copy(z2), 1:(div(n, 2) + 1))
98-
@test_throws BoundsError BLAS.axpy!(α, copy(z1), 1:div(n,2), copy(z2), 0:(div(n, 2) - 1))
97+
@test_throws ArgumentError BLAS.axpy!(α, copy(z1), 0:div(n,2), copy(z2), 1:(div(n, 2) + 1))
98+
@test_throws ArgumentError BLAS.axpy!(α, copy(z1), 1:div(n,2), copy(z2), 0:(div(n, 2) - 1))
9999
@test_approx_eq BLAS.axpy!(α,copy(z1),1:n,copy(z2),1:n) z2 + α*z1
100100
end
101101

@@ -150,8 +150,8 @@ for elty in [Float32, Float64, Complex64, Complex128]
150150
BLAS.copy!(x2, 1:n, x1, 1:n)
151151
@test x2 == x1
152152
@test_throws DimensionMismatch BLAS.copy!(x2, 1:n, x1, 1:(n - 1))
153-
@test_throws BoundsError BLAS.copy!(x1, 0:div(n, 2), x2, 1:(div(n, 2) + 1))
154-
@test_throws BoundsError BLAS.copy!(x1, 1:(div(n, 2) + 1), x2, 0:div(n, 2))
153+
@test_throws ArgumentError BLAS.copy!(x1, 0:div(n, 2), x2, 1:(div(n, 2) + 1))
154+
@test_throws ArgumentError BLAS.copy!(x1, 1:(div(n, 2) + 1), x2, 0:div(n, 2))
155155

156156
# symv and hemv
157157

test/linalg/tridiag.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ let n = 12 #Size of matrix problem to test
212212
@test diag(A,-1) == b
213213
@test diag(A,0) == a
214214
@test diag(A,n-1) == zeros(elty,1)
215-
@test_throws BoundsError diag(A,n+1)
215+
@test_throws ArgumentError diag(A,n+1)
216216

217217
debug && println("Idempotent tests")
218218
for func in (conj, transpose, ctranspose)
@@ -335,7 +335,7 @@ let n = 12 #Size of matrix problem to test
335335
@test diag(A,0) == b
336336
@test diag(A,1) == c
337337
@test diag(A,n-1) == zeros(elty,1)
338-
@test_throws BoundsError diag(A,n+1)
338+
@test_throws ArgumentError diag(A,n+1)
339339

340340
debug && println("Simple unary functions")
341341
for func in (det, inv)

test/sparsedir/umfpack.jl

+2
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ x = speye(2) + im * speye(2)
6262

6363
@test det(sparse([1,3,3,1], [1,1,3,3], [1,1,1,1])) == 0
6464

65+
# UMFPACK_ERROR_n_nonpositive
66+
@test_throws ArgumentError lufact(sparse(Int[], Int[], Float64[], 5, 0))

0 commit comments

Comments
 (0)