Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

changed isinteger, isreal, etc. #3071

Merged
merged 5 commits into from

6 participants

@simonbyrne
Collaborator

From discussion of #3054

  • new isela iseltype function (I'm open to a better suggestion for the name)
  • deprecate isinteger, isreal, iscomplex, isbool
  • renamed integer_valued, real_valued, float64_valued to isintegervalued isinteger, etc. (I didn't change it to isinteger as that could cause problems with existing code/matlab & octave users).: this is a breaking change.
@simonbyrne simonbyrne added isela function, removed redundant functions: isinteger, isreal,…
… iscomplex, isbool.

renamed integer_valued, real_valued, float64_valued
ba4df47
@StefanKarpinski

In general this is good although I'm unclear on why isela needs to exist – this is just <:.

@simonbyrne
Collaborator

It should be equivalent to

isela(x,T) = eltype(x) <: T

iscomplex seemed to be used quite a bit, so I thought it made sense to keep the similar function. However some of that usage should arguably be handled by dispatch, though some of it (such as the lapack) could be a bit tricky.

@pao
Collaborator

isela(x,T) = eltype(x) <: T is much easier to comprehend--is there a reason to use the definition you gave in your patch instead?

@simonbyrne
Collaborator

No, I only thought of the alternative after @StefanKarpinski's comment.

@JeffBezanson

Thanks for doing this!

I think iseltype would be better. And just writing out eltype(x) <: T is not so bad either.

I also think it is defensible for isinteger(3.0) to be true. The argument is, after all, an integer. isintegervalued is pretty verbose.

@StefanKarpinski

I would be cool with isinteger, isreal, et al. testing for value. But we could shorten them to isintval and isrealval. Since we consider numbers to be like single-element containers, it makes send that eltype of them would give their type. Again, I'm concerned about what eltype("foo") should be, but in practice it jet doesn't seem to be a big deal.

@JeffBezanson

I could go along with isintval, but it is always nice to use whole words when possible.

It is generally best for eltype of something iterable to give the type of the elements it generates.

@JeffBezanson

Looking over many function names, it seems that anything over 10 characters starts to seem long. Most times when a name struck me as "just barely ok" it had 10 characters (beginswith), and when one struck me as "starting to get long" it had 11 characters (ishermitian, permutedims). Seems subjective but I bet this is actually pretty robust.

@wlbksy

how about isofinteger and isofreal

@StefanKarpinski

Doesn't really read very well. I think let's just go with isinteger and isreal and document it clearly.

@simonbyrne
Collaborator

Okay, I've made the changes. However I just had one other thought: another option would be something like

isval(x,Integer)
isval(x,Real)
isval(x,Float64)

Of course the problem would be how to handle arrays (currently no array methods are defined for isinteger (the new one), but they are for isinf).

@JeffBezanson

Yes we might need something like isconvertible(Int, x).

@JeffBezanson

I think the definitions of the form isinteger{T<:Integer}(::AbstractArray{T}) = true should remain, along with isinteger(a::AbstractArray) = all(isinteger, a). I know that's inconsistent with isinf, which is elementwise, but it seems right to me.

In general, it's best to use map(isinf, A), map(isinteger, A), all(isreal, A) etc., but adding the above definition allows isinteger to be O(1) on integer-typed arrays.

@simonbyrne
Collaborator

Okay, that should be all of the missing methods.

@JeffBezanson

I'd like to merge this. Ok with @StefanKarpinski @ViralBShah ?

@StefanKarpinski

Yeah, go for it.

@ViralBShah
Owner

LGTM.

@JeffBezanson JeffBezanson merged commit aa33b77 into JuliaLang:master
@simonbyrne simonbyrne referenced this pull request
Closed

0.2 release notes #2581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 10, 2013
  1. @simonbyrne

    added isela function, removed redundant functions: isinteger, isreal,…

    simonbyrne authored
    … iscomplex, isbool.
    
    renamed integer_valued, real_valued, float64_valued
Commits on May 11, 2013
  1. @simonbyrne
  2. @simonbyrne

    merge remote

    simonbyrne authored
Commits on May 12, 2013
  1. @simonbyrne
  2. @simonbyrne
This page is out of date. Refresh to see the latest.
View
17 base/abstractarray.jl
@@ -10,6 +10,14 @@ eltype(x) = Any
eltype{T,n}(::AbstractArray{T,n}) = T
eltype{T,n}(::Type{AbstractArray{T,n}}) = T
eltype{T<:AbstractArray}(::Type{T}) = eltype(super(T))
+iseltype(x,T) = eltype(x) <: T
+isinteger(x::AbstractArray) = all(isinteger,x)
+isinteger{T<:Integer,n}(x::AbstractArray{T,n}) = true
+isreal(x::AbstractArray) = all(isreal,x)
+isreal{T<:Real,n}(x::AbstractArray{T,n}) = true
+isfloat64(x::AbstractArray) = all(isfloat64,x)
+isfloat64{T<:Float64,n}(x::AbstractArray{T,n}) = true
+isfloat64{T<:Float32,n}(x::AbstractArray{T,n}) = true
ndims{T,n}(::AbstractArray{T,n}) = n
ndims{T,n}(::Type{AbstractArray{T,n}}) = n
ndims{T<:AbstractArray}(::Type{T}) = ndims(super(T))
@@ -20,15 +28,6 @@ last(a::AbstractArray) = a[end]
strides(a::AbstractArray) = ntuple(ndims(a), i->stride(a,i))::Dims
-isinteger{T<:Integer}(::AbstractArray{T}) = true
-isinteger(::AbstractArray) = false
-isreal{T<:Real}(::AbstractArray{T}) = true
-isreal(::AbstractArray) = false
-iscomplex{T<:Complex}(::AbstractArray{T}) = true
-iscomplex(::AbstractArray) = false
-isbool(::AbstractArray{Bool}) = true
-isbool(::AbstractArray) = false
-
function isassigned(a::AbstractArray, i::Int...)
# TODO
try
View
19 base/complex.jl
@@ -43,11 +43,8 @@ for fn in _numeric_conversion_func_names
@eval $fn(z::Complex) = complex($fn(real(z)),$fn(imag(z)))
end
-iscomplex(x::Complex) = true
-iscomplex(x::Number) = false
-
-real_valued{T<:Real}(z::Complex{T}) = imag(z) == 0
-integer_valued(z::Complex) = real_valued(z) && integer_valued(real(z))
+isreal{T<:Real}(z::Complex{T}) = imag(z) == 0
+isinteger(z::Complex) = isreal(z) && isinteger(real(z))
isfinite(z::Complex) = isfinite(real(z)) && isfinite(imag(z))
reim(z) = (real(z), imag(z))
@@ -91,8 +88,6 @@ end
type ImaginaryUnit <: Number end
const im = ImaginaryUnit()
-iscomplex(::ImaginaryUnit) = true
-
convert{T<:Real}(::Type{Complex{T}}, ::ImaginaryUnit) = Complex{T}(zero(T),one(T))
convert(::Type{Complex}, ::ImaginaryUnit) = Complex(real(im),imag(im))
@@ -109,14 +104,14 @@ convert(::Type{Complex}, z::Complex) = z
convert(::Type{Complex}, x::Real) = complex(x)
==(z::Complex, w::Complex) = (real(z) == real(w)) & (imag(z) == imag(w))
-==(z::Complex, x::Real) = real_valued(z) && real(z) == x
-==(x::Real, z::Complex) = real_valued(z) && real(z) == x
+==(z::Complex, x::Real) = isreal(z) && real(z) == x
+==(x::Real, z::Complex) = isreal(z) && real(z) == x
isequal(z::Complex, w::Complex) = isequal(real(z),real(w)) & isequal(imag(z),imag(w))
-isequal(z::Complex, x::Real) = real_valued(z) && isequal(real(z),x)
-isequal(x::Real, z::Complex) = real_valued(z) && isequal(real(z),x)
+isequal(z::Complex, x::Real) = isreal(z) && isequal(real(z),x)
+isequal(x::Real, z::Complex) = isreal(z) && isequal(real(z),x)
-hash(z::Complex) = (r = hash(real(z)); real_valued(z) ? r : bitmix(r,hash(imag(z))))
+hash(z::Complex) = (r = hash(real(z)); isreal(z) ? r : bitmix(r,hash(imag(z))))
conj(z::Complex) = complex(real(z),-imag(z))
abs(z::Complex) = hypot(real(z), imag(z))
View
6 base/deprecated.jl
@@ -193,10 +193,16 @@ export PipeString
@deprecate unsafe_assign unsafe_store!
@deprecate add_each! union!
@deprecate del_each! setdiff!
+@deprecate real_valued isreal
+@deprecate integer_valued isinteger
+@deprecate float64_valued isfloat64
@deprecate expr(hd, a...) Expr(hd, a...)
@deprecate expr(hd, a::Array{Any,1}) Expr(hd, a...)
@deprecate readdir(cmd::Cmd) readdir(string(cmd)[2:end-1])
+@deprecate isbool(x) iseltype(x,Bool)
+@deprecate iscomplex(x) iseltype(x,Complex)
+
# note removed macros: str, B_str, I_str, E_str, L_str, L_mstr, I_mstr, E_mstr
View
7 base/exports.jl
@@ -336,7 +336,6 @@ export
float,
float32,
float64,
- float64_valued,
floor,
frexp,
gamma,
@@ -356,15 +355,14 @@ export
int8,
integer,
integer_partitions,
- integer_valued,
inv,
invmod,
iround,
- isbool,
- iscomplex,
isdenormal,
+ iseltype,
iseven,
isfinite,
+ isfloat64,
isinf,
isinteger,
isnan,
@@ -402,7 +400,6 @@ export
primes,
radians2degrees,
real,
- real_valued,
realmax,
realmin,
reim,
View
5 base/floatfuncs.jl
@@ -29,7 +29,10 @@ maxintfloat(::Type{Float32}) = float32(16777216.)
maxintfloat{T<:FloatingPoint}(x::T) = maxintfloat(T)
maxintfloat() = maxintfloat(Float64)
-integer_valued(x::FloatingPoint) = (trunc(x)==x)&isfinite(x)
+isinteger(x::FloatingPoint) = (trunc(x)==x)&isfinite(x)
+isfloat64(x::Number) = float64(x) == x
+isfloat64(::Float64) = true
+isfloat64(::Float32) = true
## precision, as defined by the effective number of bits in the mantissa ##
get_precision(::Float32) = 24
View
2  base/linalg.jl
@@ -138,6 +138,8 @@ export
typealias BlasFloat Union(Float64,Float32,Complex128,Complex64)
+typealias BlasReal Union(Float64,Float32)
+typealias BlasComplex Union(Complex128,Complex64)
typealias BlasChar Char
if USE_LIB64
View
2  base/linalg/arnoldi.jl
@@ -10,7 +10,7 @@ function eigs{T<:BlasFloat}(A::AbstractMatrix{T};
if m != n; error("Input must be square"); end
if n <= 6 && nev > n-1; nev = n-1; end
sym = issym(A)
- cmplx = iscomplex(A)
+ cmplx = iseltype(A,Complex)
bmat = "I"
# Compute the Ritz values and Ritz vectors
View
9 base/linalg/dense.jl
@@ -206,7 +206,7 @@ randsym(n) = symmetrize!(randn(n,n))
^(A::Matrix, p::Integer) = p < 0 ? inv(A^-p) : Base.power_by_squaring(A,p)
function ^(A::Matrix, p::Number)
- if integer_valued(p)
+ if isinteger(p)
ip = integer(real(p))
if ip < 0
return inv(Base.power_by_squaring(A, -ip))
@@ -218,7 +218,7 @@ function ^(A::Matrix, p::Number)
error("matrix must be square")
end
(v, X) = eig(A)
- if isreal(v) && any(v.<0)
+ if any(v.<0)
v = complex(v)
end
if ishermitian(A)
@@ -382,7 +382,7 @@ function sqrtm(A::StridedMatrix, cond::Bool)
if ishermitian(A)
return sqrtm(Hermitian(A), cond)
else
- SchurF = schurfact!(iscomplex(A) ? copy(A) : complex(A))
+ SchurF = schurfact!(iseltype(A,Complex) ? copy(A) : complex(A))
R = zeros(eltype(SchurF[:T]), n, n)
for j = 1:n
R[j,j] = sqrt(SchurF[:T][j,j])
@@ -409,7 +409,8 @@ end
sqrtm{T<:Integer}(A::StridedMatrix{T}, cond::Bool) = sqrtm(float(A), cond)
sqrtm{T<:Integer}(A::StridedMatrix{Complex{T}}, cond::Bool) = sqrtm(complex128(A), cond)
sqrtm(A::StridedMatrix) = sqrtm(A, false)
-sqrtm(a::Number) = isreal(a) ? (b = sqrt(complex(a)); imag(b) == 0 ? real(b) : b) : sqrt(a)
+sqrtm(a::Number) = (b = sqrt(complex(a)); imag(b) == 0 ? real(b) : b)
+sqrtm(a::Complex) = sqrt(a)
function det(A::Matrix)
m, n = size(A)
View
32 base/linalg/factorization.jl
@@ -252,7 +252,9 @@ function *{T<:BlasFloat}(A::QRPackedQ{T}, B::StridedVecOrMat{T})
end
LAPACK.gemqrt!('L', 'N', A.vs, A.T, Bc)
end
-Ac_mul_B(A::QRPackedQ, B::StridedVecOrMat) = LAPACK.gemqrt!('L', iscomplex(A.vs[1]) ? 'C' : 'T', A.vs, A.T, copy(B))
+Ac_mul_B{T<:BlasReal}(A::QRPackedQ{T}, B::StridedVecOrMat) = LAPACK.gemqrt!('L','T',A.vs,A.T,copy(B))
+Ac_mul_B{T<:BlasComplex}(A::QRPackedQ{T}, B::StridedVecOrMat) = LAPACK.gemqrt!('L','C',A.vs,A.T,copy(B))
+
*(A::StridedVecOrMat, B::QRPackedQ) = LAPACK.gemqrt!('R', 'N', B.vs, B.T, copy(A))
function A_mul_Bc{T<:BlasFloat}(A::StridedVecOrMat{T}, B::QRPackedQ{T})
m = size(A, 1)
@@ -264,7 +266,7 @@ function A_mul_Bc{T<:BlasFloat}(A::StridedVecOrMat{T}, B::QRPackedQ{T})
else
throw(DimensionMismatch(""))
end
- LAPACK.gemqrt!('R', iscomplex(B.vs[1]) ? 'C' : 'T', B.vs, B.T, Ac)
+ LAPACK.gemqrt!('R', iseltype(B.vs,Complex) ? 'C' : 'T', B.vs, B.T, Ac)
end
## Least squares solution. Should be more careful about cases with m < n
(\)(A::QR, B::StridedVector) = Triangular(A[:R], 'U')\(A[:Q]'B)[1:size(A, 2)]
@@ -346,7 +348,8 @@ function *{T<:BlasFloat}(A::QRPivotedQ{T}, B::StridedVecOrMat{T})
end
LAPACK.ormqr!('L', 'N', A.hh, A.tau, Bc)
end
-Ac_mul_B(A::QRPivotedQ, B::StridedVecOrMat) = LAPACK.ormqr!('L', iscomplex(A.hh[1]) ? 'C' : 'T', A.hh, A.tau, copy(B))
+Ac_mul_B{T<:BlasReal}(A::QRPivotedQ{T}, B::StridedVecOrMat) = LAPACK.ormqr!('L','T',A.hh,A.tau,copy(B))
+Ac_mul_B{T<:BlasComplex}(A::QRPivotedQ{T}, B::StridedVecOrMat) = LAPACK.ormqr!('L','C',A.hh,A.tau,copy(B))
*(A::StridedVecOrMat, B::QRPivotedQ) = LAPACK.ormqr!('R', 'N', B.hh, B.tau, copy(A))
function A_mul_Bc{T<:BlasFloat}(A::StridedVecOrMat{T}, B::QRPivotedQ{T})
m = size(A, 1)
@@ -358,7 +361,7 @@ function A_mul_Bc{T<:BlasFloat}(A::StridedVecOrMat{T}, B::QRPivotedQ{T})
else
throw(DimensionMismatch(""))
end
- LAPACK.ormqr!('R', iscomplex(B.hh[1]) ? 'C' : 'T', B.hh, B.tau, Ac)
+ LAPACK.ormqr!('R', iseltype(B.hh,Complex) ? 'C' : 'T', B.hh, B.tau, Ac)
end
##TODO: Add methods for rank(A::QRP{T}) and adjust the (\) method accordingly
@@ -408,11 +411,10 @@ function getindex(A::Eigen, d::Symbol)
error("No such type field")
end
-function eigfact!{T<:BlasFloat}(A::StridedMatrix{T})
+function eigfact!{T<:BlasReal}(A::StridedMatrix{T})
n = size(A, 2)
if n == 0; return Eigen(zeros(T, 0), zeros(T, 0, 0)) end
if ishermitian(A) return eigfact!(Hermitian(A)) end
- if iscomplex(A) return Eigen(LAPACK.geev!('N', 'V', A)[[1,3]]...) end
WR, WI, VL, VR = LAPACK.geev!('N', 'V', A)
if all(WI .== 0.) return Eigen(WR, VR) end
@@ -431,6 +433,13 @@ function eigfact!{T<:BlasFloat}(A::StridedMatrix{T})
return Eigen(complex(WR, WI), evec)
end
+function eigfact!{T<:BlasComplex}(A::StridedMatrix{T})
+ n = size(A, 2)
+ if n == 0; return Eigen(zeros(T, 0), zeros(T, 0, 0)) end
+ if ishermitian(A) return eigfact!(Hermitian(A)) end
+ Eigen(LAPACK.geev!('N', 'V', A)[[1,3]]...)
+end
+
eigfact(A::StridedMatrix) = eigfact!(copy(A))
eigfact{T<:Integer}(x::StridedMatrix{T}) = eigfact(float64(x))
eigfact(x::Number) = Eigen([x], fill(one(x), 1, 1))
@@ -443,24 +452,27 @@ end
#Calculates eigenvectors
eigvecs(A::Union(Number, StridedMatrix)) = eigfact(A)[:vectors]
-function eigvals(A::StridedMatrix)
+function eigvals{T<:BlasReal}(A::StridedMatrix{T})
if ishermitian(A) return eigvals(Hermitian(A)) end
- if iscomplex(A) return LAPACK.geev!('N', 'N', copy(A))[1] end
valsre, valsim, _, _ = LAPACK.geev!('N', 'N', copy(A))
if all(valsim .== 0) return valsre end
return complex(valsre, valsim)
end
+function eigvals{T<:BlasReal}(A::StridedMatrix{T})
+ if ishermitian(A) return eigvals(Hermitian(A)) end
+ LAPACK.geev!('N', 'N', copy(A))[1]
+end
eigvals(x::Number) = [one(x)]
#Computes maximum and minimum eigenvalue
function eigmax(A::Union(Number, StridedMatrix))
v = eigvals(A)
- iscomplex(v) ? error("Complex eigenvalues cannot be ordered") : max(v)
+ iseltype(v,Complex) ? error("Complex eigenvalues cannot be ordered") : max(v)
end
function eigmin(A::Union(Number, StridedMatrix))
v = eigvals(A)
- iscomplex(v) ? error("Complex eigenvalues cannot be ordered") : min(v)
+ iseltype(v,Complex) ? error("Complex eigenvalues cannot be ordered") : min(v)
end
inv(A::Eigen) = scale(A.vectors, 1.0/A.values)*A.vectors'
View
12 base/linalg/lapack.jl
@@ -234,7 +234,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt3, gerqf, getrf, elty, relty) in
work = Array($elty, 1)
lwork = blas_int(-1)
info = Array(BlasInt, 1)
- cmplx = iscomplex(A)
+ cmplx = iseltype(A,Complex)
if cmplx; rwork = Array($relty, 2n); end
for i in 1:2
if cmplx
@@ -575,7 +575,7 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in
rvecs = jobvr == 'V'
VL = Array($elty, (n, lvecs ? n : 0))
VR = Array($elty, (n, rvecs ? n : 0))
- cmplx = iscomplex(A)
+ cmplx = iseltype(A,Complex)
if cmplx
W = Array($elty, n)
rwork = Array($relty, 2n)
@@ -642,7 +642,7 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in
work = Array($elty, 1)
lwork = blas_int(-1)
S = Array($relty, minmn)
- cmplx = iscomplex(A)
+ cmplx = iseltype(A,Complex)
if cmplx
rwork = Array($relty, job == 'N' ? 7*minmn : 5*minmn*minmn + 5*minmn)
end
@@ -694,7 +694,7 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in
U = Array($elty, jobu == 'A'? (m, m):(jobu == 'S'? (m, minmn) : (m, 0)))
VT = Array($elty, jobvt == 'A'? (n, n):(jobvt == 'S'? (minmn, n) : (n, 0)))
work = Array($elty, 1)
- cmplx = iscomplex(A)
+ cmplx = iseltype(A,Complex)
if cmplx; rwork = Array($relty, 5minmn); end
lwork = blas_int(-1)
info = Array(BlasInt, 1)
@@ -755,7 +755,7 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in
ldq = max(1, n)
Q = jobq == 'Q' ? Array($elty, ldq, n) : Array($elty, 0)
work = Array($elty, max(3n, m, p) + n)
- cmplx = iscomplex(A)
+ cmplx = iseltype(A,Complex)
if cmplx; rwork = Array($relty, 2n); end
iwork = Array(BlasInt, n)
info = Array(BlasInt, 1)
@@ -1476,7 +1476,7 @@ for (syconv, syev, sysv, sytrf, sytri, sytrs, elty, relty) in
function syev!(jobz::BlasChar, uplo::BlasChar, A::StridedMatrix{$elty})
chkstride1(A)
chksquare(A)
- cmplx = iscomplex(A)
+ cmplx = iseltype(A,Complex)
n = size(A, 1)
W = Array($relty, n)
work = Array($elty, 1)
View
6 base/linalg/tridiag.jl
@@ -325,10 +325,8 @@ LDLTTridiagonal{S<:BlasFloat,T<:BlasFloat}(D::Vector{S}, E::Vector{T}) = LDLTTri
ldltd!{T<:BlasFloat}(A::SymTridiagonal{T}) = LDLTTridiagonal(LAPACK.pttrf!(real(A.dv),A.ev)...)
ldltd{T<:BlasFloat}(A::SymTridiagonal{T}) = ldltd!(copy(A))
-function (\){T<:BlasFloat}(C::LDLTTridiagonal{T}, B::StridedVecOrMat{T})
- if iscomplex(B) return LAPACK.pttrs!('L', C.D, C.E, copy(B)) end
- LAPACK.pttrs!(C.D, C.E, copy(B))
-end
+(\){T<:BlasReal}(C::LDLTTridiagonal{T}, B::StridedVecOrMat{T}) = LAPACK.pttrs!(C.D, C.E, copy(B))
+(\){T<:BlasComplex}(C::LDLTTridiagonal{T}, B::StridedVecOrMat{T}) = LAPACK.pttrs!('L', C.D, C.E, copy(B))
type LUTridiagonal{T} <: Factorization{T}
dl::Vector{T}
View
12 base/mpfr.jl
@@ -17,7 +17,7 @@ export
import
Base: (*), +, -, /, <, <=, ==, >, >=, ^, besselj, besselj0, besselj1,
bessely, bessely0, bessely1, ceil, cmp, convert, copysign, exp, exp2,
- exponent, factorial, floor, hypot, integer_valued, iround, isfinite,
+ exponent, factorial, floor, hypot, isinteger, iround, isfinite,
isinf, isnan, ldexp, log, log2, log10, max, min, mod, modf, nextfloat,
prevfloat, promote_rule, rem, round, show, showcompact, sum, sqrt,
string, trunc, get_precision, exp10, expm1, gamma, lgamma, digamma,
@@ -102,7 +102,7 @@ convert(::Type{FloatingPoint}, x::BigInt) = BigFloat(x)
for to in (Int8, Int16, Int32, Int64)
@eval begin
function convert(::Type{$to}, x::BigFloat)
- (integer_valued(x) && (typemin($to) <= x <= typemax($to))) || throw(InexactError())
+ (isinteger(x) && (typemin($to) <= x <= typemax($to))) || throw(InexactError())
convert($to, ccall((:mpfr_get_si,:libmpfr),
Clong, (Ptr{BigFloat}, Int32), &x, RoundToZero))
end
@@ -112,7 +112,7 @@ end
for to in (Uint8, Uint16, Uint32, Uint64)
@eval begin
function convert(::Type{$to}, x::BigFloat)
- (integer_valued(x) && (typemin($to) <= x <= typemax($to))) || throw(InexactError())
+ (isinteger(x) && (typemin($to) <= x <= typemax($to))) || throw(InexactError())
convert($to, ccall((:mpfr_get_ui,:libmpfr),
Culong, (Ptr{BigFloat}, Int32), &x, RoundToZero))
end
@@ -120,7 +120,7 @@ for to in (Uint8, Uint16, Uint32, Uint64)
end
function convert(::Type{BigInt}, x::BigFloat)
- if integer_valued(x)
+ if isinteger(x)
return itrunc(x)
else
throw(InexactError())
@@ -460,7 +460,7 @@ function bessely(n::Integer, x::BigFloat)
end
function factorial(x::BigFloat)
- if x < 0 || !integer_valued(x)
+ if x < 0 || !isinteger(x)
throw(DomainError())
end
ui = convert(Culong, x)
@@ -620,7 +620,7 @@ function exponent(x::BigFloat)
return ccall((:mpfr_get_exp, :libmpfr), Clong, (Ptr{BigFloat},), &x) - 1
end
-function integer_valued(x::BigFloat)
+function isinteger(x::BigFloat)
return ccall((:mpfr_integer_p, :libmpfr), Int32, (Ptr{BigFloat},), &x) != 0
end
View
9 base/number.jl
@@ -1,17 +1,8 @@
## generic operations on numbers ##
-isreal(x::Number) = false
isreal(x::Real) = true
-
-isinteger(x::Number) = false
isinteger(x::Integer) = true
-real_valued(x::Real) = true
-integer_valued(x::Integer) = true
-
-isbool(x::Number) = false
-isbool(x::Bool) = true
-
size(x::Number) = ()
size(x::Number,d) = convert(Int,d)<1 ? throw(BoundsError()) : 1
eltype(x::Number) = typeof(x)
View
12 base/rational.jl
@@ -92,11 +92,11 @@ isfinite(x::Rational) = x.den != 0
typemin{T<:Integer}(::Type{Rational{T}}) = -one(T)//zero(T)
typemax{T<:Integer}(::Type{Rational{T}}) = one(T)//zero(T)
-integer_valued(x::Rational) = x.den == 1
-float64_valued(x::Rational) = abs(x.num) <= x.den*maxintfloat(Float64)
+isinteger(x::Rational) = x.den == 1
+isfloat64(x::Rational) = abs(x.num) <= x.den*maxintfloat(Float64)
-hash(x::Rational) = integer_valued(x) ? hash(x.num) :
- float64_valued(x) ? hash(float64(x)) :
+hash(x::Rational) = isinteger(x) ? hash(x.num) :
+ isfloat64(x) ? hash(float64(x)) :
bitmix(hash(x.num),hash(x.den))
-(x::Rational) = (-x.num) // x.den
@@ -111,8 +111,8 @@ hash(x::Rational) = integer_valued(x) ? hash(x.num) :
==(x::Integer , y::Rational) = y == x
# needed to avoid ambiguity between ==(x::Real, z::Complex) and ==(x::Rational, y::Number)
-==(z::Complex , x::Rational) = real_valued(z) && real(z) == x
-==(x::Rational, z::Complex ) = real_valued(z) && real(z) == x
+==(z::Complex , x::Rational) = isreal(z) && real(z) == x
+==(x::Rational, z::Complex ) = isreal(z) && real(z) == x
==(x::Rational, y::Number ) = x.num == x.den*y
==(x::Number , y::Rational) = y == x
View
2  base/sparse.jl
@@ -442,7 +442,7 @@ function sprand(m::Integer, n::Integer, density::FloatingPoint, rng::Function, v
I = rand!(1:m, Array(Int, numnz))
J = rand!(1:n, Array(Int, numnz))
S = sparse(I, J, v, m, n)
- if !isbool(v)
+ if !iseltype(v,Bool)
S.nzval = rng(nnz(S))
end
View
220 doc/helpdb.jl
@@ -808,26 +808,19 @@ collection)
"),
-("Set-Like Collections","Base","add_each!","add_each!(collection,
-iterable)
-
-
- Adds each element in iterable to the collection.
-
-"),
-
("Set-Like Collections","Base","Set","Set(x...)
Construct a \"Set\" with the given elements. Should be used instead
- of \"IntSet\" for sparse integer sets.
+ of \"IntSet\" for sparse integer sets, or for sets of arbitrary
+ objects.
"),
("Set-Like Collections","Base","IntSet","IntSet(i...)
- Construct an \"IntSet\" of the given integers. Implemented as a bit
+ Construct a sorted set of the given integers. Implemented as a bit
string, and therefore designed for dense integer sets. If the set
will be sparse (for example holding a single very large integer),
use \"Set\" instead.
@@ -842,11 +835,10 @@ iterable)
"),
-("Set-Like Collections","Base","union!","union!(s1, s2)
+("Set-Like Collections","Base","union!","union!(s, iterable)
- Constructs the union of IntSets s1 and s2, stores the result in
- \"s1\".
+ Union each element of \"iterable\" into set \"s\" in-place.
"),
@@ -866,6 +858,13 @@ iterable)
"),
+("Set-Like Collections","Base","setdiff!","setdiff!(s, iterable)
+
+
+ Remove each element of \"iterable\" from set \"s\" in-place.
+
+"),
+
("Set-Like Collections","Base","symdiff","symdiff(s1, s2...)
@@ -912,13 +911,6 @@ iterable)
"),
-("Set-Like Collections","Base","del_each!","del_each!(s, itr)
-
-
- Deletes each element of itr in set s in-place.
-
-"),
-
("Set-Like Collections","Base","intersect!","intersect!(s1, s2)
@@ -2510,41 +2502,39 @@ stream[, offset])
"),
("Mathematical Functions","Base","round","round(x[, digits[, base]])
--> FloatingPoint
- \"round(x)\" returns the nearest integer to \"x\". \"round(x,
- digits)\" rounds to the specified number of digits after the
- decimal place, or before if negative, e.g., \"round(pi,2)\" is
- \"3.14\". \"round(x, digits, base)\" rounds using a different base,
- defaulting to 10, e.g., \"round(pi, 3, 2)\" is \"3.125\".
+ \"round(x)\" returns the nearest integral value of the same type as
+ \"x\" to \"x\". \"round(x, digits)\" rounds to the specified number
+ of digits after the decimal place, or before if negative, e.g.,
+ \"round(pi,2)\" is \"3.14\". \"round(x, digits, base)\" rounds
+ using a different base, defaulting to 10, e.g., \"round(pi, 3, 2)\"
+ is \"3.125\".
"),
-("Mathematical Functions","Base","ceil","ceil(x[, digits[, base]]) ->
-FloatingPoint
+("Mathematical Functions","Base","ceil","ceil(x[, digits[, base]])
- Returns the nearest integer not less than \"x\". \"digits\" and
- \"base\" work as above.
+ Returns the nearest integral value of the same type as \"x\" not
+ less than \"x\". \"digits\" and \"base\" work as above.
"),
("Mathematical Functions","Base","floor","floor(x[, digits[, base]])
--> FloatingPoint
- Returns the nearest integer not greater than \"x\". \"digits\" and
- \"base\" work as above.
+ Returns the nearest integral value of the same type as \"x\" not
+ greater than \"x\". \"digits\" and \"base\" work as above.
"),
("Mathematical Functions","Base","trunc","trunc(x[, digits[, base]])
--> FloatingPoint
- Returns the nearest integer not greater in magnitude than \"x\".
- \"digits\" and \"base\" work as above.
+ Returns the nearest integral value of the same type as \"x\" not
+ greater in magnitude than \"x\". \"digits\" and \"base\" work as
+ above.
"),
@@ -2577,7 +2567,6 @@ FloatingPoint
"),
("Mathematical Functions","Base","signif","signif(x, digits[, base])
--> FloatingPoint
Rounds (in the sense of \"round\") \"x\" so that there are
@@ -2702,28 +2691,28 @@ FloatingPoint
"),
-("Mathematical Functions","Base","erfinv","erfinv(x)
+("Mathematical Functions","Base","dawson","dawson(x)
- Compute the inverse error function of a real \"x\",
- so that \\operatorname{erf}(\\operatorname{erfinv}(x)) = x.
+ Compute the Dawson function (scaled imaginary error function) of
+ \"x\", defined by \\frac{\\sqrt{\\pi}}{2} e^{-x^2}
+ \\operatorname{erfi}(x).
"),
-("Mathematical Functions","Base","erfcinv","erfcinv(x)
+("Mathematical Functions","Base","erfinv","erfinv(x)
- Compute the inverse complementary error function of a real \"x\",
- so that \\operatorname{erfc}(\\operatorname{erfcinv}(x)) = x.
+ Compute the inverse error function of a real \"x\", defined by
+ \\operatorname{erf}(\\operatorname{erfinv}(x)) = x.
"),
-("Mathematical Functions","Base","dawson","dawson(x)
+("Mathematical Functions","Base","erfcinv","erfcinv(x)
- Compute the Dawson function (scaled imaginary error function) of
- \"x\", defined by \\frac{\\sqrt{\\pi}}{2} e^{-x^2}
- \\operatorname{erfi}(x).
+ Compute the inverse error complementary function of a real \"x\",
+ defined by \\operatorname{erfc}(\\operatorname{erfcinv}(x)) = x.
"),
@@ -3153,13 +3142,6 @@ FloatingPoint
"),
-("Data Formats","Base","isbool","isbool(x)
-
-
- Test whether number or array is boolean
-
-"),
-
("Data Formats","Base","int","int(x)
@@ -3187,13 +3169,6 @@ FloatingPoint
"),
-("Data Formats","Base","isinteger","isinteger(x)
-
-
- Test whether a number or array is of integer type
-
-"),
-
("Data Formats","Base","signed","signed(x)
@@ -3319,11 +3294,11 @@ FloatingPoint
"),
-("Data Formats","Base","float64_valued","float64_valued(x::Rational)
+("Data Formats","Base","isfloat64","isfloat64(x::Rational)
- True if \"x\" can be losslessly represented as a \"Float64\" data
- type
+ Tests whether \"x\" or all its elements can be losslessly
+ represented as a \"Float64\" data type
"),
@@ -3355,20 +3330,6 @@ FloatingPoint
"),
-("Data Formats","Base","iscomplex","iscomplex(x) -> Bool
-
-
- Test whether a number or array is of a complex type
-
-"),
-
-("Data Formats","Base","isreal","isreal(x) -> Bool
-
-
- Test whether a number or array is of a real type
-
-"),
-
("Data Formats","Base","bswap","bswap(n)
@@ -3533,17 +3494,19 @@ FloatingPoint
"),
-("Numbers","Base","integer_valued","integer_valued(x)
+("Numbers","Base","isinteger","isinteger(x)
- Test whether \"x\" is numerically equal to some integer
+ Test whether \"x\" or all its elements are numerically equal to
+ some integer
"),
-("Numbers","Base","real_valued","real_valued(x)
+("Numbers","Base","isreal","isreal(x)
- Test whether \"x\" is numerically equal to some real number
+ Test whether \"x\" or all its elements are numerically equal to
+ some real number
"),
@@ -3768,6 +3731,13 @@ Integer
"),
+("Arrays","Base","iseltype","iseltype(A, T)
+
+
+ Tests whether A or its elements are of type T
+
+"),
+
("Arrays","Base","length","length(A) -> Integer
@@ -4860,13 +4830,14 @@ flags[, timelimit]]])
"),
("Parallel Computing","Base","addprocs","addprocs({\"host1\",
-\"host2\", ...}; tunnel=false)
+\"host2\", ...}; tunnel=false, dir=JULIA_HOME)
Add processes on remote machines via SSH. Requires julia to be
installed in the same location on each node, or to be available via
a shared file system. If \"tunnel\" is \"true\" then SSH tunneling
- will be used.
+ will be used. Named argument \"dir\" optionally specifies the
+ location of the julia binaries on the worker nodes.
"),
@@ -5492,7 +5463,7 @@ own])
"),
-("Tasks","Base","tls","tls(symbol)
+("Tasks","Base","task_local_storage","task_local_storage(symbol)
Look up the value of a symbol in the current task's task-local
@@ -5500,7 +5471,8 @@ own])
"),
-("Tasks","Base","tls","tls(symbol, value)
+("Tasks","Base","task_local_storage","task_local_storage(symbol,
+value)
Assign a value to a symbol in the current task's task-local
@@ -5508,6 +5480,73 @@ own])
"),
+("Base.Collections","Base.Collections","PriorityQueue{K,V}","Priority
+Queue{K,V}([ord])
+
+
+ Construct a new PriorityQueue, with keys of type K and
+ values/priorites of type V. If an order is not given, the priority
+ queue is min-ordered using the default comparison for V.
+
+"),
+
+("Base.Collections","Base.Collections","enqueue!","enqueue!(pq, k, v)
+
+
+ Insert the a key \"k\" into a priority queue \"pq\" with priority
+ \"v\".
+
+"),
+
+("Base.Collections","Base.Collections","dequeue!","dequeue!(pq)
+
+
+ Remove and return the lowest priority key from a priority queue.
+
+"),
+
+("Base.Collections","Base.Collections","heapify","heapify(v[, ord])
+
+
+ Return a new vector in binary heap order, optionally using the
+ given ordering.
+
+"),
+
+("Base.Collections","Base.Collections","heapify!","heapify!(v[, ord])
+
+
+ In-place heapify.
+
+"),
+
+("Base.Collections","Base.Collections","isheap","isheap(v[, ord])
+
+
+ Return true iff an array is heap-ordered according to the given
+ order.
+
+"),
+
+("Base.Collections","Base.Collections","heappush!","heappush!(v[,
+ord])
+
+
+ Given a binary heap-ordered array, push a new element, preserving
+ the heap property. For efficiency, this function does not check
+ that the array is indeed heap-ordered.
+
+"),
+
+("Base.Collections","Base.Collections","heappop!","heappop!(v[, ord])
+
+
+ Given a binary heap-ordered array, remove and return the lowest
+ ordered element. For efficiency, this function does not check that
+ the array is indeed heap-ordered.
+
+"),
+
("Constants","Base","OS_NAME","OS_NAME
@@ -6702,11 +6741,10 @@ y)
("Base.Sort","Base.Sort","searchsorted","searchsorted(a, x[, ord])
- Returns the index of the first value of \"a\" equal to or
- succeeding \"x\", according to ordering \"ord\" (default:
- \"Sort.Forward\").
-
- Alias for \"searchsortedfirst()\"
+ Returns the range of indices of \"a\" equal to \"x\", assuming
+ \"a\" is sorted according to ordering \"ord\" (default:
+ \"Sort.Forward\"). Returns an empty range located at the insertion
+ point if \"a\" does not contain \"x\".
"),
View
32 doc/stdlib/base.rst
@@ -1771,10 +1771,6 @@ Data Formats
Convert a number or numeric array to boolean
-.. function:: isbool(x)
-
- Test whether number or array is boolean
-
.. function:: int(x)
Convert a number or array to the default integer type on your platform. Alternatively, ``x`` can be a string, which is parsed as an integer.
@@ -1787,10 +1783,6 @@ Data Formats
Convert a number or array to integer type. If ``x`` is already of integer type it is unchanged, otherwise it converts it to the default integer type on your platform.
-.. function:: isinteger(x)
-
- Test whether a number or array is of integer type
-
.. function:: signed(x)
Convert a number to a signed integer
@@ -1861,9 +1853,9 @@ Data Formats
Get the exponent of a normalized floating-point number.
-.. function:: float64_valued(x::Rational)
+.. function:: isfloat64(x::Rational)
- True if ``x`` can be losslessly represented as a ``Float64`` data type
+ Tests whether ``x`` or all its elements can be losslessly represented as a ``Float64`` data type
.. function:: complex64(r,i)
@@ -1881,14 +1873,6 @@ Data Formats
Convert real numbers or arrays to complex
-.. function:: iscomplex(x) -> Bool
-
- Test whether a number or array is of a complex type
-
-.. function:: isreal(x) -> Bool
-
- Test whether a number or array is of a real type
-
.. function:: bswap(n)
Byte-swap an integer
@@ -1981,13 +1965,13 @@ Numbers
Get the previous floating point number in lexicographic order
-.. function:: integer_valued(x)
+.. function:: isinteger(x)
- Test whether ``x`` is numerically equal to some integer
+ Test whether ``x`` or all its elements are numerically equal to some integer
-.. function:: real_valued(x)
+.. function:: isreal(x)
- Test whether ``x`` is numerically equal to some real number
+ Test whether ``x`` or all its elements are numerically equal to some real number
.. function:: BigInt(x)
@@ -2124,6 +2108,10 @@ Basic functions
Returns the type of the elements contained in A
+.. function:: iseltype(A,T)
+
+ Tests whether A or its elements are of type T
+
.. function:: length(A) -> Integer
Returns the number of elements in A (note that this differs from MATLAB where ``length(A)`` is the largest dimension of ``A``)
View
2  test/blas.jl
@@ -50,7 +50,7 @@ for elty in (Float32, Float64, Complex64, Complex128)
@assert all(LinAlg.BLAS.gemm('N', 'N', I4, U4) .== U4)
@assert all(LinAlg.BLAS.gemm('N', 'T', I4, U4) .== L4)
# gemm compared to (sy)(he)rk
- if iscomplex(elm1)
+ if iseltype(elm1,Complex)
@assert all(triu(LinAlg.BLAS.herk('U', 'N', U4)) .== triu(LinAlg.BLAS.gemm('N', 'T', U4, U4)))
@assert all(tril(LinAlg.BLAS.herk('L', 'N', U4)) .== tril(LinAlg.BLAS.gemm('N', 'T', U4, U4)))
@assert all(triu(LinAlg.BLAS.herk('U', 'N', L4)) .== triu(LinAlg.BLAS.gemm('N', 'T', L4, L4)))
View
6 test/linalg.jl
@@ -66,13 +66,13 @@ for elty in (Float32, Float64, Complex64, Complex128)
@test_approx_eq f[:vectors]*f[:Schur]*f[:vectors]' a
@test_approx_eq sort(real(f[:values])) sort(real(d))
@test_approx_eq sort(imag(f[:values])) sort(imag(d))
- @test istriu(f[:Schur]) || isreal(a)
+ @test istriu(f[:Schur]) || iseltype(a,Real)
f = schurfact(a[1:5,1:5], a[6:10,6:10]) # Generalized Schur
@test_approx_eq f[:Q]*f[:S]*f[:Z]' a[1:5,1:5]
@test_approx_eq f[:Q]*f[:T]*f[:Z]' a[6:10,6:10]
- @test istriu(f[:S]) || isreal(a)
- @test istriu(f[:T]) || isreal(a)
+ @test istriu(f[:S]) || iseltype(a,Real)
+ @test istriu(f[:T]) || iseltype(a,Real)
usv = svdfact(a) # singular value decomposition
@test_approx_eq usv[:U]*scale(usv[:S],usv[:Vt]) a
View
6 test/mpfr.jl
@@ -179,9 +179,9 @@ x = BigFloat(12)
@test get_precision(x) == old_precision
@test_fails set_bigfloat_precision(1)
-# integer_valued
-@test integer_valued(BigFloat(12))
-@test !integer_valued(BigFloat(12.12))
+# isinteger
+@test isinteger(BigFloat(12))
+@test !isinteger(BigFloat(12.12))
# nextfloat / prevfloat
with_bigfloat_precision(53) do
Something went wrong with that request. Please try again.