-
Notifications
You must be signed in to change notification settings - Fork 44
/
PictureFLAME.html
324 lines (261 loc) · 10.4 KB
/
PictureFLAME.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Picture FLAME</title>
<link rel="stylesheet" href="style.css">
<script src="parse_code.js"></script
<script src="routines.js"></script>
<script src="routines_2.js"></script>
<script src="display_code.js"></script>
<script src="display_operand.js"></script>
<script src="regions.js"></script>
<script src="animator.js"></script>
<script>
var DEFAULT_SIZE = 5;
var DEFAULT_NB_ALG = 2;
var DEFAULT_MODE = -1;
function detect_mode(code){
//M-script look for ...
var matched = code.match(/\.\.\./g);
if (matched && matched.length != 0){
DEFAULT_MODE = 1;
}
//Python look for \
matched = code.match(/\\/g);
if (matched && matched.length != 0){
DEFAULT_MODE = 2;
}
}
var loopcount = DEFAULT_SIZE;
//matlab expressions
var newlineExpr = /\.\.\.\s*\n/;
var commentExpr = /%.*/g;
var outputExpr = /\[[^=]+\]\s*=/m;
//FLAMEPy expressions
if (DEFAULT_MODE ==2){
newlineExpr = /\\\s*\n/;
commentExpr = /#-*/;
outputExpr = /\[[^=]+\]\s*=/m;
}
function interprete_code(stmtNum){
var stmt = document.getElementById('display_code').childNodes[stmtNum].firstChild.innerHTML;
stmt = stmt.replace(newlineExpr, '\n');
var partExpr = /(_|\.)Part_[12]x[12]/gi;
var repartExpr = /(_|\.)Repart_[12]x[12]_/gi;
var contExpr = /(_|\.)Cont_with_[13]x[13]_/gi;
var oprdExpr = /\(\s*[A-z0-9]+(,|\s)/gim;
var partTypeExpr = /[123]x[123]/;
var partDirExpr = /FLA_(TOP|BOTTOM|LEFT|RIGHT|TL|TR|BL|BR)/;
if (DEFAULT_MODE == 2)
partDirExpr = /'(TOP|BOTTOM|LEFT|RIGHT|TL|TR|BL|BR)/;
var partTest = partExpr.test(stmt);
var repartTest = repartExpr.test(stmt);
var contTest = contExpr.test(stmt);
var operand = null;
if (partTest | repartTest | contTest){
//partition, repartition and continue_with routines
operand = oprdExpr.exec(stmt)[0].replace(/\(\s*/g, '').charAt(0);
for (var i=0; i != operands.length; ++i){
if (operands[i].tag == operand){
if (partTest)
operands[i].partition(
partTypeExpr.exec(stmt)[0],
(DEFAULT_MODE==1?
partDirExpr.exec(stmt)[0].substring(4):
partDirExpr.exec(stmt)[0].substring(1))
);
else if (repartTest)
operands[i].repartition();
else
operands[i].cont_with();
}
}
}
else{
//regular statements
var parsed_stmt = parse_stmt(stmt);
//highlight operands
for (var i = 0; i != parsed_stmt.args.length; ++i){
for (var j = 0; j != operands.length; ++j){
//check if operands[j] needs to be highlighted
//make output (defaulted to last arg) pink
if (operands[j].match(parsed_stmt.args[i].op)){
operands[j].select(parsed_stmt.args[i].subregion,
(i==parsed_stmt.args.length-1?'pink':'lightblue'));
}
}
}
//execute functions
if (parsed_stmt.fn != ''){
//BLAS-like function call
execute_BLAS(parsed_stmt);
}
}
}
var operands;
function make_operand(tag, m, n, i){
var len = operands.push(new Operand(tag, m, n));
return '<div id="'+tag+'" class="operand'+i+'">'+tag+operands[len-1].display()+'</div>';
}
function display_operands(operands){
var output = '';
for (var i = 0; i != operands.length; ++i){
switch (operands[i].length){
case 1: //matrix or column vector
if (operands[i].charCodeAt(0)>=97){ //vector
output += make_operand(operands[i],DEFAULT_SIZE,1, i%2);
}
else{ //vector
output += make_operand(operands[i],DEFAULT_SIZE, DEFAULT_SIZE, i%2);
}
break;
case 2: //row vector
output += make_operand(operands[i].charAt(0), 1, DEFAULT_SIZE, i%2);
break;
default://scalar
output += make_operand(operands[i],1,1, i%2);
break;
}
}
document.getElementById('display_pic').innerHTML = output;
}
var ani = null
function initialize(code){
detect_mode(document.getElementById('code').value);
//parse file
var codeSummary = parse(code);
var fnSummary = parse_fn_header(codeSummary.fn);
display_code(codeSummary.code);
//create operand images
operands = new Array();
display_operands(fnSummary.operands);
//execute FLAME algorithm
ani = new Animator(codeSummary.head, codeSummary.foot, loopcount, document.getElementById('display_code').childNodes.length);
}
function next(){
ani.next_animation();
}
function play(){
document.getElementById('next').disabled = true;
document.getElementById('reload').disabled = true;
document.getElementById('new').disabled = true;
document.getElementById('play').disabled = true;
document.getElementById('stop').disabled = false;
ani.run(stop);
}
function stop(){
document.getElementById('next').disabled = false;
document.getElementById('reload').disabled = false;
document.getElementById('new').disabled = false;
document.getElementById('play').disabled = false;
document.getElementById('stop').disabled = true;
}
function close_input_window(){
document.getElementById('input_group').style.display="none";
}
function open_input_window(){
document.getElementById('input_group').style.display="block";
}
function close_animation_window(){
document.getElementById('animation_group').style.display="none";
}
function open_animation_window(){
document.getElementById('animation_group').style.display="block";
}
function load_program(){
initialize(document.getElementById('code').value);
}
</script>
</head>
<body> <!--onLoad="initialize(document.getElementById('code').value)" -->
<h2>PictureFLAME</h2>
<div id="input_group">
<div id="input_control" class="group_header">
Input Program
<!-- <div style="float:right;color:white;background-color:navy;border:2px solid lightgray;" onClick="close_input_window();load_program();open_animation_window()">
Load
</div>
-->
<input type="button" value="Load Program" onClick="close_input_window();load_program();open_animation_window()"/>
</div>
<div id="input_block">
<textarea id="code" name="code" cols="75" rows="20" style="margin:10px">
function [ A_out, B_out, C_out, D_out ] = Function_Name_unb( A, B, C, D)
[ ATL, ATR, ...
ABL, ABR ] = FLA_Part_2x2( A, ...
0, 0, 'FLA_TL' );
[ BTL, BTR, ...
BBL, BBR ] = FLA_Part_2x2( B, ...
0, 0, 'FLA_BR' );
[ CL, CR ] = FLA_Part_1x2( C, ...
0, 'FLA_LEFT' );
[ DT, ...
DB ] = FLA_Part_2x1( D, ...
0, 'FLA_TOP' );
while ( size( ATL, 1 ) < size( A, 1 ) )
[ A00, A01, A02, ...
A10, A11, A12, ...
A20, A21, A22 ] = FLA_Repart_2x2_to_3x3( ATL, ATR, ...
ABL, ABR, ...
1, 1, 'FLA_BR' );
[ B00, B01, B02, ...
B10, B11, B12, ...
B20, B21, B22 ] = FLA_Repart_2x2_to_3x3( BTL, BTR, ...
BBL, BBR, ...
1, 1, 'FLA_TL' );
[ C0, C1, C2 ]= FLA_Repart_1x2_to_1x3( CL, CR, ...
1, 'FLA_RIGHT' );
[ D0, ...
D1, ...
D2 ] = FLA_Repart_2x1_to_3x1( DT, ...
DB, ...
1, 'FLA_BOTTOM' );
%------------------------------------------------------------%
% update line 1 %
% : %
% update line n %
%------------------------------------------------------------%
[ ATL, ATR, ...
ABL, ABR ] = FLA_Cont_with_3x3_to_2x2( A00, A01, A02, ...
A10, A11, A12, ...
A20, A21, A22, ...
'FLA_TL' );
[ BTL, BTR, ...
BBL, BBR ] = FLA_Cont_with_3x3_to_2x2( B00, B01, B02, ...
B10, B11, B12, ...
B20, B21, B22, ...
'FLA_BR' );
[ CL, CR ] = FLA_Cont_with_1x3_to_1x2( C0, C1, C2, ...
'FLA_LEFT' );
[ DT, ...
DB ] = FLA_Cont_with_3x1_to_2x1( D0, ...
D1, ...
D2, ...
'FLA_TOP' );
end
A_out = [ ATL, ATR
ABL, ABR ];
B_out = [ BTL, BTR
BBL, BBR ];
C_out = [ CL, CR ];
D_out = [ DT
DB ];
return
</textarea>
</div>
</div>
<div id="animation_group" style="display:none">
<div id="control" class="group_header">
Animation
<input type = "button" id="next" value="Next" onClick="ani.next_animation()"/>
<input type = "button" id="reload" value="Reload" onClick="load_program()"/>
<input type = "button" id="new" value="New Program" onClick="close_animation_window();open_input_window()"/>
<input type = "button" id="play" value="Play" onClick="play()"/>
<input type = "button" id="stop" value="Stop" onClick="ani.stop()" disabled="true"/>
</div>
<div id='display_code'></div>
<div id='display_pic'></div>
</div>
</body>
</html>