Skip to content

Commit

Permalink
implement correct behavior for findin function with (Any,b::UnitRange…
Browse files Browse the repository at this point in the history
…) argument
  • Loading branch information
gajomi committed Jan 11, 2016
1 parent ef59efe commit 75336c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 1 addition & 14 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -863,22 +863,9 @@ function indexin(a::AbstractArray, b::AbstractArray)
[get(bdict, i, 0) for i in a]
end

# findin (the index of intersection)
function findin(a, b::UnitRange)
ind = Array(Int, 0)
f = first(b)
l = last(b)
for i = 1:length(a)
if f <= a[i] <= l
push!(ind, i)
end
end
ind
end

function findin(a, b)
ind = Array(Int, 0)
bset = Set(b)
bset = unique(b)
@inbounds for i = 1:length(a)
a[i] in bset && push!(ind, i)
end
Expand Down
2 changes: 2 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ r = 5:-1:1
@test isempty((1:4)[5:4])
@test_throws BoundsError (1:10)[8:-1:-2]

@test findin([5.2, 3.3], 3:20) == findin([5.2, 3.3], collect(3:20))

let
span = 5:20
r = -7:3:42
Expand Down

0 comments on commit 75336c6

Please sign in to comment.