-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTranspose.py
More file actions
92 lines (65 loc) · 2.25 KB
/
Transpose.py
File metadata and controls
92 lines (65 loc) · 2.25 KB
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
# Programmed by: jasdev
#
import flame
import laff as laff
def Transpose_unb_var1(A, B):
"""
Transpose_unb_var1(matrix, matrix)
Transposes matrix A and stores result in matrix B.
Traverses matrix A from LEFT to RIGHT,
matrix B from TOP to BOTTOM,
and copies columns of A to rows of B.
"""
AL, AR = flame.part_1x2(A, \
0, 'LEFT')
BT, \
BB = flame.part_2x1(B, \
0, 'TOP')
while AL.shape[1] < A.shape[1]:
A0, a1, A2 = flame.repart_1x2_to_1x3(AL, AR, \
1, 'RIGHT')
B0, \
b1t, \
B2 = flame.repart_2x1_to_3x1(BT, \
BB, \
1, 'BOTTOM')
laff.copy( a1, b1t )
AL, AR = flame.cont_with_1x3_to_1x2(A0, a1, A2, \
'LEFT')
BT, \
BB = flame.cont_with_3x1_to_2x1(B0, \
b1t, \
B2, \
'TOP')
flame.merge_2x1(BT, \
BB, B)
def Transpose_unb_var2(A, B):
"""
Transpose_unb_var1(matrix, matrix)
Transposes matrix A and stores result in matrix B.
Traverses matrix A from TOP to BOTTOM,
matrix B from LEFT to RIGHT,
and copies rows of A to columns of B.
"""
AT, \
AB = flame.part_2x1(A, \
0, 'TOP')
BL, BR = flame.part_1x2(B, \
0, 'LEFT')
while AT.shape[0] < A.shape[0]:
A0, \
a1t, \
A2 = flame.repart_2x1_to_3x1(AT, \
AB, \
1, 'BOTTOM')
B0, b1, B2 = flame.repart_1x2_to_1x3(BL, BR, \
1, 'RIGHT')
laff.copy( a1t, b1 )
AT, \
AB = flame.cont_with_3x1_to_2x1(A0, \
a1t, \
A2, \
'TOP')
BL, BR = flame.cont_with_1x3_to_1x2(B0, b1, B2, \
'LEFT')
flame.merge_1x2(BL, BR, B)