MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / reorder

Method reorder

runtime/common/SampleResult.cpp:488–513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486}
487
488void sample_result::reorder(const std::vector<std::size_t> &idx,
489 const std::string_view registerName) {
490 // First process the counts
491 auto &result = retrieve_result(registerName.data());
492 CountsDictionary newCounts;
493 for (auto [bits, count] : result.counts) {
494 if (idx.size() != bits.size())
495 throw std::runtime_error("Calling reorder() with invalid parameter idx");
496
497 std::string newBits(bits);
498 int i = 0;
499 for (auto oldIdx : idx)
500 newBits[i++] = bits[oldIdx];
501 newCounts[newBits] = count;
502 }
503 result.counts = newCounts;
504
505 // Now process the sequential data
506 for (auto &s : result.sequentialData) {
507 std::string newBits(s);
508 int i = 0;
509 for (auto oldIdx : idx)
510 newBits[i++] = s[oldIdx];
511 s = newBits;
512 }
513}
514} // namespace cudaq

Callers 4

processResultsMethod · 0.80
processResultsMethod · 0.80
processResultsMethod · 0.80

Calls 2

dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected