| 2367 | // T can be CompMatr1, CompMatr2, CompMatr, DiagMatr1, DiagMatr2, DiagMatr, FullStateDiagMatr |
| 2368 | template <class T> |
| 2369 | void assertMatrixFieldsAreValid(T matr, int expectedNumQb, string badFieldMsg, const char* caller) { |
| 2370 | |
| 2371 | qindex dim = util_getMatrixDim(matr); |
| 2372 | tokenSubs vars = { |
| 2373 | {"${NUM_QUBITS}", matr.numQubits}, |
| 2374 | {"${NUM_ROWS}", dim}}; |
| 2375 | |
| 2376 | // assert correct fixed-size numQubits (caller gaurantees this passes for dynamic-size), |
| 2377 | // where the error message string already contains the expected numQb |
| 2378 | assertThat(matr.numQubits == expectedNumQb, badFieldMsg, vars, caller); |
| 2379 | |
| 2380 | // validate .numQubits and .numRows or .numElems |
| 2381 | qindex expectedDim = powerOf2(matr.numQubits); |
| 2382 | assertThat(matr.numQubits >= 1, badFieldMsg, vars, caller); |
| 2383 | assertThat(dim == expectedDim, badFieldMsg, vars, caller); |
| 2384 | |
| 2385 | if constexpr (util_isHeapMatrixType<T>()) |
| 2386 | assertAdditionalHeapMatrixFieldsAreValid(matr, caller); |
| 2387 | |
| 2388 | // we do not bother checking slightly more involved fields like numAmpsPerNode - there's |
| 2389 | // no risk that they're wrong (because they're const so users cannot modify them) unless |
| 2390 | // the struct was unitialised, which we have already validated against |
| 2391 | } |
| 2392 | void validate_matrixFields(CompMatr1 m, const char* caller) { assertMatrixFieldsAreValid(m, 1, report::INVALID_COMP_MATR_1_FIELDS, caller); } |
| 2393 | void validate_matrixFields(CompMatr2 m, const char* caller) { assertMatrixFieldsAreValid(m, 2, report::INVALID_COMP_MATR_2_FIELDS, caller); } |
| 2394 | void validate_matrixFields(CompMatr m, const char* caller) { assertMatrixFieldsAreValid(m, m.numQubits, report::INVALID_COMP_MATR_FIELDS, caller); } |
no test coverage detected