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

Function createCompMatr

quest/src/api/matrices.cpp:213–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211
212
213extern "C" CompMatr createCompMatr(int numQubits) {
214 validate_envIsInit(__func__);
215 validate_newCompMatrParams(numQubits, __func__);
216
217 // validation ensures these never overflow
218 qindex numRows = powerOf2(numQubits);
219 qindex numElems = numRows * numRows;
220
221 // attempt to allocate 1D memory
222 qcomp* cpuMem = cpu_allocArray(numElems); // nullptr if failed
223 qcomp* gpuMem = nullptr;
224 if (getQuESTEnv().isGpuAccelerated)
225 gpuMem = gpu_allocArray(numElems); // nullptr if failed
226
227 // prepare output CompMatr (avoiding C++20 designated initialiser)
228 CompMatr out;
229 out.numQubits = numQubits;
230 out.numRows = numRows;
231
232 // attemptedly allocate (un-initialised) flags in the heap so that struct copies are mutable
233 out.isApproxUnitary = util_allocEpsilonSensitiveHeapFlag(); // nullptr if failed
234 out.isApproxHermitian = util_allocEpsilonSensitiveHeapFlag();
235 out.wasGpuSynced = cpu_allocHeapFlag(); // nullptr if failed
236
237 // attemptedly allocate 2D alias for 1D CPU memory
238 out.cpuElems = cpu_allocAndInitMatrixWrapper(cpuMem, numRows); // nullptr if failed
239 out.cpuElemsFlat = cpuMem;
240 out.gpuElemsFlat = gpuMem;
241
242 validateMatrixAllocs(out, __func__);
243 setInitialHeapFlags(out);
244 return out;
245}
246
247
248extern "C" DiagMatr createDiagMatr(int numQubits) {

Callers 15

SECTIONFunction · 0.85
SECTIONFunction · 0.85
createInlineCompMatrFunction · 0.85
_createInlineCompMatrFunction · 0.85
demo_setInlineCompMatrFunction · 0.85
demo_setCompMatrFunction · 0.85
demo_syncCompMatrFunction · 0.85
demo_CompMatrFunction · 0.85

Calls 11

validate_envIsInitFunction · 0.85
powerOf2Function · 0.85
cpu_allocArrayFunction · 0.85
getQuESTEnvFunction · 0.85
gpu_allocArrayFunction · 0.85
cpu_allocHeapFlagFunction · 0.85
validateMatrixAllocsFunction · 0.85
setInitialHeapFlagsFunction · 0.85

Tested by

no test coverage detected