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 29, 2017
1 parent 408cdf1 commit e48d23d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2236,9 +2236,9 @@ 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]
map(i -> get(bdict, i, 0), a)
end

function _findin(a, 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 indexin(3.0, 2:5) == 2

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

0 comments on commit e48d23d

Please sign in to comment.