Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tbd: deprecate array-reducing isreal #19996

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

isinteger(x::AbstractArray) = all(isinteger,x)
isinteger{T<:Integer,n}(x::AbstractArray{T,n}) = true
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
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: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,9 @@ function frexp{T<:AbstractFloat}(A::Array{T})
return (F, E)
end

# Deprecate array-reducing isreal
@deprecate isreal(A::AbstractArray) all(isreal, A)

# Deprecate promote_eltype_op (#19814, #19937)
_promote_eltype_op(::Any) = Any
_promote_eltype_op(op, A) = (@_inline_meta; promote_op(op, eltype(A)))
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated, but shouldn't this be !np_real_eigs instead of ~np_real_eigs ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought so, but apparently ~(x::Bool) is a synonym for !x (~ being bitwise not)?

Copy link
Contributor

@tkelman tkelman Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they happen to be equivalent for Bool, but I suspect this was written more out of matlab-habit than intentionally

Copy link
Member Author

@Sacha0 Sacha0 Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will touch that up if this pull request goes forward. Otherwise will open a touchup PR. Thanks!

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 isinteger(Diagonal(rand(1:5,5)))
@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