-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScale_a_matrix.py
60 lines (42 loc) · 1.37 KB
/
Scale_a_matrix.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Programmed by: Jasdev Singh
#
import flame
import laff as laff
def Scale_a_matrix_unb_var1(beta, A):
"""
Scale_a_matrix_unb_var1(scalar, matrix)
Scales matrix A by a factor of beta.
Traverses matrix A from LEFT to RIGHT.
"""
AL, AR = flame.part_1x2(A, \
0, 'LEFT')
while AL.shape[1] < A.shape[1]:
A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \
1, 'RIGHT')
laff.scal(beta,a1)
AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \
'LEFT')
flame.merge_1x2(AL, AR, A)
def Scale_a_matrix_unb_var2(beta, A):
"""
Scale_a_matrix_unb_var2(scalar, matrix)
Scales matrix A by a factor of beta.
Traverses matrix A from TOP to BOTTOM.
"""
AT, \
AB = flame.part_2x1(A, \
0, 'TOP')
while AT.shape[0] < A.shape[0]:
A0, \
a1t, \
A2 = flame.repart_2x1_to_3x1(AT, \
AB, \
1, 'BOTTOM')
laff.scal(beta,a1t)
AT, \
AB = flame.cont_with_3x1_to_2x1(A0, \
a1t, \
A2, \
'TOP')
flame.merge_2x1(AT, \
AB, A)