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

Function util_tryAllocMatrix

quest/src/core/utilities.cpp:1209–1231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1207
1208
1209void util_tryAllocMatrix(vector<vector<qcomp>> &matr, qindex numRows, qindex numCols, std::function<void()> errFunc) {
1210
1211 // this function resizes the matrix, not only reserving it,
1212 // such that matr.size() will subsequently return 'numRows'
1213 // (unless numCols=0), and matr[0].size() will return 'numCols'
1214
1215 if (numRows == 0 || numCols == 0)
1216 return;
1217
1218 try {
1219 // alloc span of rows
1220 matr.resize(numRows);
1221
1222 // alloc each row (serially enumerate since we expected matrix is small/tractable)
1223 for (qindex r=0; r<numRows; r++)
1224 matr[r].resize(numCols);
1225
1226 } catch (std::bad_alloc &e) {
1227 errFunc();
1228 } catch (std::length_error &e) {
1229 errFunc();
1230 }
1231}

Callers 4

allocateMatrixQuadrantsFunction · 0.85
getDensityQuregAmpsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected