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

deprecate array-reducing isinteger #19925

Merged
merged 1 commit into from
Jan 15, 2017
Merged
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 @@ -2,11 +2,10 @@

## Basic functions ##

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)
Copy link
Member

Choose a reason for hiding this comment

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

With this change, we will lose this optimization. It seems to be blocked by the bounds check in all; adding @inbounds to all allows the loop to be optimized away.

Copy link
Member

Choose a reason for hiding this comment

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

We might want to add

all{T<:Integer}(::typeof(isinteger), ::AbstractArray{T}) = true
all{T<:Real}(::typeof(isreal), ::AbstractArray{T}) = true

Copy link
Member Author

Choose a reason for hiding this comment

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

As opposed or in addition to decorating all with @inbounds as you suggest above? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I think adding @inbounds to all is not safe unless we add a specialization for Array (where we know iteration never goes out of bounds).

Copy link
Member Author

Choose a reason for hiding this comment

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

Specializations added. Thanks!

isreal{T<:Real,n}(x::AbstractArray{T,n}) = true
all{T<:Integer}(::typeof(isinteger), ::AbstractArray{T}) = true

## Constructors ##

Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,9 @@ function frexp{T<:AbstractFloat}(A::Array{T})
return (F, E)
end

# Deprecate reducing isinteger over arrays
@deprecate isinteger(A::AbstractArray) all(isinteger, 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
5 changes: 1 addition & 4 deletions base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
"""
isinteger(x) -> Bool

Test whether `x` or all its elements are numerically equal to some integer.
Test whether `x` is numerically equal to some integer.

```jldoctest
julia> isinteger(4.0)
true

julia> isinteger([1; 2; 5.5])
false
```
"""
isinteger(x::Integer) = true
Expand Down
2 changes: 1 addition & 1 deletion test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ let
end

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

# unary ops
Expand Down
2 changes: 1 addition & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ end
X = get(A, -5:5, NaN32)
@test eltype(X) == Float32
@test Base.elsize(X) == sizeof(Float32)
@test !isinteger(X)
@test !all(isinteger, X)
@test isnan.(X) == [trues(6);falses(5)]
@test X[7:11] == [1:5;]
X = get(A, (2:4, 9:-2:-13), 0)
Expand Down