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

Function demo_setDiagMatr

examples/isolated/initialising_matrices.cpp:299–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297
298
299void demo_setDiagMatr() {
300
301 // inline literal (C++ only)
302 DiagMatr a = createDiagMatr(1);
303 setDiagMatr(a, {6_i,5_i});
304 reportDiagMatr(a);
305 destroyDiagMatr(a);
306
307 // vector (C++ only)
308 vector<qcomp> vec {11, 22, 33, 44};
309 DiagMatr b = createDiagMatr(2);
310 setDiagMatr(b, vec);
311 reportDiagMatr(b);
312 destroyDiagMatr(b);
313
314 // compile-time array
315 qcomp arr[4] = {7_i, 8_i, 8, 7};
316 DiagMatr c = createDiagMatr(2);
317 setDiagMatr(c, arr);
318 reportDiagMatr(c);
319 destroyDiagMatr(c);
320
321 // heap pointer
322 int dim = 8;
323 qcomp* ptr = (qcomp*) malloc(dim * sizeof *ptr);
324 for (int i=0; i<dim; i++)
325 ptr[i] = -i*.5_i;
326 DiagMatr d = createDiagMatr(3);
327 setDiagMatr(d, ptr);
328 reportDiagMatr(d);
329 destroyDiagMatr(d);
330
331 // cleanup
332 free(ptr);
333}
334
335
336void demo_syncDiagMatr() {

Callers 1

mainFunction · 0.70

Calls 4

createDiagMatrFunction · 0.85
setDiagMatrFunction · 0.85
reportDiagMatrFunction · 0.85
destroyDiagMatrFunction · 0.85

Tested by

no test coverage detected