| 1207 | |
| 1208 | |
| 1209 | void 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 | } |
no outgoing calls
no test coverage detected