feat: Enhance Matrix
class with row/column getters and permutation matrix checks
#134
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 several enhancements to the
Matrix
class, including new methods for row and column retrieval, as well as functionality for checking permutation matrices.Changes Made
Introduce Row and Column Retrieval Methods
getRow(int)
andgetColumn(int)
MethodsThese instance methods allow retrieval of a specific row or column from the matrix based on the provided index. Negative indices are supported to access rows or columns from the end of the matrix.
Static Variants
Static methods
getRow(int, Matrix)
andgetColumn(int, Matrix)
have been added to retrieve rows and columns from a givenMatrix
instance.Alias for Consistency
The
getCol(int)
andgetCol(Matrix, int)
method has been introduced as an alias forgetColumn(int)
andgetColumn(Matrix, int)
respectively to maintain a consistent naming convention across the matrix operations.Add Permutation Matrix Checks
isPermutationMatrix()
This instance method checks if the current matrix is a permutation matrix. A permutation matrix is defined as a square matrix where each row and column contains exactly one
1
and all other entries are0
. It uses theisSquare()
method to verify the matrix's square property and then validates each row and column to confirm the canonical basis array condition.Static
isPermutationMatrix(Matrix m)
This static method checks if a provided
Matrix
instance is a permutation matrix, performing similar checks as the instance method.Static
isPermutationMatrix(double[][] arr)
A static convenience method to determine if a two-dimensional array represents a permutation matrix. It creates a
Matrix
instance from the given array and uses theisPermutationMatrix(Matrix m)
method for the check.Documentation
NullMatrixException
andIllegalMatrixSizeException
).Impact
Enhanced Matrix Functionality
getRow
andgetColumn
methods (including their static variants) improves the flexibility of matrix manipulation by allowing direct access to specific rows and columns. This enhancement is particularly useful for matrix operations where specific rows or columns need to be extracted and analyzed.getCol
as an alias forgetColumn
standardizes the naming conventions, making the API more intuitive and consistent for users.Improved Matrix Validation
isPermutationMatrix()
instance method,isPermutationMatrix(Matrix m)
static method, andisPermutationMatrix(double[][] arr)
static method) provide a robust way to validate matrices against the permutation matrix criteria. This is essential for applications that require verification of matrix properties, such as those involving matrix decompositions or combinatorial algorithms.Backward Compatibility
Matrix
class remains unaffected, while new features can be utilized where needed.Performance Considerations
O(n^2)
and a space complexity ofO(1)
, making them efficient for matrices of reasonable size. However, users should be aware of the potential performance implications for very large matrices.Example Usage
These updates aim to enhance the functionality and usability of the
Matrix
class by providing more robust methods for matrix operations and checks.