MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / basic_encode

Method basic_encode

QAlg/Encode/Encode.cpp:65–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63};
64
65void Encode::basic_encode(const QVec &q, const std::string& data) {
66
67 for (auto i : data) {
68 if (i != '0' && i != '1') {
69 QCERR_AND_THROW_ERRSTR(run_fail, "Error: The input vector b is error.");
70 }
71 }
72 if (q.size() < data.size()) {
73 QCERR_AND_THROW_ERRSTR(run_fail, "Error: The input qvec q is error.");
74 }
75
76 int k = 0;
77 string data_temp = data;
78 std::reverse(data_temp.begin(), data_temp.end());
79
80 for (auto i : data_temp)
81 {
82 if (i == '1')
83 m_qcircuit << X(q[k]);
84 ++k;
85 }
86
87 for (int i = 0; i < k; ++i) {
88 m_out_qubits.push_back(q[i]);
89 }
90
91}
92
93void Encode::amplitude_encode_recursive(const QVec &q, const std::vector<double>& data)
94{

Callers 1

test_basic_encodingFunction · 0.45

Calls 5

XClass · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by 1

test_basic_encodingFunction · 0.36