Pretty Printing#
- pepflow.pprint_str(string: str) None#
Pretty-print the string in LaTeX format.
- Parameters:
string (str) – The string to be printed.
Example
>>> pprint_str("x_0")
- pepflow.pprint_matrix(mat: ndarray, precision: int = 3) None#
Pretty-print the matrix in LaTeX format.
- Parameters:
mat (np.ndarray) – The matrix to be printed.
precision (int) – Number of decimal places to display for each value. Defaults to 3.
Example
>>> mat = np.array([[0.0, 0.5], [0.0, 0.0]]) >>> pprint_matrix(mat)
- pepflow.pprint_labeled_vector(vec: ndarray | LambdaType, labels: list[str], precision: int = 3, print_label: bool = True, return_vector: bool = False) ndarray | None#
Prints a vector with corresponding labels.
This function displays a vector (typically coefficients of function values) using a list of strings as labels. The matrix can be provided either directly as a NumPy array or as a function mapping labels to values. Optionally, the printed values can be formatted to a given precision.
- Parameters:
mat (np.ndarray | types.FunctionType) – A vector, a function that returns vector values given labels.
labels (list[str]) – List of strings to use as labels.
precision (int) – Number of decimal places to display for each value. Defaults to 3.
print_label (bool) – Whether to display the labels. Defaults to True.
return_vector (bool) – If True, returns the constructed vector as a NumPy array. Defaults to False.
- Returns:
np.ndarray | None – The vector as a NumPy array if return_vector=True, otherwise None.
Example
>>> vec = np.array([0.5, 0.125]) >>> tags = ["f(x_0)", "f(x_1)"] >>> pprint_labeled_vector(vec, tags)
- pepflow.pprint_labeled_matrix(mat: ndarray | LambdaType | MatrixWithNames, row_labels: list[str] | None = None, column_labels: list[str] | None = None, precision: int = 3, print_label: bool = True, return_matrix: bool = False) ndarray | None#
Prints a matrix with corresponding row and column labels.
This function displays a matrix (typically representing dual variables), using a list of strings (mostly tags) as labels for rows and columns. The matrix can be provided either directly as a NumPy array or as a function mapping index pairs to values. Optionally, the printed values can be formatted to a given precision.
- Parameters:
mat (np.ndarray | types.FunctionType |
MatrixWithNames) – A matrix, a function that returns matrix values given row and column labels, or a MatrixWithNames object.row_labels (list[str] | None) – List of strings to use as row labels. When None, the function works only mat is a
MatrixWithNamesobjectcolumn_labels (list[str] | None) – List of strings to use as column labels. When None, the function works only for square matrices with equal row and column labels.
precision (int) – Number of decimal places to display for each value. Defaults to 3.
print_label (bool) – Whether to display the labels. Defaults to True.
return_matrix (bool) – If True, returns the constructed matrix as a NumPy array. Defaults to False.
- Returns:
np.ndarray | None – The matrix as a NumPy array if return_matrix=True, otherwise None.
Example
>>> mat = np.array([[0.0, 0.5], [0.0, 0.0]]) >>> tags = ["x1", "x2"] >>> pprint_labeled_matrix(mat, tags)