-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement Matrix , its Methods and Some Functions including Strassen Matrix Multiplication in Go #662
Conversation
- Added the Strassen matrix multiplication algorithm for efficient matrix multiplication. - Added strassenmatrixmultiply.go to include the new algorithm. - Added example usage and test functions for verification. - Introduced benchmarks for performance evaluation. Closes TheAlgorithms#661 (if applicable)
along with the following supporting functions and test cases: 1. `AddMatrices`: Function to add two matrices. 2. `SubtractMatrices`: Function to subtract two matrices. 3. `MultiplyMatrices`: Function to multiply two matrices simply using loops. 4. `PrintMatrix`: Function to print a matrix for debugging purposes. 5. `EqualMatrix`: Function to check if two matrices are equal. 6. `StrassenMatrixMultiply` : Function to multiply two matrices using strassen algorithm
@raklaptudirm , I have made the required changes in the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the Go idiom that you should not repeat the package name. For example, in matrix.AddMatrices
, you are using the word "Matrix" twice. matrix.Add
is a much simpler name and it doesn't lose any information. Change the names accordingly.
Also, you could make some simple functions that find the lenght/breadth of a matrix, given you are trying to find that multiple times.
@raklaptudirm
in which
and
BUT now in many functions simple
Do I need to change them to |
Renamed files and functions: - addmatrices.go to add.go - addmatrices_test.go to add_test.go - matrixmultiply.go to multiply.go - matrixmultiply_test.go to multiply_test.go - subtractmatrices.go to subtract.go - subtractmatrices_test.go to subtract_test.go - printmatrix.go to print.go - printmatrix_test.go to print_test.go New files: - breadth.go - breadth_test.go - checkequal.go - checkequal_test.go - isvalid.go - isvalid_test.go - length.go - length_test.go - samedimensions.go - samedimensions_test.go Modified files: - strassenmatrixmultiply.go - strassenmatrixmultiply_test.go This commit includes renaming and restructuring files for clarity, adding new functionality, and removing some obsolete files.
Don't do a validity check in the Even better, you could make matrix a type with a constructor that ensures that the number of columns in each row is the same. |
This commit introduces a new type, represented as a struct with methods for creating, manipulating, and performing operations on matrices. The following changes have been made: - Added the `Matrix` struct with fields for elements, rows, and columns. - Implemented the `New` function to create a new matrix with specified dimensions and initial values. - Implemented the `NewFromElements` function to create a matrix from a provided 2D slice of elements. - Added the `Get` and `Set` methods to access and modify matrix elements by row and column indices. - Implemented the `Print` method to print the matrix to the console. - Introduced the `SameDimensions` method to check if two matrices have the same dimensions. - Implemented functions for matrix operations, including `Add`, `Subtract`, `Multiply`, and `CheckEqual`. - Added a helper function `IsValid` to check if a given matrix has consistent row lengths. These changes provide a foundation for working with matrices in Go, allowing for easy creation, manipulation, and comparison of matrices.
In this commit, the following key additions have been made to the folder: - Implemented `StrassenMatrixMultiply`, a fast matrix multiplication algorithm, to efficiently multiply two matrices. - Introduced `Copy` method to create a deep copy of a matrix, allowing for independent manipulation without affecting the original matrix. - Implemented `Submatrix` method to extract a submatrix from an existing matrix based on specified row and column indices. - Added `Rows` and `Columns` methods to retrieve rows and columns of matrix. - Included comprehensive test cases to ensure the correctness and robustness of these newly implemented features. These enhancements expand the capabilities of the type, making it more versatile and efficient in performing matrix operations.
Also fix the CI errors. |
In this commit, the following significant changes have been made: 1. Refactored the `Matrix` type from a pointer to a value type. Using a pointer for a small structure like `Matrix` was deemed unnecessary and has been updated to enhance code simplicity. 2. Added comprehensive benchmarks to all functions. These benchmarks will help ensure that the code performs efficiently and allows for easy performance profiling. 3. Fixed code integration errors that were identified during the refactoring process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't reviewed it fully, so will come back to this later. But I've left some thoughts on the PR 😄
…imensions to MatchDimensions, and remove unnecessary code This commit updates the type variable T to constraints.Integer, providing a more specific type constraint. It also renames the SameDimensions function to MatchDimensions for clarity. Additionally, unnecessary code lines have been removed for cleaner and more optimized code.
…ly, SubMatrix, and Subtract functions
…stead of causing a panic.
…an empty matrix is passed as input.
Body: - Updated the Add,Subtract, SubMatrix, and Multiply functions in the matrix package to use the context and sync packages for goroutine management and error handling. - Removed the use of the errgroup package in these functions.
Body: - Updated the Add,Subtract, SubMatrix, and Multiply functions in the matrix package to use the context and sync packages for goroutine management and error handling. - Removed the use of the errgroup package in these functions.
Well done! This is looking much better now 😄 PS: you might need to make an empty commit - the update GoDoc action has stopped the execution of other actions for some reason 😓 |
The GoDoc action has stopped the execution of other actions. This empty commit is a workaround to trigger the other actions to run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very good quality pr, LGTM :)
Title: Implementation of Matrix and Associated Methods in Go
Description:
This pull request introduces several enhancements to the math/matrix directory:
Closes #661 (if applicable)