From 1299fbf64eb48ea868c39bffd85125d5a6a85eeb Mon Sep 17 00:00:00 2001 From: Jutho Haegeman Date: Wed, 8 Oct 2014 15:51:47 +0200 Subject: [PATCH 1/2] fix indexin for new Dict syntax --- base/array.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/array.jl b/base/array.jl index 67b832fcbed17..cb18f7e9c70ea 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1148,7 +1148,7 @@ indmin(a) = findmin(a)[2] # similar to Matlab's ismember # returns a vector containing the highest index in b for each value in a that is a member of b function indexin(a::AbstractArray, b::AbstractArray) - bdict = Dict(b, 1:length(b)) + bdict = Dict(zip(b, 1:length(b))) [get(bdict, i, 0) for i in a] end From 032fb9a5da9dc1c17743b9955b0cb8fc0bb4f825 Mon Sep 17 00:00:00 2001 From: Jutho Haegeman Date: Wed, 8 Oct 2014 23:09:37 +0200 Subject: [PATCH 2/2] add test for indexin --- test/arrayops.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/arrayops.jl b/test/arrayops.jl index 0d1116a70239b..55c40e4e928c8 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -902,3 +902,11 @@ function i7197() ind2sub(size(S), 5) 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]