-
-
Notifications
You must be signed in to change notification settings - Fork 48.9k
Strassen matrix multiply #13470
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
Strassen matrix multiply #13470
Conversation
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
matrix/strassen_matrix_multiply.py
Outdated
|
|
||
| Matrix = List[List[int]] | ||
|
|
||
| def add(A: Matrix, B: Matrix) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function add
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
matrix/strassen_matrix_multiply.py
Outdated
| n = len(A) | ||
| return [[A[i][j] + B[i][j] for j in range(n)] for i in range(n)] | ||
|
|
||
| def sub(A: Matrix, B: Matrix) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function sub
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
matrix/strassen_matrix_multiply.py
Outdated
| n = len(A) | ||
| return [[A[i][j] - B[i][j] for j in range(n)] for i in range(n)] | ||
|
|
||
| def naive_mul(A: Matrix, B: Matrix) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function naive_mul
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
| ci[j] += a_ik * bk[j] | ||
| return C | ||
|
|
||
| def next_power_of_two(n: int) -> int: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function next_power_of_two
Please provide descriptive name for the parameter: n
matrix/strassen_matrix_multiply.py
Outdated
| p <<= 1 | ||
| return p | ||
|
|
||
| def pad_matrix(A: Matrix, size: int) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function pad_matrix
Please provide descriptive name for the parameter: A
matrix/strassen_matrix_multiply.py
Outdated
|
|
||
| m = next_power_of_two(n_orig) | ||
| if m != n_orig: | ||
| A_pad = pad_matrix(A, m) |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: A_pad
matrix/strassen_matrix_multiply.py
Outdated
| m = next_power_of_two(n_orig) | ||
| if m != n_orig: | ||
| A_pad = pad_matrix(A, m) | ||
| B_pad = pad_matrix(B, m) |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: B_pad
matrix/strassen_matrix_multiply.py
Outdated
| A_pad = pad_matrix(A, m) | ||
| B_pad = pad_matrix(B, m) | ||
| else: | ||
| A_pad, B_pad = A, B |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: A_pad
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: B_pad
matrix/strassen_matrix_multiply.py
Outdated
| else: | ||
| A_pad, B_pad = A, B | ||
|
|
||
| C_pad = _strassen_recursive(A_pad, B_pad, threshold) |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: C_pad
matrix/strassen_matrix_multiply.py
Outdated
| C = unpad_matrix(C_pad, n_orig, n_orig) | ||
| return C | ||
|
|
||
| def _strassen_recursive(A: Matrix, B: Matrix, threshold: int) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function _strassen_recursive
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
for more information, see https://pre-commit.ci
…625/Python into strassen_matrix_multiply
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| https://en.wikipedia.org/wiki/Strassen_algorithm | ||
| """ | ||
|
|
||
| Matrix = list[list[int]] |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Matrix
matrix/strassen_matrix_multiply.py
Outdated
|
|
||
| Matrix = list[list[int]] | ||
|
|
||
| def add(A: Matrix, B: Matrix) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function add
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
matrix/strassen_matrix_multiply.py
Outdated
| return [[A[i][j] + B[i][j] for j in range(n)] for i in range(n)] | ||
|
|
||
|
|
||
| def sub(A: Matrix, B: Matrix) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function sub
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
matrix/strassen_matrix_multiply.py
Outdated
| return [[A[i][j] - B[i][j] for j in range(n)] for i in range(n)] | ||
|
|
||
|
|
||
| def naive_mul(A: Matrix, B: Matrix) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function naive_mul
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
| return C | ||
|
|
||
|
|
||
| def next_power_of_two(n: int) -> int: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function next_power_of_two
Please provide descriptive name for the parameter: n
matrix/strassen_matrix_multiply.py
Outdated
| return [] | ||
|
|
||
| if (m := next_power_of_two(n_orig)) != n_orig: | ||
| A_pad = pad_matrix(A, m) |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: A_pad
matrix/strassen_matrix_multiply.py
Outdated
|
|
||
| if (m := next_power_of_two(n_orig)) != n_orig: | ||
| A_pad = pad_matrix(A, m) | ||
| B_pad = pad_matrix(B, m) |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: B_pad
matrix/strassen_matrix_multiply.py
Outdated
| A_pad = pad_matrix(A, m) | ||
| B_pad = pad_matrix(B, m) | ||
| else: | ||
| A_pad, B_pad = A, B |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: A_pad
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: B_pad
matrix/strassen_matrix_multiply.py
Outdated
| else: | ||
| A_pad, B_pad = A, B | ||
|
|
||
| C_pad = _strassen_recursive(A_pad, B_pad, threshold) |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: C_pad
matrix/strassen_matrix_multiply.py
Outdated
| return C | ||
|
|
||
|
|
||
| def _strassen_recursive(A: Matrix, B: Matrix, threshold: int) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function _strassen_recursive
Please provide descriptive name for the parameter: A
Please provide descriptive name for the parameter: B
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| https://en.wikipedia.org/wiki/Strassen_algorithm | ||
| """ | ||
|
|
||
| Matrix = list[list[int]] |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Matrix
| return result | ||
|
|
||
|
|
||
| def next_power_of_two(n: int) -> int: |
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.
Please provide descriptive name for the parameter: n
| return unpad_matrix(c_pad, n_orig, n_orig) | ||
|
|
||
|
|
||
| def _strassen_recursive(matrix_a: Matrix, matrix_b: Matrix, threshold: int) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function _strassen_recursive
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| https://en.wikipedia.org/wiki/Strassen_algorithm | ||
| """ | ||
|
|
||
| Matrix = list[list[int]] |
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.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Matrix
| return result | ||
|
|
||
|
|
||
| def next_power_of_two(n: int) -> int: |
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.
Please provide descriptive name for the parameter: n
| return unpad_matrix(c_pad, n_orig, n_orig) | ||
|
|
||
|
|
||
| def _strassen_recursive(matrix_a: Matrix, matrix_b: Matrix, threshold: int) -> Matrix: |
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.
As there is no test file in this pull request nor any test function or class in the file matrix/strassen_matrix_multiply.py, please provide doctest for the function _strassen_recursive
|
Closing require_descriptive_names PRs to prepare for Hacktoberfest |
Describe your change:
Checklist: