Skip to content

Commit 2dd71a1

Browse files
committed
2 parents 2d60fe9 + 4a868d0 commit 2dd71a1

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

src/tesseract.cc

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ std::string Node::str() {
7474
ss << "Node(";
7575
ss << "errors=" << self.errors << ", ";
7676
ss << "cost=" << self.cost << ", ";
77-
ss << "num_detectors=" << self.num_detectors << ", ";
77+
ss << "num_dets=" << self.num_dets << ", ";
7878
return ss.str();
7979
}
8080

8181
bool Node::operator>(const Node& other) const {
82-
return cost > other.cost || (cost == other.cost && num_detectors < other.num_detectors);
82+
return cost > other.cost || (cost == other.cost && num_dets < other.num_dets);
8383
}
8484

8585
double TesseractDecoder::get_detcost(
@@ -293,27 +293,27 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
293293
return;
294294
}
295295

296-
size_t min_num_detectors = detections.size();
297-
size_t max_num_detectors = min_num_detectors + detector_beam;
296+
size_t min_num_dets = detections.size();
297+
size_t max_num_dets = min_num_dets + detector_beam;
298298

299299
std::vector<size_t> next_errors;
300300
boost::dynamic_bitset<> next_detectors;
301301
std::vector<DetectorCostTuple> next_detector_cost_tuples;
302302

303-
pq.push({initial_cost, min_num_detectors, std::vector<size_t>()});
303+
pq.push({initial_cost, min_num_dets, std::vector<size_t>()});
304304
size_t num_pq_pushed = 1;
305305

