Created
July 10, 2013 06:58
-
-
Save w01fe/5964022 to your computer and use it in GitHub Desktop.
top_k.clj
This file contains hidden or 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
(defn top-k | |
"Return the top k elements of xs according to score-fn" | |
[k score-fn xs] | |
(let [n (count xs) | |
scores (dbl/amake [i n] (score-fn (nth xs i))) | |
^ints idxs (dbl/amax-indices scores k)] | |
(seq (hiphip.array/amake Object [i k] (nth xs (aget idxs (- n i 1))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment