Skip to content

Commit

Permalink
Deprecate array-reducing isreal.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Jan 9, 2017
1 parent 8c21ec9 commit 74936b5
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

## Basic functions ##

isreal(x::AbstractArray) = all(isreal,x)
iszero(x::AbstractArray) = all(iszero,x)
isreal{T<:Real,n}(x::AbstractArray{T,n}) = true
all{T<:Real}(::typeof(isreal), ::AbstractArray{T}) = true
all{T<:Integer}(::typeof(isinteger), ::AbstractArray{T}) = true
ctranspose(a::AbstractArray) = error("ctranspose not implemented for $(typeof(a)). Consider adding parentheses, e.g. A*(B*C') instead of A*B*C' to avoid explicit calculation of the transposed matrix.")
transpose(a::AbstractArray) = error("transpose not implemented for $(typeof(a)). Consider adding parentheses, e.g. A*(B*C.') instead of A*B*C' to avoid explicit calculation of the transposed matrix.")
Expand Down
5 changes: 1 addition & 4 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ real{T<:Real}(::Type{Complex{T}}) = T
"""
isreal(x) -> Bool
Test whether `x` or all its elements are numerically equal to some real number.
Test whether `x` is numerically equal to some real number.
```jldoctest
julia> isreal(5.)
true
julia> isreal([4.; complex(0,1)])
false
```
"""
isreal(x::Real) = true
Expand Down
3 changes: 2 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1496,8 +1496,9 @@ function frexp{T<:AbstractFloat}(A::Array{T})
return (F, E)
end

# Deprecate reducing isinteger over arrays
# Deprecate array-reducing isinteger and isreal
@deprecate isinteger(A::AbstractArray) all(isinteger, A)
@deprecate isreal(A::AbstractArray) all(isreal, A)

# Calling promote_op is likely a bad idea, so deprecate its convenience wrapper promote_eltype_op
@deprecate promote_eltype_op(op, As...) promote_op(op, map(eltype, As)...)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function logm(A::StridedMatrix)
end
end

if isreal(A) && ~np_real_eigs
if all(isreal, A) && ~np_real_eigs
return real(retmat)
else
return retmat
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ end
parent(D::Diagonal) = D.diag

ishermitian{T<:Real}(D::Diagonal{T}) = true
ishermitian(D::Diagonal) = isreal(D.diag)
ishermitian(D::Diagonal) = all(isreal, D.diag)
issymmetric(D::Diagonal) = true
isposdef(D::Diagonal) = all(x -> x > 0, D.diag)

Expand Down
2 changes: 1 addition & 1 deletion base/linalg/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getindex(A::Union{Eigen,GeneralizedEigen}, d::Symbol)
throw(KeyError(d))
end

isposdef(A::Union{Eigen,GeneralizedEigen}) = isreal(A.values) && all(x -> x > 0, A.values)
isposdef(A::Union{Eigen,GeneralizedEigen}) = all(isreal, A.values) && all(x -> x > 0, A.values)

"""
eigfact!(A, [B])
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ end

ishermitian(A::Hermitian) = true
ishermitian{T<:Real,S}(A::Symmetric{T,S}) = true
ishermitian{T<:Complex,S}(A::Symmetric{T,S}) = isreal(A.data)
ishermitian{T<:Complex,S}(A::Symmetric{T,S}) = all(isreal, A.data)
issymmetric{T<:Real,S}(A::Hermitian{T,S}) = true
issymmetric{T<:Complex,S}(A::Hermitian{T,S}) = isreal(A.data)
issymmetric{T<:Complex,S}(A::Hermitian{T,S}) = all(isreal, A.data)
issymmetric(A::Symmetric) = true
transpose(A::Symmetric) = A
ctranspose{T<:Real}(A::Symmetric{T}) = A
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ logm(A::LowerTriangular) = logm(A.').'
function sqrtm{T}(A::UpperTriangular{T})
n = checksquare(A)
realmatrix = false
if isreal(A)
if all(isreal, A)
realmatrix = true
for i = 1:n
if real(A[i,i]) < 0
Expand Down
2 changes: 1 addition & 1 deletion test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ end

# isinteger and isreal
@test all(isinteger, Diagonal(rand(1:5, 5))) # reducing isinteger(...) deprecated
@test isreal(Diagonal(rand(5)))
@test all(isreal, Diagonal(rand(5))) # reducing isreal(...) deprecated

# unary ops
let A = Diagonal(rand(1:5,5))
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
cpapd = cholfact(apd, :U, Val{true})
@test rank(cpapd) == n
@test all(diff(diag(real(cpapd.factors))).<=0.) # diagonal should be non-increasing
if isreal(apd)
if all(isreal, apd)
@test apd*inv(cpapd) eye(n)
end
@test full(cpapd) apd
Expand Down

0 comments on commit 74936b5

Please sign in to comment.