-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmult2.py
More file actions
30 lines (26 loc) · 762 Bytes
/
mult2.py
File metadata and controls
30 lines (26 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def brute_mult(A,B):
n = len(A)
result = [[0] * n for _ in A]
for i in range(n):
for j in range(n):
for k in range(n):
result[i][j] += A[i][k] * B[k][j]
return result
def mat_add(A,B):
n = len(A)
result = [[0] * n for _ in A]
for i in range(n):
for j in range(n):
result[i][j] += A[i][j] + B[i][j]
return result
def strassen_mult(A,B):
if len(A)==1:
result = brute_mult(A,B)
return result
def get_quadrant(a, hhalf, vhalf):
n = len(a)
hstart = hhalf * n//2
vstart = vhalf * n//2
return [row[vstart:vstart + n//2] for row in a [hstart:hstart + n//2]]
def assemble (top_left, top_right, bottom_left, bottom_right):
n = len(top_left)