Skip to content

Commit 4ce0865

Browse files
changed all push_backs to emplace_back
added const ref for amplitudes in rotationsToDisentangle
1 parent 50f7a60 commit 4ce0865

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/algorithms/StatePreparation.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ template <typename T>
8888
for (size_t i = 0; i < matrixVec.size(); ++i) {
8989
sum += matrixVec[i] * vector[i];
9090
}
91-
result.push_back(sum);
91+
result.emplace_back(sum);
9292
}
9393
return result;
9494
}
@@ -175,7 +175,7 @@ template <typename T>
175175
// works out Ry and Rz rotation angles used to disentangle LSB qubit
176176
// rotations make up block diagonal matrix U
177177
[[nodiscard]] auto
178-
rotationsToDisentangle(std::vector<std::complex<double>> amplitudes, double EPS)
178+
rotationsToDisentangle(std::vector<std::complex<double>>& const amplitudes, double EPS)
179179
-> std::tuple<std::vector<std::complex<double>>, std::vector<double>,
180180
std::vector<double>> {
181181
std::vector<std::complex<double>> remainingVector;
@@ -184,10 +184,10 @@ rotationsToDisentangle(std::vector<std::complex<double>> amplitudes, double EPS)
184184
for (size_t i = 0; i < (amplitudes.size() / 2); ++i) {
185185
auto [remains, theta, phi] =
186186
blochAngles(amplitudes[2 * i], amplitudes[2 * i + 1], EPS);
187-
remainingVector.push_back(remains);
187+
remainingVector.emplace_back(remains);
188188
// minus sign because we move it to zero
189-
thetas.push_back(-theta);
190-
phis.push_back(-phi);
189+
thetas.emplace_back(-theta);
190+
phis.emplace_back(-phi);
191191
}
192192
return {remainingVector, thetas, phis};
193193
}
@@ -222,7 +222,7 @@ gatesToUncompute(std::vector<std::complex<double>>& amplitudes,
222222
// qubit directly the controls are collected and then newly set
223223
std::vector<qc::Control> newControls;
224224
for (const auto& control : op->getControls()) {
225-
newControls.push_back(
225+
newControls.emplace_back(
226226
qc::Control{control.qubit + static_cast<Qubit>(i)});
227227
}
228228
op->setControls(qc::Controls{newControls.begin(), newControls.end()});
@@ -244,7 +244,7 @@ gatesToUncompute(std::vector<std::complex<double>>& amplitudes,
244244
// qubit directly the controls are collected and then newly set
245245
std::vector<qc::Control> newControls;
246246
for (const auto& control : op->getControls()) {
247-
newControls.push_back(
247+
newControls.emplace_back(
248248
qc::Control{control.qubit + static_cast<Qubit>(i)});
249249
}
250250
op->setControls(qc::Controls{newControls.begin(), newControls.end()});

0 commit comments

Comments
 (0)