From 64cb4048a85cdaaf5175bcb511ce23d261bb2f71 Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Thu, 20 Oct 2022 12:37:38 +0000 Subject: [PATCH] fix topk bug which cause ctc score diff --- speechx/speechx/utils/math.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/speechx/speechx/utils/math.cc b/speechx/speechx/utils/math.cc index 289470f6c..959740a05 100644 --- a/speechx/speechx/utils/math.cc +++ b/speechx/speechx/utils/math.cc @@ -79,10 +79,12 @@ void TopK(const std::vector& data, int cur = values->size() - 1; while (!pq.empty()) { const auto& item = pq.top(); - pq.pop(); - + (*values)[cur] = item.first; (*indices)[cur] = item.second; + + // item if reference, must pop here + pq.pop(); cur--; } @@ -93,4 +95,4 @@ template void TopK(const std::vector& data, std::vector* values, std::vector* indices); -} // namespace ppspeech \ No newline at end of file +} // namespace ppspeech