Skip to content

Commit e48d23d

Browse files
committed
Make indexin first argument accept any iterable
1 parent 408cdf1 commit e48d23d

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
@@ -2236,9 +2236,9 @@ julia> indexin(b,a)
22362236
3
22372237
```
22382238
"""
2239-
function indexin(a::AbstractArray, b::AbstractArray)
2239+
function indexin(a, b::AbstractArray)
22402240
bdict = Dict(zip(b, 1:length(b)))
2241-
[get(bdict, i, 0) for i in a]
2241+
map(i -> get(bdict, i, 0), a)
22422242
end
22432243

22442244
function _findin(a, b)

test/arrayops.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,11 @@ end
13731373
# PR #8622 and general indexin tests
13741374
@test indexin([1,3,5,7], [5,4,3]) == [0,3,1,0]
13751375
@test indexin([1 3; 5 7], [5 4; 3 2]) == [0 2; 1 0]
1376+
@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [0,3,4,0]
1377+
@test indexin(6, [1,3,6,6,2]) == 4
1378+
@test indexin([6], [1,3,6,6,2]) == [4]
1379+
@test indexin(3, 2:5) == 2
1380+
@test indexin(3.0, 2:5) == 2
13761381

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

0 commit comments

Comments
 (0)