-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
65 lines (49 loc) · 1.2 KB
/
example.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
<!doctype html>
<html>
<head>
</head>
<body>
<textarea id="result" rows="3" cols="50"></textarea>
<script src="gpu.rocks/gpu-browser.js"></script>
<script src="gpu-ez.js"></script>
<script>
async function glsl(file) {
const res = await fetch(`glsl/${file}`);
const content = await res.text();
return GpuEz.glsl(content);
}
async function main() {
const [invInit, invRow, invResult] = await Promise.all([
glsl('inv-matrix-init.c'),
glsl('inv-matrix-row.c'),
glsl('inv-matrix-result.c')
]);
function invMatrix(matrix) {
const size = matrix.length;
let invStep = invInit(matrix, size);
for (let i = 0; i < size; i++) {
const norm = invRow(invStep, size, i);
invStep.delete();
invStep = norm;
}
const result = invResult.arrayOut(invStep, size);
invStep.delete();
return result;
}
const matrix = [
[1, 2],
[3, 4]
];
const inv = invMatrix(matrix);
const pretty = inv.map((row) => (
row.map((cell) => (
cell.toFixed(2)
)).join(' \t ')
)).join('\n');
document.querySelector('#result').value = pretty;
}
window.onload = main;
window.onbeforeunload = GpuEz.gpuFree;
</script>
</body>
</html>