MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / createPauliStrSum

Function createPauliStrSum

quest/src/api/paulis.cpp:166–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164
165
166extern "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
189PauliStrSum createPauliStrSum(vector<PauliStr> strings, vector<qcomp> coeffs) {
190

Callers 12

SECTIONFunction · 0.85
createMyHamiltonianFunction · 0.85
createMyObservableFunction · 0.85
createMyHamiltonianFunction · 0.85
createMyObservableFunction · 0.85
prepareRandomPauliStrSumFunction · 0.85
demo_createPauliStrSumFunction · 0.85
prepareRandomPauliStrSumFunction · 0.85
demo_createPauliStrSumFunction · 0.85

Tested by

no test coverage detected