Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/tesseract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <algorithm>
#include <boost/functional/hash.hpp> // For boost::hash_range
#include <cassert>
#include <cstdint>
#include <functional> // For std::hash (though not strictly necessary here, but good practice)
#include <iostream>

Expand Down Expand Up @@ -85,24 +86,26 @@ bool Node::operator>(const Node& other) const {
double TesseractDecoder::get_detcost(
size_t d, const std::vector<DetectorCostTuple>& detector_cost_tuples) const {
double min_cost = INF;
uint32_t min_det_cost = std::numeric_limits<uint32_t>::infinity();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the std::numeric_limits<T>::infinity() applies for uint32_t? if it is only for floating-point types then this could become zero and later we might face division by zero issues!

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you are replacing the div with mul 👏🏻

min_cost = error_cost;
min_det_cost = dct.detectors_count;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can have a more discriptive name for this variable, something like min_cost_det_cnt?

}
}
}

return min_cost + config.det_penalty;
return (min_cost / min_det_cost) + config.det_penalty;
}

TesseractDecoder::TesseractDecoder(TesseractConfig config_) : config(config_) {
Expand Down
Loading