Skip to content

Commit

Permalink
Make indexin first argument accept iterables as well
Browse files Browse the repository at this point in the history
I also fixed the docstring and added a test where a matrix is passed.

Also compactified the tests according to
https://github.com/JuliaLang/julia/pull/8622/files#r18615289
  • Loading branch information
garrison committed Sep 23, 2017
1 parent ff44cc4 commit 804dc88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2201,8 +2201,8 @@ indmin(a) = findmin(a)[2]
"""
indexin(a, b)
Returns a vector containing the highest index in `b` for
each value in `a` that is a member of `b` . The output
Returns an array containing the highest index in `b` for
each value in `a` that is a member of `b`. The output
vector contains 0 wherever `a` is not a member of `b`.
# Examples
Expand All @@ -2227,7 +2227,7 @@ 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
Expand Down
11 changes: 4 additions & 7 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1370,13 +1370,10 @@ function i7197()
end
@test i7197() == (2,2)

# PR #8622 and general indexin test
function pr8622()
x=[1,3,5,7]
y=[5,4,3]
return indexin(x,y)
end
@test pr8622() == [0,3,1,0]
# PR #8622 and general indexin tests
@test indexin([1,3,5,7], [5,4,3]) == [0,3,1,0]
@test indexin((2 * x + 1 for x in 0:3), [5,4,3]) == [0,3,1,0]
@test indexin([1 3; 5 7], [5 4; 3 2]) == [0 2; 1 0]

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

0 comments on commit 804dc88

Please sign in to comment.