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
import time | |
import numpy as np | |
def topk(a, k): | |
# idx = a.argsort()[-k:][::-1] # slower (runs in O(n logn) time) | |
idx = np.argpartition(a, -k)[-k:] # faster (runs in linear O(n) time) | |
return a[idx], idx | |
def decode(n): | |
return np.random.rand(n) |