Skip to content

Commit

Permalink
Make indexin first argument accept any iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Sep 27, 2017
1 parent 88253a5 commit 372d179
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2230,11 +2230,13 @@ julia> indexin(b,a)
3
```
"""
function indexin(a::AbstractArray, b::AbstractArray)
function indexin(a, b::AbstractArray)
bdict = Dict(zip(b, 1:length(b)))
[get(bdict, i, 0) for i in a]
end

indexin(a::T, b::AbstractArray{T}) where {T} = findlast(b, a)

function _findin(a, b)
ind = Int[]
bset = Set(b)
Expand Down
5 changes: 5 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,11 @@ end
# PR #8622 and general indexin tests
@test indexin([1,3,5,7], [5,4,3]) == [0,3,1,0]
@test indexin([1 3; 5 7], [5 4; 3 2]) == [0 2; 1 0]
@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [0,3,4,0]
@test indexin(6, [1,3,6,6,2]) == 4
@test indexin([6], [1,3,6,6,2]) == [4]
@test indexin(3, 2:5) == 2
@test_broken indexin(3.0, 2:5) == 2

#6828 - size of specific dimensions
let a = Array{Float64}(10)
Expand Down

0 comments on commit 372d179

Please sign in to comment.