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

Mention square matrices in strassen docs and make it more clear #9839

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions divide_and_conquer/strassen_matrix_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def print_matrix(matrix: list) -> None:
def actual_strassen(matrix_a: list, matrix_b: list) -> list:
"""
Recursive function to calculate the product of two matrices, using the Strassen
Algorithm. It only supports even length matrices.
Algorithm. It only supports square matrices of any size that is a power of 2.
"""
if matrix_dimensions(matrix_a) == (2, 2):
return default_matrix_multiplication(matrix_a, matrix_b)
Expand Down Expand Up @@ -129,8 +129,8 @@ def strassen(matrix1: list, matrix2: list) -> list:
new_matrix1 = matrix1
new_matrix2 = matrix2

# Adding zeros to the matrices so that the arrays dimensions are the same and also
# power of 2
# Adding zeros to the matrices to convert them both into square matrices of equal
# dimensions that are a power of 2
for i in range(maxim):
if i < dimension1[0]:
for _ in range(dimension1[1], maxim):
Expand Down