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

Function printVector

quest/src/core/printer.cpp:1201–1236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1199// T can be any 1D type, e.g. Qureg (.isDensityMatrix=0), FullStateDiagMatr, DiagMatr/1/2
1200template <class T>
1201void printVector(T obj, string indent) {
1202
1203 // divide vector into one of two column vectors (ul and ll; ur and lr stay empty)
1204 qcompmatr ul,ur,ll,lr;
1205 qindex numAmps = powerOf2(obj.numQubits);
1206 MatrixQuadrantInds inds = getTruncatedMatrixQuadrantInds(numAmps, 1);
1207 allocateMatrixQuadrants(inds, ul,ur,ll,lr);
1208 populateMatrixQuadrants(inds, ul,ur,ll,lr, obj);
1209
1210 // rows are only labelled if we're printing a Qureg...
1211 vector<string> upperRowLabels = {};
1212 vector<string> lowerRowLabels = {};
1213 if constexpr (util_isQuregType<T>()) {
1214 upperRowLabels = getBasisKets(inds.upperStartRow, inds.numUpperLeftRows);
1215 lowerRowLabels = getBasisKets(inds.lowerStartRow, inds.numLowerLeftRows);
1216 }
1217
1218 // and/or if the type is distributed
1219 if constexpr (util_isDistributableType<T>())
1220 if (obj.isDistributed)
1221 populateDistributedVectorRowLabels(upperRowLabels, lowerRowLabels, obj, inds);
1222
1223 // columns are never labelled
1224 vector<string> colLabels = {};
1225
1226 // only successively indent each row when vector represets a diagonal matrix
1227 bool indentEachRow = ! util_isQuregType<T>(); // since else diagonal
1228 string indentPerRow = (indentEachRow)? string(SET_SPACE_BETWEEN_DIAG_MATRIX_COLS, MATRIX_SPACE_CHAR) : "";
1229 string ellipsisChar = (indentEachRow)? DDOTS_CHAR : VDOTS_CHAR;
1230
1231 // will print the vector in one or two quadrants (right two quadrants are unpopulated)
1232 printMatrixInFourQuadrants(
1233 ul, ur, ll, lr,
1234 colLabels, colLabels, upperRowLabels, lowerRowLabels,
1235 indent, indentPerRow, ellipsisChar);
1236}
1237
1238
1239void print_elems(DiagMatr1 obj, string indent) { printVector(obj, indent); }

Callers 1

print_elemsFunction · 0.85

Calls 7

powerOf2Function · 0.85
allocateMatrixQuadrantsFunction · 0.85
populateMatrixQuadrantsFunction · 0.85
getBasisKetsFunction · 0.85

Tested by

no test coverage detected