From 6e4ebe34e4f2e22dd306c9a0af7587d1bd6929a4 Mon Sep 17 00:00:00 2001 From: gopinath-vasalamarri Date: Fri, 15 Aug 2025 22:34:58 +0000 Subject: [PATCH] Improve the performance of get_detcost() function. More information -- https://docs.google.com/spreadsheets/d/17fL_NVWe7XjwGmdBIts75YFuzUmokUyfd_YMEU9ISXY/edit?gid=0#gid=0 --- src/tesseract.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/tesseract.cc b/src/tesseract.cc index 97c8f4d8..293fc907 100644 --- a/src/tesseract.cc +++ b/src/tesseract.cc @@ -17,6 +17,7 @@ #include #include // For boost::hash_range #include +#include #include // For std::hash (though not strictly necessary here, but good practice) #include @@ -85,24 +86,26 @@ bool Node::operator>(const Node& other) const { double TesseractDecoder::get_detcost( size_t d, const std::vector& detector_cost_tuples) const { double min_cost = INF; + uint32_t min_det_cost = std::numeric_limits::infinity(); double error_cost; ErrorCost ec; DetectorCostTuple dct; for (int ei : d2e[d]) { ec = error_costs[ei]; - if (ec.min_cost >= min_cost) break; + if (ec.likelihood_cost * min_det_cost >= min_cost * errors[ei].symptom.detectors.size()) break; dct = detector_cost_tuples[ei]; if (!dct.error_blocked) { - error_cost = ec.likelihood_cost / dct.detectors_count; - if (error_cost < min_cost) { + error_cost = ec.likelihood_cost; + if (error_cost < min_cost * dct.detectors_count) { min_cost = error_cost; + min_det_cost = dct.detectors_count; } } } - return min_cost + config.det_penalty; + return (min_cost / min_det_cost) + config.det_penalty; } TesseractDecoder::TesseractDecoder(TesseractConfig config_) : config(config_) {