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

Function printMatrixInFourQuadrants

quest/src/core/printer.cpp:700–779  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

698
699
700void printMatrixInFourQuadrants(
701 qcompmatr upperLeft, qcompmatr upperRight,
702 qcompmatr lowerLeft, qcompmatr lowerRight,
703 vector<string> leftColLabels, vector<string> rightColLabels, // shown above the first row
704 vector<string> upperRowLabels, vector<string> lowerRowLabels, // shown right of the last column
705 string baseIndent, string indentPerRow, string verticalEllipsis
706) {
707 // this function prints a matrix which has been prior divided into one, two or four
708 // quadrants, resulting from reporter truncation of the original matrix. It can be
709 // used to print truncated (or non-truncated) non-square matrices, horizontal and
710 // vertical vectors, diagonal matrices, and lists of scalars (e.g. Pauli coefficients)
711
712 // the below preconditions are assumed but not enforced:
713 // - it is valid for lowerLeft to be empty, implying upperLeft contains entire columns;
714 // in that scenario, lowerRight must also be empty
715 // - it is valid for upperRight to be empty, implying upperLeft contains entire rows;
716 // in that scenario, lowerRight must also be empty
717 // - it is valid for upperRight=lowerLeft=lowerRight to be empty, implying upperLeft
718 // contains the entire matrix
719 // - it is valid for qcompmatr={} (empty), but it is INVALID to be {{}} (reported non-empty)
720 // - it is INVALID for any qcompmatr to have an inconsistent number of columns across its rows
721 // - it is INVALID for upperLeft and lowerLeft to differ in #columns, though #rows can vary;
722 // the same applies to upperRight and lowerRight
723 // - it is INVALID for upperLeft and upperRight to differ in #rows, though #columns can vary;
724 // the same applies to lowerLeft and lowerRight
725 // - it is INVALID for upperLeft to ever be empty
726 // - it is valid for leftColLabels=rightColLabels to be empty, but otherwise...
727 // - leftColLabels must match the #cols in upperLeft (can contain empty strings)
728 // - rightColLabels must similarly match the #cols in upperRight
729 // - it is valid for upperRight=lowerRight to be empty, while lowerLeft is not empty;
730 // this would be the case when printing a vector. Non-distributed vectors like this
731 // are fine, although distributed vectors should use a separate, bespoke routine since
732 // this function cannot display labeled ranks spanning vertically
733
734 if (!comm_isRootNode())
735 return;
736
737 // prepare element strings
738 stringmatr upperLeftStrings = getMatrixOfQcompStrings(upperLeft);
739 stringmatr upperRightStrings = getMatrixOfQcompStrings(upperRight);
740 stringmatr lowerLeftStrings = getMatrixOfQcompStrings(lowerLeft);
741 stringmatr lowerRightStrings = getMatrixOfQcompStrings(lowerRight);
742
743 // decide column widths
744 vector<size_t> leftColWidths = getMaxWidthOfColumns(upperLeftStrings, lowerLeftStrings);
745 vector<size_t> rightColWidths = getMaxWidthOfColumns(upperRightStrings, lowerRightStrings);
746
747 // including consideration of column labels
748 expandMaxWidthsAccordingToLabels(leftColWidths, leftColLabels);
749 expandMaxWidthsAccordingToLabels(rightColWidths, rightColLabels);
750
751 // optionally print all column labels
752 if (!leftColLabels.empty()) {
753 cout << baseIndent;
754 printRowInTwoQuadrants(leftColLabels, leftColWidths, rightColLabels, rightColWidths);
755 cout << endl;
756 }
757

Callers 3

printDenseSquareMatrixFunction · 0.85
printVectorFunction · 0.85
print_elemsFunction · 0.85

Calls 7

comm_isRootNodeFunction · 0.85
getMatrixOfQcompStringsFunction · 0.85
getMaxWidthOfColumnsFunction · 0.85
printRowInTwoQuadrantsFunction · 0.85
printPerRowIndentFunction · 0.85

Tested by

no test coverage detected