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

Add deprecation for equalto and occursin #26480

Merged
merged 1 commit into from
Mar 19, 2018
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
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ Library improvements
* `diagm` now accepts several diagonal index/vector `Pair`s ([#24047]).

* `isequal`, `==`, and `in` have one argument "curried" forms. For example `isequal(x)`
returns a function that compares its argument to `x` using `isequal` ([#23812]).
returns a function that compares its argument to `x` using `isequal` ([#26436]).

* `reinterpret` now works on any AbstractArray using the new `ReinterpretArray` type.
This supersedes the old behavior of reinterpret on Arrays. As a result, reinterpreting
Expand Down Expand Up @@ -1287,7 +1287,6 @@ Command-line option changes
[#23750]: https://github.com/JuliaLang/julia/issues/23750
[#23757]: https://github.com/JuliaLang/julia/issues/23757
[#23805]: https://github.com/JuliaLang/julia/issues/23805
[#23812]: https://github.com/JuliaLang/julia/issues/23812
[#23816]: https://github.com/JuliaLang/julia/issues/23816
[#23885]: https://github.com/JuliaLang/julia/issues/23885
[#23902]: https://github.com/JuliaLang/julia/issues/23902
Expand Down Expand Up @@ -1414,4 +1413,5 @@ Command-line option changes
[#26262]: https://github.com/JuliaLang/julia/issues/26262
[#26284]: https://github.com/JuliaLang/julia/issues/26284
[#26286]: https://github.com/JuliaLang/julia/issues/26286
[#26442]: https://github.com/JuliaLang/julia/issues/26442
[#26436]: https://github.com/JuliaLang/julia/issues/26436
[#26442]: https://github.com/JuliaLang/julia/issues/26442
6 changes: 3 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ end

findall(x::Bool) = x ? [1] : Vector{Int}()
findall(testf::Function, x::Number) = testf(x) ? [1] : Vector{Int}()
findall(p::OccursIn, x::Number) = x in p.x ? [1] : Vector{Int}()
findall(p::Fix2{typeof(in)}, x::Number) = x in p.x ? [1] : Vector{Int}()

"""
findmax(itr) -> (x, index)
Expand Down Expand Up @@ -2208,7 +2208,7 @@ function _sortedfindin(v, w)
return out
end

function findall(pred::OccursIn{<:Union{Array{<:Real},Real}}, x::Array{<:Real})
function findall(pred::Fix2{typeof(in),<:Union{Array{<:Real},Real}}, x::Array{<:Real})
if issorted(x, Sort.Forward) && issorted(pred.x, Sort.Forward)
return _sortedfindin(x, pred.x)
else
Expand All @@ -2217,7 +2217,7 @@ function findall(pred::OccursIn{<:Union{Array{<:Real},Real}}, x::Array{<:Real})
end
# issorted fails for some element types so the method above has to be restricted
# to element with isless/< defined.
findall(pred::OccursIn, x::Union{AbstractArray, Tuple}) = _findin(x, pred.x)
findall(pred::Fix2{typeof(in)}, x::Union{AbstractArray, Tuple}) = _findin(x, pred.x)

# Copying subregions
function indcopy(sz::Dims, I::Vector)
Expand Down
6 changes: 4 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,8 @@ end
findfirstnot(B::BitArray) = findnextnot(B,1)

# returns the index of the first matching element
function findnext(pred::EqualTo, B::BitArray, start::Integer)
function findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool},
B::BitArray, start::Integer)
v = pred.x
v == false && return findnextnot(B, start)
v == true && return findnext(B, start)
Expand Down Expand Up @@ -1581,7 +1582,8 @@ end
findlastnot(B::BitArray) = findprevnot(B, length(B))

# returns the index of the previous matching element
function findprev(pred::EqualTo, B::BitArray, start::Integer)
function findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool},
B::BitArray, start::Integer)
v = pred.x
v == false && return findprevnot(B, start)
v == true && return findprev(B, start)
Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,12 @@ end
# Issue #26248
@deprecate conj(x) x

# PR #26436
@deprecate equalto(x) isequal(x)
@deprecate(occursin(x), in(x))
Copy link
Member

Choose a reason for hiding this comment

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

Why the parens?

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise it parses as occursin(x) in x

Copy link
Member

Choose a reason for hiding this comment

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

d'oh!

@deprecate_binding EqualTo Base.Fix2{typeof(isequal)} false
@deprecate_binding OccursIn Base.Fix2{typeof(in)} false

# Remove ambiguous CartesianIndices and LinearIndices constructors that are ambiguous between an axis and an array (#26448)
@eval IteratorsMD @deprecate CartesianIndices(inds::Vararg{AbstractUnitRange{Int},N}) where {N} CartesianIndices(inds)
@eval IteratorsMD @deprecate CartesianIndices(inds::Vararg{AbstractUnitRange{<:Integer},N}) where {N} CartesianIndices(inds)
Expand Down
8 changes: 4 additions & 4 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -435,18 +435,18 @@ read(io::GenericIOBuffer) = read!(io,StringVector(bytesavailable(io)))
readavailable(io::GenericIOBuffer) = read(io)
read(io::GenericIOBuffer, nb::Integer) = read!(io,StringVector(min(nb, bytesavailable(io))))

function findfirst(delim::EqualTo{UInt8}, buf::IOBuffer)
function findfirst(delim::Fix2{<:Union{typeof(isequal),typeof(==)},UInt8}, buf::IOBuffer)
p = pointer(buf.data, buf.ptr)
q = GC.@preserve buf ccall(:memchr,Ptr{UInt8},(Ptr{UInt8},Int32,Csize_t),p,delim.x,bytesavailable(buf))
q == C_NULL && return nothing
return Int(q-p+1)
end

function findfirst(delim::EqualTo{UInt8}, buf::GenericIOBuffer)
function findfirst(isdelim::Fix2{<:Union{typeof(isequal),typeof(==)},UInt8}, buf::GenericIOBuffer)
data = buf.data
for i = buf.ptr : buf.size
for i = buf.ptr:buf.size
@inbounds b = data[i]
if b == delim.x
if isdelim(b)
return i - buf.ptr + 1
end
end
Expand Down
4 changes: 0 additions & 4 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,6 @@ used to implement specialized methods.
"""
isequal(x) = Fix2(isequal, x)

const EqualTo = Fix2{typeof(isequal)}

"""
==(x)
Expand All @@ -861,8 +859,6 @@ used to implement specialized methods.
"""
in(x) = Fix2(in, x)

const OccursIn = Fix2{typeof(in)}

"""
splat(f)
Expand Down
3 changes: 2 additions & 1 deletion base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ precompile(Tuple{typeof(Base.find_env), Array{Base.AbstractEnv, 1}})
precompile(Tuple{typeof(Base.find_env), Base.CurrentEnv})
precompile(Tuple{typeof(Base.find_env), Base.NamedEnv})
precompile(Tuple{typeof(Base.find_env), typeof(Pkg.dir)})
precompile(Tuple{typeof(Base.findfirst), Base.EqualTo{UInt8}, Base.GenericIOBuffer{Array{UInt8, 1}}})
precompile(Tuple{typeof(Base.findfirst), Base.Fix2{typeof(isequal),UInt8}, Base.GenericIOBuffer{Array{UInt8, 1}}})
precompile(Tuple{typeof(Base.findfirst), Base.Fix2{typeof(==),UInt8}, Base.GenericIOBuffer{Array{UInt8, 1}}})
precompile(Tuple{typeof(Base.first), Base.OneTo{Int64}})
precompile(Tuple{typeof(Base.firstindex), String})
precompile(Tuple{typeof(Base.flush), Base.IOStream})
Expand Down
20 changes: 12 additions & 8 deletions base/strings/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

nothing_sentinel(i) = i == 0 ? nothing : i

function findnext(pred::EqualTo{<:AbstractChar}, s::String, i::Integer)
function findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:AbstractChar},
s::String, i::Integer)
if i < 1 || i > sizeof(s)
i == sizeof(s) + 1 && return nothing
throw(BoundsError(s, i))
Expand All @@ -13,14 +14,15 @@ function findnext(pred::EqualTo{<:AbstractChar}, s::String, i::Integer)
while true
i = _search(s, first_utf8_byte(c), i)
i == 0 && return nothing
s[i] == c && return i
pred(s[i]) && return i
i = nextind(s, i)
end
end

findfirst(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray) = nothing_sentinel(_search(a, pred.x))
findfirst(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray) =
nothing_sentinel(_search(a, pred.x))

findnext(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) =
findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) =
nothing_sentinel(_search(a, pred.x, i))

function _search(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer = 1)
Expand All @@ -44,21 +46,23 @@ function _search(a::ByteArray, b::AbstractChar, i::Integer = 1)
end
end

function findprev(pred::EqualTo{<:AbstractChar}, s::String, i::Integer)
function findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:AbstractChar},
s::String, i::Integer)
c = pred.x
c '\x7f' && return nothing_sentinel(_rsearch(s, c % UInt8, i))
b = first_utf8_byte(c)
while true
i = _rsearch(s, b, i)
i == 0 && return nothing
s[i] == c && return i
pred(s[i]) && return i
i = prevind(s, i)
end
end

findlast(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray) = nothing_sentinel(_rsearch(a, pred.x))
findlast(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray) =
nothing_sentinel(_rsearch(a, pred.x))

findprev(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) =
findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) =
nothing_sentinel(_rsearch(a, pred.x, i))

function _rsearch(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer = sizeof(a))
Expand Down
3 changes: 2 additions & 1 deletion stdlib/Pkg3/src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ precompile(Tuple{typeof(Base.copy), Array{Base.UUID, 1}})
precompile(Tuple{typeof(Base.copyto!), Array{Any, 1}, Tuple{String, Base.VersionNumber, String, String}})
precompile(Tuple{typeof(Base.copyto!), Array{Any, 1}, Tuple{String, Base.VersionNumber}})
precompile(Tuple{typeof(Base.count), Base.BitArray{1}})
precompile(Tuple{typeof(Base.count), Base.EqualTo{Char}, String})
precompile(Tuple{typeof(Base.count), Base.Fix2{typeof(isequal),Char}, String})
precompile(Tuple{typeof(Base.count), Base.Fix2{typeof(==),Char}, String})
precompile(Tuple{typeof(Base.deepcopy), Base.Dict{String, Any}})
precompile(Tuple{typeof(Base.deepcopy_internal), Array{Base.Dict{String, Any}, 1}, Base.IdDict{Any, Any}})
precompile(Tuple{typeof(Base.deepcopy_internal), Base.Dict{Any, Any}, Base.IdDict{Any, Any}})
Expand Down
4 changes: 2 additions & 2 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,8 @@ function findall(p::Function, S::SparseMatrixCSC)

return inds
end
findall(p::Base.OccursIn, x::SparseMatrixCSC) =
invoke(findall, Tuple{Base.OccursIn, AbstractArray}, p, x)
findall(p::Base.Fix2{typeof(in)}, x::SparseMatrixCSC) =
invoke(findall, Tuple{Base.Fix2{typeof(in)}, AbstractArray}, p, x)

function findnz(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti}
numnz = nnz(S)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/SparseArrays/src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ function findall(p::Function, x::SparseVector{<:Any,Ti}) where Ti

return I
end
findall(p::Base.OccursIn, x::SparseVector{<:Any,Ti}) where {Ti} =
invoke(findall, Tuple{Base.OccursIn, AbstractArray}, p, x)
findall(p::Base.Fix2{typeof(in)}, x::SparseVector{<:Any,Ti}) where {Ti} =
invoke(findall, Tuple{Base.Fix2{typeof(in)}, AbstractArray}, p, x)

function findnz(x::SparseVector{Tv,Ti}) where {Tv,Ti}
numnz = nnz(x)
Expand Down
2 changes: 1 addition & 1 deletion test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ end
@test length(0.0:-0.5) == 0
@test length(1:2:0) == 0
end
@testset "findall(::OccursIn, ::Array)" begin
@testset "findall(::Base.Fix2{typeof(in)}, ::Array)" begin
@test findall(in(3:20), [5.2, 3.3]) == findall(in(Vector(3:20)), [5.2, 3.3])

let span = 5:20,
Expand Down