@@ -83,6 +83,7 @@ template <typename T>
83
83
const std::vector<double >& vector)
84
84
-> std::vector<double> {
85
85
std::vector<double > result;
86
+ result.reserve (matrix.size ());
86
87
for (const auto & matrixVec : matrix) {
87
88
double sum{0 };
88
89
for (size_t i = 0 ; i < matrixVec.size (); ++i) {
@@ -175,13 +176,20 @@ template <typename T>
175
176
// works out Ry and Rz rotation angles used to disentangle LSB qubit
176
177
// rotations make up block diagonal matrix U
177
178
[[nodiscard]] auto
178
- rotationsToDisentangle (const std::vector<std::complex<double >>& amplitudes, double EPS)
179
+ rotationsToDisentangle (const std::vector<std::complex<double >>& amplitudes,
180
+ double EPS)
179
181
-> std::tuple<std::vector<std::complex<double >>, std::vector<double >,
180
182
std::vector<double >> {
183
+ size_t amplitudesHalf = amplitudes.size () / 2 ;
181
184
std::vector<std::complex<double >> remainingVector;
182
185
std::vector<double > thetas;
183
186
std::vector<double > phis;
184
- for (size_t i = 0 ; i < (amplitudes.size () / 2 ); ++i) {
187
+
188
+ remainingVector.reserve (amplitudesHalf);
189
+ thetas.reserve (amplitudesHalf);
190
+ phis.reserve (amplitudesHalf);
191
+
192
+ for (size_t i = 0 ; i < amplitudesHalf; ++i) {
185
193
auto [remains, theta, phi] =
186
194
blochAngles (amplitudes[2 * i], amplitudes[2 * i + 1 ], EPS);
187
195
remainingVector.emplace_back (remains);
0 commit comments