Skip to content

Commit

Permalink
bring more error messages up to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Nov 19, 2013
1 parent de3dcdc commit 704b852
Show file tree
Hide file tree
Showing 40 changed files with 186 additions and 189 deletions.
5 changes: 2 additions & 3 deletions base/abstractarray.jl
Expand Up @@ -808,8 +808,7 @@ function cat(catdim::Integer, X...)
len = d <= ndimsX[1] ? dimsX[1][d] : 1 len = d <= ndimsX[1] ? dimsX[1][d] : 1
for i = 2:nargs for i = 2:nargs
if len != (d <= ndimsX[i] ? dimsX[i][d] : 1) if len != (d <= ndimsX[i] ? dimsX[i][d] : 1)
error("Dimension mismatch on dimension ", d) error("mismatch in dimension ", d)
#error("lala $d")
end end
end end
end end
Expand Down Expand Up @@ -876,7 +875,7 @@ function cat_t(catdim::Integer, typeC, A::AbstractArray...)
len = d <= ndimsA[1] ? dimsA[1][d] : 1 len = d <= ndimsA[1] ? dimsA[1][d] : 1
for i = 2:nargs for i = 2:nargs
if len != (d <= ndimsA[i] ? dimsA[i][d] : 1) if len != (d <= ndimsA[i] ? dimsA[i][d] : 1)
error("dimension mismatch on dimension ", d) error("mismatch in dimension ", d)
end end
end end
end end
Expand Down
6 changes: 3 additions & 3 deletions base/bitarray.jl
Expand Up @@ -955,7 +955,7 @@ end


function pop!(B::BitVector) function pop!(B::BitVector)
if isempty(B) if isempty(B)
error("BitArray must not be empty") error("argument must not be empty")
end end
item = B[end] item = B[end]
B[end] = false B[end] = false
Expand Down Expand Up @@ -993,7 +993,7 @@ end


function shift!(B::BitVector) function shift!(B::BitVector)
if isempty(B) if isempty(B)
error("BitArray must not be empty") error("argument must not be empty")
end end
@inbounds begin @inbounds begin
item = B[1] item = B[1]
Expand Down Expand Up @@ -2309,7 +2309,7 @@ function cat(catdim::Integer, X::Union(BitArray, Integer)...)
len = d <= ndimsX[1] ? dimsX[1][d] : 1 len = d <= ndimsX[1] ? dimsX[1][d] : 1
for i = 2:nargs for i = 2:nargs
if len != (d <= ndimsX[i] ? dimsX[i][d] : 1) if len != (d <= ndimsX[i] ? dimsX[i][d] : 1)
error("Dimension mismatch on dimension ", d) error("mismatch in dimension ", d)
end end
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion base/combinatorics.jl
Expand Up @@ -108,7 +108,7 @@ function invperm(a::AbstractVector)
for i = 1:n for i = 1:n
j = a[i] j = a[i]
((1 <= j <= n) && b[j] == 0) || ((1 <= j <= n) && b[j] == 0) ||
error("input is not a permutation") error("argument is not a permutation")
b[j] = i b[j] = i
end end
b b
Expand Down
2 changes: 1 addition & 1 deletion base/darray.jl
Expand Up @@ -195,7 +195,7 @@ end


function reshape{T,S<:Array}(A::DArray{T,1,S}, d::Dims) function reshape{T,S<:Array}(A::DArray{T,1,S}, d::Dims)
if prod(d) != length(A) if prod(d) != length(A)
error("Dimensions must be consistent with array size.") error("dimensions must be consistent with array size")
end end
DArray(d) do I DArray(d) do I
sz = map(length,I) sz = map(length,I)
Expand Down
8 changes: 4 additions & 4 deletions base/file.jl
Expand Up @@ -50,8 +50,8 @@ function mkpath(path::String, mode::Unsigned=0o777)
mkdir(path) mkdir(path)
end end


