Skip to content
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

Added Strassen's Matrix Multiplication in divide and conquer #958

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

shuvojitss
Copy link
Contributor

@shuvojitss shuvojitss commented Oct 30, 2024

Pull Request for PyVerse 💡

Requesting to submit a pull request to the PyVerse repository.


Issue Title

Please enter the title of the issue related to your pull request.
Strassen's Matrix Multiplication

  • I have provided the issue title.

Info about the Related Issue

What's the goal of the project?
We are given with 2 matrix, our goal is to multiply them such that the time complexity of the calculation is O(n^2.81). We have used divide and conque approach to achieve the time complexity.

  • I have described the aim of the project.

Name

Please mention your name.
Shuvojit Samanta

  • I have provided my name.

GitHub ID

Please mention your GitHub ID.
shuvojitss

  • I have provided my GitHub ID.

Email ID

Please mention your email ID for further communication.
shuvojitsamanta15@gmail.com

  • I have provided my email ID.

Identify Yourself

Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC, SWOC).
GSSOC

  • I have mentioned my participant role.

Closes

Enter the issue number that will be closed through this PR.
Closes: #943

  • I have provided the issue number.

Describe the Add-ons or Changes You've Made

Give a clear description of what you have added or modified.

Algorithm Steps

  1. Input Matrices: Given two n x n matrices, A and B.

  2. Base Case:

    • If n = 1 , return the product A[0][0] x B[0][0] .
  3. Divide:

    • Split each matrix into four n/2 x n/2 submatrices:
  4. Compute Products:

    • Calculate the following seven products:
      1. P1 = A11 x (B12 - B22)
      2. P2 = (A11 + A12) x B22
      3. P3 = (A21 + A22) x B11
      4. P4 = A22 x (B21 - B11)
      5. P5 = (A11 + A22) x (B11 + B22)
      6. P6 = (A12 - A22) x (B21 + B22)
      7. P7 = (A11 - A21) x (B11 + B12)
  5. Combine Results:

    • Compute the four submatrices of the resulting product:
      • C11 = P5 + P4 - P2 + P6
      • C12 = P1 + P2
      • C21 = P3 + P4
      • C22 = P5 + P1 - P3 - P7
  6. Combine Submatrices:

    • Construct the final resulting matrix C from the submatrices.
  7. Output: Return the resulting matrix C .

  • I have described my changes.

Type of Change

Select the type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Describe how your changes have been tested.
I have tetsted it in all python editors and its working. I am providing a sample input output to describe it.

Sample Input:

Enter the elements of the first matrix (2x2):
5 10
15 20
Enter the elements of the second matrix (2x2):
6 8
9 2

Sample Output:

The resultant matrix is:
120     60
270     160
  • I have described my testing process.

Checklist

Please confirm the following:

  • My code follows the guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly wherever it was hard to understand.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added things that prove my fix is effective or that my feature works.
  • Any dependent changes have been merged and published in downstream modules.

Copy link

👋 Thank you for opening this pull request! We're excited to review your contribution. Please give us a moment, and we'll get back to you shortly!

Feel free to join our community on Discord to discuss more!

@UTSAVS26 UTSAVS26 added Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. Status: Review Ongoing PR is currently under review and awaiting feedback from reviewers. level1 gssoc-ext hacktoberfest labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. gssoc-ext hacktoberfest level1 Status: Review Ongoing PR is currently under review and awaiting feedback from reviewers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Code Addition Request]: Strassen's Matrix Multiplication in divide and conquer
2 participants