hi guys, i wonder if any of you know of a more efficient way to rank an array
currently i am using
A=[45, 4, 7, 10, 25, 36, 36, 22, 31, 16] # input vector
T=f.(B[S]) #output vector
this correctly produces
T = [100, 1, 4, 9, 36, 64, 81, 25, 49, 16]
this to me looks wildly inefficient, is there a better way?
sortperm for obtaining just the sorting permutation.
hey Tamas, thank you,
but apparently it doesnt do much it works!
rank_vector(f,A::AbstractVector) = f.(rank_vector(A))
rank_vector2(f,A::AbstractVector) = f.(rank_vector2(A))
9.799 μs (7 allocations: 23.88 KiB)
3.600 μs (6 allocations: 24.33 KiB)
27.600 μs (7 allocations: 23.88 KiB)
12.900 μs (8 allocations: 23.89 KiB)
I imagine that the sorting/inversion will dominate in any case, so I am not sure it is possible to make this more efficient for general
Note however that in your integer benchmarks you have a lot of repetition for
Ints. Depending on whether this is a feature of your data and your need for a stable sort, you may be able to come up with a faster specialized algorithm (I assume your data is large, which is why you want to make this efficient).
Sorry man, i had a typo in my code, your suggestion actually works!