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

Function demo_setCompMatr

examples/isolated/initialising_matrices.cpp:149–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147
148
149void demo_setCompMatr() {
150
151 // inline literal (C++ only)
152 CompMatr a = createCompMatr(1);
153 setCompMatr(a, {{1,2_i},{3_i+.1,-4}});
154 reportCompMatr(a);
155 destroyCompMatr(a);
156
157 // 2D vector (C++ only)
158 vector<vector<qcomp>> vec {
159 {-9,-8, -8, -9},
160 {7, 7, 6, 6},
161 {0, -1, -2, -3},
162 {-4_i, -5_i, 0, 0}
163 };
164 CompMatr b = createCompMatr(2);
165 setCompMatr(b, vec);
166 reportCompMatr(b);
167 destroyCompMatr(b);
168
169 // nested pointers
170 int dim = 8;
171 qcomp** ptrs = (qcomp**) malloc(dim * sizeof *ptrs);
172 for (int i=0; i<dim; i++) {
173 ptrs[i] = (qcomp*) malloc(dim * sizeof **ptrs);
174 for (int j=0; j<dim; j++)
175 ptrs[i][j] = i + j*1i;
176 }
177 CompMatr c = createCompMatr(3);
178 setCompMatr(c, ptrs);
179 reportCompMatr(c);
180 destroyCompMatr(c);
181
182 // array of pointers (decays, so C++ supported)
183 qcomp* ptrArr[8];
184 for (int i=0; i<dim; i++)
185 ptrArr[i] = ptrs[i];
186 CompMatr d = createCompMatr(3);
187 setCompMatr(d, ptrArr);
188 reportCompMatr(d);
189 destroyCompMatr(d);
190
191 // cleanup
192 for (int i=0; i<dim; i++)
193 free(ptrs[i]);
194 free(ptrs);
195}
196
197
198void demo_syncCompMatr() {

Callers 1

mainFunction · 0.70

Calls 4

createCompMatrFunction · 0.85
setCompMatrFunction · 0.85
reportCompMatrFunction · 0.85
destroyCompMatrFunction · 0.85

Tested by

no test coverage detected