-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrmv_ln.py
109 lines (82 loc) · 3.06 KB
/
Trmv_ln.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Programmed by: Jasdev Singh
#
import flame
import laff as laff
def Trmv_ln_unb_var1(L, x):
"""
Trmv_ln_unb_var1(matrix, vector)
Computes y = L * x using DOT products.
L is the lower triangular matrix.
Traverses matrix L from BOTTOM-RIGHT to TOP-LEFT,
vector x from BOTTOM to TOP.
"""
LTL, LTR, \
LBL, LBR = flame.part_2x2(L, \
0, 0, 'BR')
xT, \
xB = flame.part_2x1(x, \
0, 'BOTTOM')
while LBR.shape[0] < L.shape[0]:
L00, l01, L02, \
l10t, lambda11, l12t, \
L20, l21, L22 = flame.repart_2x2_to_3x3(LTL, LTR, \
LBL, LBR, \
1, 1, 'TL')
x0, \
chi1, \
x2 = flame.repart_2x1_to_3x1(xT, \
xB, \
1, 'TOP')
laff.scal( lambda11, chi1 )
laff.dots( l10t, x0, chi1 )
LTL, LTR, \
LBL, LBR = flame.cont_with_3x3_to_2x2(L00, l01, L02, \
l10t, lambda11, l12t, \
L20, l21, L22, \
'BR')
xT, \
xB = flame.cont_with_3x1_to_2x1(x0, \
chi1, \
x2, \
'BOTTOM')
flame.merge_2x1(xT, \
xB, x)
def Trmv_ln_unb_var2(L, x):
"""
Trmv_ln_unb_var2(matrix, vector)
Computes y = L * x using AXPY operations.
L is the lower triangular matrix.
Traverses matrix L from BOTTOM-RIGHT to TOP-LEFT,
vector x from BOTTOM to TOP.
"""
LTL, LTR, \
LBL, LBR = flame.part_2x2(L, \
0, 0, 'BR')
xT, \
xB = flame.part_2x1(x, \
0, 'BOTTOM')
while LBR.shape[0] < L.shape[0]:
L00, l01, L02, \
l10t, lambda11, l12t, \
L20, l21, L22 = flame.repart_2x2_to_3x3(LTL, LTR, \
LBL, LBR, \
1, 1, 'TL')
x0, \
chi1, \
x2 = flame.repart_2x1_to_3x1(xT, \
xB, \
1, 'TOP')
laff.axpy( chi1, l21, x2 )
laff.scal( lambda11, chi1 )
LTL, LTR, \
LBL, LBR = flame.cont_with_3x3_to_2x2(L00, l01, L02, \
l10t, lambda11, l12t, \
L20, l21, L22, \
'BR')
xT, \
xB = flame.cont_with_3x1_to_2x1(x0, \
chi1, \
x2, \
'BOTTOM')
flame.merge_2x1(xT, \
xB, x)