mkdir(path::String, mode::Signed) = error("mkdir: mode must be an unsigned integer -- perhaps 0o$mode?") mkdir(path::String, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode")
mkpath(path::String, mode::Signed) = error("mkpath: mode must be an unsigned integer -- perhaps 0o$mode?") mkpath(path::String, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode")


function rmdir(path::String) function rmdir(path::String)
@unix_only ret = ccall(:rmdir, Int32, (Ptr{Uint8},), bytestring(path)) @unix_only ret = ccall(:rmdir, Int32, (Ptr{Uint8},), bytestring(path))
Expand Down Expand Up @@ -151,7 +151,7 @@ function download(url::String, filename::String)
elseif downloadcmd == :fetch elseif downloadcmd == :fetch
run(`fetch -f $filename $url`) run(`fetch -f $filename $url`)
else else
error("No download agent available; install curl, wget, or fetch.") error("no download agent available; install curl, wget, or fetch")
end end
filename filename
end end
Expand All @@ -169,7 +169,7 @@ function readdir(path::String)
bytestring(path), uv_readdir_req) bytestring(path), uv_readdir_req)


if file_count < 0 if file_count < 0
error("Unable to read directory $path.") error("unable to read directory $path")
end end


# The list of dir entries is returned as a contiguous sequence of null-terminated # The list of dir entries is returned as a contiguous sequence of null-terminated
Expand Down
10 changes: 5 additions & 5 deletions base/fs.jl
Expand Up @@ -78,7 +78,7 @@ open(f::String,flags) = open(f,flags,0)


function close(f::File) function close(f::File)
if !f.open if !f.open
error("File is already closed") error("file is already closed")
end end
err = ccall(:jl_fs_close, Int32, (Int32,), f.handle) err = ccall(:jl_fs_close, Int32, (Int32,), f.handle)
uv_error("close",err) uv_error("close",err)
Expand All @@ -93,7 +93,7 @@ function unlink(p::String)
end end
function unlink(f::File) function unlink(f::File)
if isempty(f.path) if isempty(f.path)
error("No path associated with this file") error("no path associated with this file")
end end
if f.open if f.open
close(f) close(f)
Expand All @@ -104,7 +104,7 @@ end


function write(f::File, buf::Ptr{Uint8}, len::Integer, offset::Integer=-1) function write(f::File, buf::Ptr{Uint8}, len::Integer, offset::Integer=-1)
if !f.open if !f.open
error("File is not open") error("file is not open")
end end
err = ccall(:jl_fs_write, Int32, (Int32, Ptr{Uint8}, Csize_t, Csize_t), err = ccall(:jl_fs_write, Int32, (Int32, Ptr{Uint8}, Csize_t, Csize_t),
f.handle, buf, len, offset) f.handle, buf, len, offset)
Expand All @@ -114,7 +114,7 @@ end


function write(f::File, c::Uint8) function write(f::File, c::Uint8)
if !f.open if !f.open
error("File is not open") error("file is not open")
end end
err = ccall(:jl_fs_write_byte, Int32, (Int32, Cchar), f.handle, c) err = ccall(:jl_fs_write_byte, Int32, (Int32, Cchar), f.handle, c)
uv_error("write",err) uv_error("write",err)
Expand All @@ -140,7 +140,7 @@ end


function read(f::File, ::Type{Uint8}) function read(f::File, ::Type{Uint8})
if !f.open if !f.open
error("File is not open") error("file is not open")
end end
ret = ccall(:jl_fs_read_byte, Int32, (Int32,), f.handle) ret = ccall(:jl_fs_read_byte, Int32, (Int32,), f.handle)
uv_error("read", ret) uv_error("read", ret)
Expand Down
4 changes: 2 additions & 2 deletions base/intset.jl
Expand Up @@ -144,7 +144,7 @@ isempty(s::IntSet) =
function first(s::IntSet) function first(s::IntSet)
n = next(s,0)[1] n = next(s,0)[1]
if n >= s.limit if n >= s.limit
error("first: set is empty") error("set must be non-empty")
end end
return n return n
end end
Expand All @@ -160,7 +160,7 @@ function last(s::IntSet)
end end
end end
end end
error("last: set has no last element") error("set has no last element")
end end


