| 164 | |
| 165 | |
| 166 | extern "C" PauliStrSum createPauliStrSum(PauliStr* strings, qcomp* coeffs, qindex numTerms) { |
| 167 | |
| 168 | // note we do not require nor impose the strings to be unique |
| 169 | validate_newPauliStrSumParams(numTerms, __func__); |
| 170 | |
| 171 | // prepare output PauliStrSum (avoiding C++20 designated initialiser) |
| 172 | PauliStrSum out; |
| 173 | out.numTerms = numTerms; |
| 174 | out.strings = cpu_allocPauliStrings(numTerms); // nullptr if failed |
| 175 | out.coeffs = cpu_allocArray(numTerms); // nullptr if failed |
| 176 | out.isApproxHermitian = util_allocEpsilonSensitiveHeapFlag(); // nullptr if failed |
| 177 | |
| 178 | // if either alloc failed, clear both before validation to avoid leak |
| 179 | freeAllMemoryIfAnyAllocsFailed(out); |
| 180 | validate_newPauliStrSumAllocs(out, numTerms*sizeof(PauliStr), numTerms*sizeof(qcomp), __func__); |
| 181 | |
| 182 | // otherwise copy given data into new heap structure, and set initial flags |
| 183 | cpu_copyPauliStrSum(out, strings, coeffs); |
| 184 | util_setFlagToUnknown(out.isApproxHermitian); |
| 185 | |
| 186 | return out; |
| 187 | } |
| 188 | |
| 189 | PauliStrSum createPauliStrSum(vector<PauliStr> strings, vector<qcomp> coeffs) { |
| 190 |
no test coverage detected