Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix indexin for new Dict syntax #8622

Merged
merged 2 commits into from
Oct 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter, but this could easily be a one-liner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed. I wanted to make it look more fancy then it is :D. Thanks for merging.

On 08 Oct 2014, at 23:56, Jeff Bezanson [email protected] wrote:

In 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)
    Doesn't matter, but this could easily be a one-liner.


Reply to this email directly or view it on GitHub.

end
@test pr8622() == [0,3,1,0]