length(s::IntSet) = int(ccall(:bitvector_count, Uint64, (Ptr{Uint32}, Uint64, Uint64), s.bits, 0, s.limit)) + length(s::IntSet) = int(ccall(:bitvector_count, Uint64, (Ptr{Uint32}, Uint64, Uint64), s.bits, 0, s.limit)) +
Expand Down
6 changes: 3 additions & 3 deletions base/io.jl
Expand Up @@ -352,7 +352,7 @@ write(s::IOStream, b::Uint8) = int(ccall(:jl_putc, Int32, (Uint8, Ptr{Void}), b,
function write{T}(s::IOStream, a::Array{T}) function write{T}(s::IOStream, a::Array{T})
if isbits(T) if isbits(T)
if isreadonly(s) if isreadonly(s)
error("Cannot write to a read-only IOStream") error("attempt to write to a read-only IOStream")
end end
int(ccall(:ios_write, Uint, (Ptr{Void}, Ptr{Void}, Uint), int(ccall(:ios_write, Uint, (Ptr{Void}, Ptr{Void}, Uint),
s.ios, a, length(a)*sizeof(T))) s.ios, a, length(a)*sizeof(T)))
Expand All @@ -363,7 +363,7 @@ end


function write(s::IOStream, p::Ptr, nb::Integer) function write(s::IOStream, p::Ptr, nb::Integer)
if isreadonly(s) if isreadonly(s)
error("Cannot write to a read-only IOStream") error("attempt to write to a read-only IOStream")
end end
int(ccall(:ios_write, Uint, (Ptr{Void}, Ptr{Void}, Uint), s.ios, p, nb)) int(ccall(:ios_write, Uint, (Ptr{Void}, Ptr{Void}, Uint), s.ios, p, nb))
end end
Expand Down Expand Up @@ -410,7 +410,7 @@ end


function write(s::IOStream, c::Char) function write(s::IOStream, c::Char)
if isreadonly(s) if isreadonly(s)
error("Cannot write to a read-only IOStream") error("attempt to write to a read-only IOStream")
end end
int(ccall(:ios_pututf8, Int32, (Ptr{Void}, Char), s.ios, c)) int(ccall(:ios_pututf8, Int32, (Ptr{Void}, Char), s.ios, c))
end end
Expand Down
4 changes: 2 additions & 2 deletions base/iobuffer.jl
Expand Up @@ -45,7 +45,7 @@ function read_sub{T}(from::IOBuffer, a::Array{T}, offs, nel)
throw(BoundsError()) throw(BoundsError())
end end
if !isbits(T) if !isbits(T)
error("Read from IOBuffer only supports bits types or arrays of bits types; got "*string(T)*".") error("read from IOBuffer only supports bits types or arrays of bits types; got "*string(T))
end end
read(from, pointer(a, offs), nel*sizeof(T)) read(from, pointer(a, offs), nel*sizeof(T))
return a return a
Expand Down Expand Up @@ -207,7 +207,7 @@ function write_sub{T}(to::IOBuffer, a::Array{T}, offs, nel)
throw(BoundsError()) throw(BoundsError())
end end
if !isbits(T) if !isbits(T)
error("Write to IOBuffer only supports bits types or arrays of bits types; got "*string(T)*".") error("write to IOBuffer only supports bits types or arrays of bits types; got "*string(T))
end end
write(to, pointer(a,offs), nel*sizeof(T)) write(to, pointer(a,offs), nel*sizeof(T))
end end
Expand Down
6 changes: 3 additions & 3 deletions base/linalg/arnoldi.jl
Expand Up @@ -7,7 +7,7 @@ function eigs(A;nev::Integer=6, ncv::Integer=20, which::ASCIIString="LM",
ritzvec::Bool=true, complexOP::Bool=false) ritzvec::Bool=true, complexOP::Bool=false)


(m, n) = size(A) (m, n) = size(A)
if m != n; error("Input must be square"); end if m != n; error("matrix must be square"); end
if n <= 6 && nev > n-1; nev = n-1; end if n <= 6 && nev > n-1; nev = n-1; end
ncv = blas_int(min(max(2*nev+2, ncv), n)) ncv = blas_int(min(max(2*nev+2, ncv), n))


Expand All @@ -16,8 +16,8 @@ function eigs(A;nev::Integer=6, ncv::Integer=20, which::ASCIIString="LM",
cmplx = T<:Complex cmplx = T<:Complex
bmat = "I" bmat = "I"
if !isempty(v0) if !isempty(v0)
if length(v0)!=n; error("Starting vector must have length $n"); end if length(v0)!=n; error("starting vector must have length $n"); end
if eltype(v0)!=T; error("Starting vector must have eltype $T"); end if eltype(v0)!=T; error("starting vector must have eltype $T"); end
else else
v0=zeros(T,(0,)) v0=zeros(T,(0,))
end end
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/arpack.jl
Expand Up @@ -52,8 +52,8 @@ function aupd_wrapper(T, linop::Function, n::Integer,
naupd(ido, bmat, n, which, nev, TOL, resid, ncv, v, n, naupd(ido, bmat, n, which, nev, TOL, resid, ncv, v, n,
iparam, ipntr, workd, workl, lworkl, info) iparam, ipntr, workd, workl, lworkl, info)
end end
if info[1] == 3; warn("Try eigs/svds with a larger value for ncv."); end if info[1] == 3; warn("try eigs/svds with a larger value for ncv"); end
if info[1] == 1; warn("Maximum number of iterations taken. Check nconv for number of converged eigenvalues."); end if info[1] == 1; warn("maximum number of iterations reached; check nconv for number of converged eigenvalues"); end
if info[1] < 0; throw(ARPACKException(info[1])); end if info[1] < 0; throw(ARPACKException(info[1])); end
if (ido[1] != -1 && ido[1] != 1); break; end if (ido[1] != -1 && ido[1] != 1); break; end
workd[ipntr[2]+zernm1] = linop(getindex(workd, ipntr[1]+zernm1)) workd[ipntr[2]+zernm1] = linop(getindex(workd, ipntr[1]+zernm1))
Expand Down
6 changes: 3 additions & 3 deletions base/linalg/bitarray.jl
Expand Up @@ -98,7 +98,7 @@ end
function diagm(v::Union(BitVector,BitMatrix)) function diagm(v::Union(BitVector,BitMatrix))
if isa(v, BitMatrix) if isa(v, BitMatrix)
if (size(v,1) != 1 && size(v,2) != 1) if (size(v,1) != 1 && size(v,2) != 1)
error("Input should be nx1 or 1xn") error("argument should be nx1 or 1xn")
end end
end end


Expand Down Expand Up @@ -224,7 +224,7 @@ end


function findmax(a::BitArray) function findmax(a::BitArray)
if length(a) == 0 if length(a) == 0
error("findmax: array is empty") error("array must be non-empty")
end end
m = false m = false
mi = 1 mi = 1
Expand All @@ -244,7 +244,7 @@ end


function findmin(a::BitArray) function findmin(a::BitArray)
if length(a) == 0 if length(a) == 0
error("findmin: array is empty") error("array must be non-empty")
end end
m = true m = true
mi = 1 mi = 1
Expand Down
6 changes: 3 additions & 3 deletions base/linalg/blas.jl
Expand Up @@ -166,7 +166,7 @@ for (fname, elty) in ((:daxpy_,:Float64),
end end
function axpy!{T,Ta<:Number}(alpha::Ta, x::Array{T}, y::Array{T}) function axpy!{T,Ta<:Number}(alpha::Ta, x::Array{T}, y::Array{T})
if length(x) != length(y) if length(x) != length(y)
error("Inputs should be of the same length") error("arguments must be of the same length")
end end
return axpy!(length(x), convert(T,alpha), x, 1, y, 1) return axpy!(length(x), convert(T,alpha), x, 1, y, 1)
end end
Expand All @@ -175,7 +175,7 @@ function axpy!{T,Ta<:Number,Ti<:Integer}(alpha::Ta, x::Array{T}, rx::Union(Range
y::Array{T}, ry::Union(Range1{Ti},Range{Ti})) y::Array{T}, ry::Union(Range1{Ti},Range{Ti}))


if length(rx) != length(ry) if length(rx) != length(ry)
error("Ranges should be of the same length") error("ranges must be of the same length")
end end


if minimum(rx) < 1 || maximum(rx) > length(x) || minimum(ry) < 1 || maximum(ry) > length(y) if minimum(rx) < 1 || maximum(rx) > length(x) || minimum(ry) < 1 || maximum(ry) > length(y)
Expand Down Expand Up @@ -576,7 +576,7 @@ function copy!{T<:BlasFloat,Ti<:Integer}(dest::Array{T}, rdest::Union(Range1{Ti}
throw(BoundsError()) throw(BoundsError())
end end
if length(rdest) != length(rsrc) if length(rdest) != length(rsrc)
error("Ranges must be of the same length") error("ranges must be of the same length")
end end
BLAS.blascopy!(length(rsrc), pointer(src)+(first(rsrc)-1)*sizeof(T), step(rsrc), BLAS.blascopy!(length(rsrc), pointer(src)+(first(rsrc)-1)*sizeof(T), step(rsrc),
pointer(dest)+(first(rdest)-1)*sizeof(T), step(rdest)) pointer(dest)+(first(rdest)-1)*sizeof(T), step(rdest))
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/bunchkaufman.jl
Expand Up @@ -14,7 +14,7 @@ function bkfact!{T<:BlasReal}(A::StridedMatrix{T}, uplo::Symbol)
end end
function bkfact!{T<:BlasReal}(A::StridedMatrix{T}, uplo::Symbol, symmetric::Bool) function bkfact!{T<:BlasReal}(A::StridedMatrix{T}, uplo::Symbol, symmetric::Bool)
if symmetric return bkfact!(A, uplo) end if symmetric return bkfact!(A, uplo) end
error("The Bunch-Kaufman decomposition is only valid for symmetric matrices") error("the Bunch-Kaufman decomposition is only valid for symmetric matrices")
end end
function bkfact!{T<:BlasComplex}(A::StridedMatrix{T}, uplo::Symbol, symmetric::Bool) function bkfact!{T<:BlasComplex}(A::StridedMatrix{T}, uplo::Symbol, symmetric::Bool)
if symmetric if symmetric
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/cholmod.jl
Expand Up @@ -733,7 +733,7 @@ for Ti in (:Int32,:Int64)
nc = trans ? m : n nc = trans ? m : n
nr = trans ? n : m nr = trans ? n : m
if nc != size(X,1) if nc != size(X,1)
error("Incompatible dimensions, $nc and $(size(X,1)), in chm_sdmult") error("incompatible dimensions, $nc and $(size(X,1)), in chm_sdmult")
end end
aa = float64([alpha, 0.]) aa = float64([alpha, 0.])
bb = float64([beta, 0.]) bb = float64([beta, 0.])
Expand Down Expand Up @@ -977,7 +977,7 @@ function findnz{Tv,Ti}(A::CholmodSparse{Tv,Ti})
ipos += 1 ipos += 1
count += 1 count += 1
else else
println("Warning: sparse matrix contains explicitly stored zeros.") println("warning: sparse matrix contains explicitly stored zeros")
end end
end end
ind = ind[1:count] # ind is the indices of nonzeros in A.nzval ind = ind[1:count] # ind is the indices of nonzeros in A.nzval
Expand Down
6 changes: 3 additions & 3 deletions base/linalg/dense.jl
Expand Up @@ -240,7 +240,7 @@ rref(x::Number) = one(x)
## "Functions of Matrices: Theory and Computation", SIAM ## "Functions of Matrices: Theory and Computation", SIAM
function expm!{T<:BlasFloat}(A::StridedMatrix{T}) function expm!{T<:BlasFloat}(A::StridedMatrix{T})
m, n = size(A) m, n = size(A)
if m != n error("expm!: Matrix A must be square") end if m != n error("matrix must be square") end
if m < 2 return exp(A) end if m < 2 return exp(A) end
ilo, ihi, scale = LAPACK.gebal!('B', A) # modifies A ilo, ihi, scale = LAPACK.gebal!('B', A) # modifies A
nA = norm(A, 1) nA = norm(A, 1)
Expand Down Expand Up @@ -554,9 +554,9 @@ function cond(A::StridedMatrix, p)
return maxv == 0.0 ? Inf : maxv / minimum(v) return maxv == 0.0 ? Inf : maxv / minimum(v)
elseif p == 1 || p == Inf elseif p == 1 || p == Inf
m, n = size(A) m, n = size(A)
if m != n; error("Use 2-norm for non-square matrices"); end if m != n; error("wse 2-norm for non-square matrices"); end
return cond(lufact(A), p) return cond(lufact(A), p)
end end
error("Norm type must be 1, 2 or Inf") error("norm type must be 1, 2, or Inf")
end end
cond(A::StridedMatrix) = cond(A, 2) cond(A::StridedMatrix) = cond(A, 2)

0 comments on commit 704b852

Please sign in to comment.