Skip to content

Commit 3d486b0

Browse files
committed
more fixes
1 parent 96849b6 commit 3d486b0

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

src/simplex.pybind.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <pybind11/pybind11.h>
2222
#include <pybind11/stl.h>
2323

24-
#include <sstream>
25-
2624
#include "common.h"
2725
#include "simplex.h"
2826
#include "stim_utils.pybind.h"
@@ -146,11 +144,10 @@ void add_simplex_module(py::module& root) {
146144
"decode_to_errors",
147145
[](SimplexDecoder& self, const py::array_t<bool>& syndrome) {
148146
if ((size_t)syndrome.size() != self.num_detectors) {
149-
std::ostringstream msg;
150-
msg << "Syndrome array size (" << syndrome.size()
151-
<< ") does not match the number of detectors in the decoder ("
152-
<< self.num_detectors << ").";
153-
throw std::invalid_argument(msg.str());
147+
std::string msg = "Syndrome array size (" + std::to_string(syndrome.size()) +
148+
") does not match the number of detectors in the decoder (" +
149+
std::to_string(self.num_detectors) + ").";
150+
throw std::invalid_argument(msg);
154151
}
155152

156153
std::vector<uint64_t> detections;
@@ -311,11 +308,11 @@ void add_simplex_module(py::module& root) {
311308
size_t num_detectors = syndromes_unchecked.shape(1);
312309

313310
if (num_detectors != self.num_detectors) {
314-
std::ostringstream msg;
315-
msg << "The number of detectors in the input array (" << num_detectors
316-
<< ") does not match the number of detectors in the decoder ("
317-
<< self.num_detectors << ").";
318-
throw std::invalid_argument(msg.str());
311+
std::string msg = "The number of detectors in the input array (" +
312+
std::to_string(num_detectors) +
313+
") does not match the number of detectors in the decoder (" +
314+
std::to_string(self.num_detectors) + ").";
315+
throw std::invalid_argument(msg);
319316
}
320317

321318
// Allocate the result array.

src/tesseract.pybind.h

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <pybind11/pybind11.h>
2222
#include <pybind11/stl.h>
2323

24-
#include <sstream>
25-
2624
#include "stim_utils.pybind.h"
2725
#include "tesseract.h"
2826

@@ -249,15 +247,10 @@ void add_tesseract_module(py::module& root) {
249247
"decode_to_errors",
250248
[](TesseractDecoder& self, const py::array_t<bool>& syndrome) {
251249
if ((size_t)syndrome.size() != self.num_detectors) {
252-
std::ostringstream msg;
253-
msg << "Syndrome array size (" << syndrome.size()
254-
<< ") does not match the number of detectors in the decoder ("
255-
<< self.num_detectors << ").";
256-
std::string msg = "Syndrome array size (" +
257-
std
258-
: to_string(syndrome.size()) +
259-
") does not match the number of detectors in the decoder (" +
260-
std::to_string(self.num_detectors) + ")." throw std::invalid_argument(msg);
250+
std::string msg = "Syndrome array size (" + std::to_string(syndrome.size()) +
251+
") does not match the number of detectors in the decoder (" +
252+
std::to_string(self.num_detectors) + ").";
253+
throw std::invalid_argument(msg);
261254
}
262255

263256
std::vector<uint64_t> detections;
@@ -291,11 +284,10 @@ void add_tesseract_module(py::module& root) {
291284
[](TesseractDecoder& self, const py::array_t<bool>& syndrome, size_t det_order,
292285
size_t det_beam) {
293286
if ((size_t)syndrome.size() != self.num_detectors) {
294-
std::ostringstream msg;
295-
msg << "Syndrome array size (" << syndrome.size()
296-
<< ") does not match the number of detectors in the decoder ("
297-
<< self.num_detectors << ").";
298-
throw std::invalid_argument(msg.str());
287+
std::string msg = "Syndrome array size (" + std::to_string(syndrome.size()) +
288+
") does not match the number of detectors in the decoder (" +
289+
std::to_string(self.num_detectors) + ").";
290+
throw std::invalid_argument(msg);
299291
}
300292

301293
std::vector<uint64_t> detections;
@@ -403,11 +395,10 @@ void add_tesseract_module(py::module& root) {
403395
"decode",
404396
[](TesseractDecoder& self, const py::array_t<bool>& syndrome) {
405397
if ((size_t)syndrome.size() != self.num_detectors) {
406-
std::ostringstream msg;
407-
msg << "Syndrome array size (" << syndrome.size()
408-
<< ") does not match the number of detectors in the decoder ("
409-
<< self.num_detectors << ").";
410-
throw std::invalid_argument(msg.str());
398+
std::string msg = "Syndrome array size (" + std::to_string(syndrome.size()) +
399+
") does not match the number of detectors in the decoder (" +
400+
std::to_string(self.num_detectors) + ").";
401+
throw std::invalid_argument(msg);
411402
}
412403

413404
std::vector<uint64_t> detections;
@@ -461,11 +452,11 @@ void add_tesseract_module(py::module& root) {
461452
size_t num_detectors = syndromes_unchecked.shape(1);
462453

463454
if (num_detectors != self.num_detectors) {
464-
std::ostringstream msg;
465-
msg << "The number of detectors in the input array (" << num_detectors
466-
<< ") does not match the number of detectors in the decoder ("
467-
<< self.num_detectors << ").";
468-
throw std::invalid_argument(msg.str());
455+
std::string msg = "The number of detectors in the input array (" +
456+
std::to_string(num_detectors) +
457+
") does not match the number of detectors in the decoder (" +
458+
std::to_string(self.num_detectors) + ").";
459+
throw std::invalid_argument(msg);
469460
}
470461

471462
// Allocate the result array.

src/tesseract_sinter_compat.pybind.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct TesseractSinterCompiledDecoder {
8383
// Store predictions into the output buffer
8484
uint8_t* single_result_buffer = result_buffer + shot * num_observable_bytes;
8585
std::fill(single_result_buffer, single_result_buffer + num_observable_bytes, 0);
86-
for (int obs_index : predictions) {
86+
for (size_t obs_index : predictions) {
8787
if (obs_index >= 0 && obs_index < num_observables) {
8888
single_result_buffer[obs_index / 8] ^= (1 << (obs_index % 8));
8989
}
@@ -191,7 +191,7 @@ struct TesseractSinterDecoder {
191191

192192
// Pack the predictions back into a bit-packed format.
193193
std::fill(single_result_data.begin(), single_result_data.end(), 0);
194-
for (int obs_index : predictions) {
194+
for (size_t obs_index : predictions) {
195195
if (obs_index >= 0 && obs_index < num_obs) {
196196
single_result_data[obs_index / 8] ^= (1 << (obs_index % 8));
197197
}

0 commit comments

Comments
 (0)