feat: Add pretty display functionality and negative index support #133
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This pull request introduces enhancements to the
Matrix
class by adding functionality for pretty displaying matrix data and supporting negative indices in matrix display methods. These changes are aimed at improving the readability and usability of matrix and array representations, particularly for debugging and data analysis.Details
Pretty Display Functionality
New Methods Added
prettyDisplay()
: Displays the entire matrix with optional column and row indices.prettyDisplay(boolean)
: Allows toggling the display of row and column indices.prettyDisplay(int)
: Displays a specific row of the matrix with optional row and column indices.prettyDisplay(int, boolean)
: Provides the option to show row and column indices for a specific row.prettyDisplay(double[][])
: Static method to pretty print a 2D array with optional index display.prettyDisplay(double[][], boolean)
: Static method to pretty print a 2D array with index display option.prettyDisplay(double[][], int)
: Static method to pretty print a specific row of a 2D array with optional index display.prettyDisplay(double[][], int, boolean)
: Static method to pretty print a specific row of a 2D array with customizable index display.Features and Enhancements
<null_matrix>
or<null_2darray>
as appropriate.InvalidIndexException
for out-of-bounds indices, with clear error messages.Support for Negative Indices
display(int)
method to support negative indices. Negative indices are interpreted as counting from the end of the matrix (e.g.,-1
for the last row,-2
for the second-to-last row).InvalidIndexException
with a descriptive message if the index is out of bounds.display(double[][], int)
method to support negative indices similarly.Impact
Functionality
prettyDisplay()
methods provide enhanced visualization of matrix data, making it easier to read and analyze.Backward Compatibility
Examples
Example Code
Here's how you might use the new
prettyDisplay()
and updateddisplay()
methods in practice:Example Output
Given the example matrix data, the output would look like this:
Notes