Hello,

I am currently using the neat ability to be able to subset (create 
matrices) Vectors by passing Int array into the [...]. When using this 
technique with Matrix, one needs to first create a subset vector and subset 
that one by the indices array. If it is a bit cryptic, look at the code. I 
found several ways how to do it and one is obviously worse than the others. 
I am thinking whether it is possible to somehow possible to use macro to 
turn method number 1, which is much clearer on what I am doing to methods 2 
or 3?

a = randn(1000, 10)

a[:,1][[[1,2] [4,5]]]

[a[[1,2],1] a[[4,5],1]]

map(x -> a[x,1], [[1,2] [4,5]])

julia> @time [a[:,1][[[1,2] [4,5]]] for i=1:100000];
elapsed time: 0.633139678 seconds (848791888 bytes allocated, 64.28% gc 
time)

julia> @time [[a[[1,2],1] a[[4,5],1]] for i=1:100000];
elapsed time: 0.087069917 seconds (40791888 bytes allocated, 28.08% gc time)

julia> @time [map(x -> a[x,1], [[1,2] [4,5]]) for i=1:100000];
elapsed time: 0.106718602 seconds (37683260 bytes allocated, 25.91% gc time)

Thanks for advice!

Reply via email to