Skip to content

Commit c93659d

Browse files
tianyizheng02github-actions
and
github-actions
authored
Fix type error in strassen_matrix_multiplication.py (#8784)
* Fix type error in strassen_matrix_multiplication.py * updating DIRECTORY.md --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 4b79d77 commit c93659d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
* [Mergesort](divide_and_conquer/mergesort.py)
295295
* [Peak](divide_and_conquer/peak.py)
296296
* [Power](divide_and_conquer/power.py)
297+
* [Strassen Matrix Multiplication](divide_and_conquer/strassen_matrix_multiplication.py)
297298

298299
## Dynamic Programming
299300
* [Abbreviation](dynamic_programming/abbreviation.py)

divide_and_conquer/strassen_matrix_multiplication.py.BROKEN divide_and_conquer/strassen_matrix_multiplication.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,19 @@ def strassen(matrix1: list, matrix2: list) -> list:
112112
[[139, 163], [121, 134], [100, 121]]
113113
"""
114114
if matrix_dimensions(matrix1)[1] != matrix_dimensions(matrix2)[0]:
115-
raise Exception(
116-
"Unable to multiply these matrices, please check the dimensions. \n"
117-
f"Matrix A:{matrix1} \nMatrix B:{matrix2}"
115+
msg = (
116+
"Unable to multiply these matrices, please check the dimensions.\n"
117+
f"Matrix A: {matrix1}\n"
118+
f"Matrix B: {matrix2}"
118119
)
120+
raise Exception(msg)
119121
dimension1 = matrix_dimensions(matrix1)
120122
dimension2 = matrix_dimensions(matrix2)
121123

122124
if dimension1[0] == dimension1[1] and dimension2[0] == dimension2[1]:
123125
return [matrix1, matrix2]
124126

125-
maximum = max(dimension1, dimension2)
127+
maximum = max(*dimension1, *dimension2)
126128
maxim = int(math.pow(2, math.ceil(math.log2(maximum))))
127129
new_matrix1 = matrix1
128130
new_matrix2 = matrix2

0 commit comments

Comments
 (0)