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

* refactor: fix strassen matrix multiplication docs

* refactor: make docs more clear
This commit is contained in:
Saahil Mahato 2023-10-07 15:20:23 +05:45 committed by GitHub
parent 2122474e41
commit 678e0aa8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,7 +74,7 @@ def print_matrix(matrix: list) -> None:
def actual_strassen(matrix_a: list, matrix_b: list) -> list: def actual_strassen(matrix_a: list, matrix_b: list) -> list:
""" """
Recursive function to calculate the product of two matrices, using the Strassen 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): if matrix_dimensions(matrix_a) == (2, 2):
return default_matrix_multiplication(matrix_a, matrix_b) return default_matrix_multiplication(matrix_a, matrix_b)
@ -129,8 +129,8 @@ def strassen(matrix1: list, matrix2: list) -> list:
new_matrix1 = matrix1 new_matrix1 = matrix1
new_matrix2 = matrix2 new_matrix2 = matrix2
# Adding zeros to the matrices so that the arrays dimensions are the same and also # Adding zeros to the matrices to convert them both into square matrices of equal
# power of 2 # dimensions that are a power of 2
for i in range(maxim): for i in range(maxim):
if i < dimension1[0]: if i < dimension1[0]:
for _ in range(dimension1[1], maxim): for _ in range(dimension1[1], maxim):