306306
while (!pq.empty()) {
307307
const Node node = pq.top();
308308
pq.pop();
309309

310-
if (node.num_detectors > max_num_detectors) continue;
310+
if (node.num_dets > max_num_dets) continue;
311311

312312
boost::dynamic_bitset<> detectors = initial_detectors;
313313
std::vector<DetectorCostTuple> detector_cost_tuples(num_errors);
314314
flip_detectors_and_block_errors(detector_order, node.errors, detectors, detector_cost_tuples);
315315

316-
if (node.num_detectors == 0) {
316+
if (node.num_dets == 0) {
317317
if (config.create_visualization) {
318318
visualizer.add_activated_errors(node.errors);
319319
visualizer.add_activated_detectors(detectors, num_detectors);
@@ -339,7 +339,7 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
339339
return;
340340
}
341341

342-
if (config.no_revisit_dets && !visited_detectors[node.num_detectors].insert(detectors).second)
342+
if (config.no_revisit_dets && !visited_detectors[node.num_dets].insert(detectors).second)
343343
continue;
344344

345345
if (config.create_visualization) {
@@ -349,9 +349,8 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
349349
if (config.verbose) {
350350
std::cout.precision(13);
351351
std::cout << "len(pq) = " << pq.size() << " num_pq_pushed = " << num_pq_pushed << std::endl;
352-
std::cout << "num_detectors = " << node.num_detectors
353-
<< " max_num_detectors = " << max_num_detectors << " cost = " << node.cost
354-
<< std::endl;
352+
std::cout << "num_dets = " << node.num_dets << " max_num_dets = " << max_num_dets
353+
<< " cost = " << node.cost << std::endl;
355354
std::cout << "activated_errors = ";
356355
for (size_t oei : node.errors) {
357356
std::cout << oei << ", ";
@@ -366,14 +365,14 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
366365
std::cout << std::endl;
367366
}
368367

369-
if (node.num_detectors < min_num_detectors) {
370-
min_num_detectors = node.num_detectors;
368+
if (node.num_dets < min_num_dets) {
369+
min_num_dets = node.num_dets;
371370
if (config.no_revisit_dets) {
372-
for (size_t i = min_num_detectors + detector_beam + 1; i <= max_num_detectors; ++i) {
371+
for (size_t i = min_num_dets + detector_beam + 1; i <= max_num_dets; ++i) {
373372
visited_detectors[i].clear();
374373
}
375374
}
376-
max_num_detectors = std::min(max_num_detectors, min_num_detectors + detector_beam);
375+
max_num_dets = std::min(max_num_dets, min_num_dets + detector_beam);
377376
}
378377

379378
for (size_t d = 0; d < num_detectors; ++d) {
@@ -415,21 +414,21 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
415414
next_detector_cost_tuples[ei].error_blocked = 1;
416415

417416
double next_cost = node.cost + errors[ei].likelihood_cost;
418-
size_t next_num_detectors = node.num_detectors;
417+
size_t next_num_dets = node.num_dets;
419418

420419
for (int d : edets[ei]) {
421420
next_detectors[d] = !next_detectors[d];
422421
int fired = next_detectors[d] ? 1 : -1;
423-
next_num_detectors += fired;
422+
next_num_dets += fired;
424423
for (int oei : d2e[d]) {
425424
next_detector_cost_tuples[oei].detectors_count += fired;
426425
}
427426
}
428427

429-
if (next_num_detectors > max_num_detectors) continue;
428+
if (next_num_dets > max_num_dets) continue;
430429

431-
if (config.no_revisit_dets && visited_detectors[next_num_detectors].find(next_detectors) !=
432-
visited_detectors[next_num_detectors].end())
430+
if (config.no_revisit_dets && visited_detectors[next_num_dets].find(next_detectors) !=
431+
visited_detectors[next_num_dets].end())
433432
continue;
434433

435434
for (int d : edets[ei]) {
@@ -454,7 +453,7 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
454453

455454
if (next_cost == INF) continue;
456455

457-
pq.push({next_cost, next_num_detectors, next_errors});
456+
pq.push({next_cost, next_num_dets, next_errors});
458457
++num_pq_pushed;
459458

460459
if (num_pq_pushed > config.pqlimit) {

src/tesseract.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct TesseractConfig {
5050
class Node {
5151
public:
5252
double cost;
53-
size_t num_detectors;
53+
// The number of activated detectors (dets for short) at this node
54+
size_t num_dets;
5455
std::vector<size_t> errors;
5556

5657
bool operator>(const Node& other) const;
@@ -118,4 +119,4 @@ struct TesseractDecoder {
118119
std::vector<DetectorCostTuple>& detector_cost_tuples) const;
119120
};
120121

121-
#endif // TESSERACT_DECODER_H
122+
#endif // TESSERACT_DECODER_H

src/tesseract.pybind.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,20 @@ void add_tesseract_module(py::module& root) {
205205
This is used internally by the decoder to track decoding progress.
206206
)pbdoc")
207207
.def(py::init<double, size_t, std::vector<size_t>>(), py::arg("cost") = 0.0,
208-
py::arg("num_detectors") = 0, py::arg("errors") = std::vector<size_t>(), R"pbdoc(
208+
py::arg("num_dets") = 0, py::arg("errors") = std::vector<size_t>(), R"pbdoc(
209209
The constructor for the `Node` class.
210210
211211
Parameters
212212
----------
213213
cost : float, default=0.0
214214
The cost of the path to this node.
215-
num_detectors : int, default=0
215+
num_dets : int, default=0
216216
The number of detectors this search node has.
217217
errors : list[int], default=empty
218218
The list of error indices this search node has.
219219
)pbdoc")
220220
.def_readwrite("cost", &Node::cost, "The cost of the node.")
221-
.def_readwrite("num_detectors", &Node::num_detectors,
222-
"The number of detectors this search node has.")
221+
.def_readwrite("num_dets", &Node::num_dets, "The number of detectors this search node has.")
223222
.def_readwrite("errors", &Node::errors, "The list of error indices this search node has.")
224223
.def(py::self > py::self,
225224
"Comparison operator for nodes based on cost. This is necessary to prioritize "

0 commit comments

Comments
 (0)