Skip to content

Commit bf27146

Browse files
committed
Make indexin first argument accept any iterable
1 parent b73d122 commit bf27146

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

base/array.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,9 +2188,9 @@ julia> indexin(b,a)
21882188
3
21892189
```
21902190
"""
2191-
function indexin(a::AbstractArray, b::AbstractArray)
2191+
function indexin(a, b::AbstractArray)
21922192
bdict = Dict(zip(b, 1:length(b)))
2193-
[get(bdict, i, 0) for i in a]
2193+
map(i -> get(bdict, i, 0), a)
21942194
end
21952195

21962196
function _findin(a, b)

test/arrayops.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,11 @@ end
13961396
# PR #8622 and general indexin tests
13971397
@test indexin([1,3,5,7], [5,4,3]) == [0,3,1,0]
13981398
@test indexin([1 3; 5 7], [5 4; 3 2]) == [0 2; 1 0]
1399+
@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [0,3,4,0]
1400+
@test indexin(6, [1,3,6,6,2]) == 4
1401+
@test indexin([6], [1,3,6,6,2]) == [4]
1402+
@test indexin(3, 2:5) == 2
1403+
@test indexin(3.0, 2:5) == 2
13991404

14001405
#6828 - size of specific dimensions
14011406
let a = Array{Float64}(uninitialized, 10)

0 commit comments

Comments
 (0)