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

Function assertMatrixFieldsAreValid

quest/src/core/validation.cpp:2369–2391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2367// T can be CompMatr1, CompMatr2, CompMatr, DiagMatr1, DiagMatr2, DiagMatr, FullStateDiagMatr
2368template <class T>
2369void 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}
2392void validate_matrixFields(CompMatr1 m, const char* caller) { assertMatrixFieldsAreValid(m, 1, report::INVALID_COMP_MATR_1_FIELDS, caller); }
2393void validate_matrixFields(CompMatr2 m, const char* caller) { assertMatrixFieldsAreValid(m, 2, report::INVALID_COMP_MATR_2_FIELDS, caller); }
2394void validate_matrixFields(CompMatr m, const char* caller) { assertMatrixFieldsAreValid(m, m.numQubits, report::INVALID_COMP_MATR_FIELDS, caller); }

Callers 1

validate_matrixFieldsFunction · 0.85

Calls 4

util_getMatrixDimFunction · 0.85
assertThatFunction · 0.85
powerOf2Function · 0.85

Tested by

no test coverage detected