| 397 | } |
| 398 | |
| 399 | sample_result |
| 400 | sample_result::get_marginal(const std::vector<std::size_t> &marginalIndices, |
| 401 | const std::string_view registerName) const { |
| 402 | const auto &counts = retrieve_result(registerName.data()).counts; |
| 403 | auto mutableIndices = marginalIndices; |
| 404 | |
| 405 | std::sort(mutableIndices.begin(), mutableIndices.end()); |
| 406 | |
| 407 | ExecutionResult sr; |
| 408 | for (auto &[bits, count] : counts) { |
| 409 | std::string newBits; |
| 410 | for ([[maybe_unused]] auto &m : mutableIndices) |
| 411 | newBits += "0"; |
| 412 | for (int counter = 0; auto &index : mutableIndices) { |
| 413 | if (index > bits.size()) |
| 414 | throw std::runtime_error("Invalid marginal index (" + |
| 415 | std::to_string(index) + |
| 416 | ", size=" + std::to_string(bits.size())); |
| 417 | |
| 418 | newBits[counter++] = bits[index]; |
| 419 | } |
| 420 | sr.appendResult(newBits, count); |
| 421 | } |
| 422 | |
| 423 | return sample_result(sr); |
| 424 | } |
| 425 | |
| 426 | void sample_result::clear() { |
| 427 | sampleResults.clear(); |
no test coverage detected