Created
November 17, 2015 04:23
-
-
Save Gnimuc/2d10aadd4bc765b96056 to your computer and use it in GitHub Desktop.
[SO] Multiple selection from Julia array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(genconv, I, J) | |
genconv[sub2ind(size(genconv),I,J)] | |
end | |
function bar(genconv, I, J) | |
diag(sub(genconv, I, J)) | |
end | |
function baz(genconv, I, J) | |
[genconv[i,j] for (i,j) in zip(I, J)] | |
end | |
function benchmark() | |
genconv = rand(10000, 20000) | |
I = rand(collect(1:size(genconv)[1]), 10000) | |
J = rand(collect(1:size(genconv)[2]), 10000) | |
# warmup | |
foo(genconv, I, J) | |
bar(genconv, I, J) | |
baz(genconv, I, J) | |
println("foo:") | |
@time foo(genconv, I, J) | |
println("bar:") | |
@time bar(genconv, I, J) | |
println("baz:") | |
@time baz(genconv, I, J) | |
return "finished" | |
end | |
benchmark() |
Author
Gnimuc
commented
Nov 17, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment