From 4398559d6c87114fec3668d76bcd6ed62107251a Mon Sep 17 00:00:00 2001 From: Yaman Umuroglu <maltanar@gmail.com> Date: Mon, 14 Sep 2020 21:12:29 +0200 Subject: [PATCH] [Util] add get_topk --- src/finn/util/test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/finn/util/test.py b/src/finn/util/test.py index 3cd4248c5..e070f8d89 100644 --- a/src/finn/util/test.py +++ b/src/finn/util/test.py @@ -77,6 +77,11 @@ def get_test_model_untrained(netname, wbits, abits): return get_test_model(netname, wbits, abits, pretrained=False) +def get_topk(vec, k): + "Return indices of the top-k values in given array vec (treated as 1D)." + return np.flip(vec.flatten().argsort())[:k] + + def soft_verify_topk(invec, idxvec, k): """Check that the topK indices provided actually point to the topK largest values in the input vector""" -- GitLab