forked from fingerecho/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathif-else.js
More file actions
80 lines (66 loc) · 1.64 KB
/
if-else.js
File metadata and controls
80 lines (66 loc) · 1.64 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
(function() {
function booleanBranch(mode) {
var gpu = new GPU({
mode: mode
});
var f = gpu.createKernel(function() {
var result = 0.0;
if(true) {
result = 4.0;
} else {
result = 2.0;
}
return result;
}, {
output : [1]
});
QUnit.assert.ok( f !== null, 'function generated test');
QUnit.assert.close(f()[0], 4, 0.01, 'basic return function test');
gpu.destroy();
}
QUnit.test( 'booleanBranch (auto)', function() {
booleanBranch(null);
});
QUnit.test( 'booleanBranch (gpu)', function() {
booleanBranch('gpu');
});
QUnit.test( 'booleanBranch (webgl)', function() {
booleanBranch('webgl');
});
QUnit.test( 'booleanBranch (webgl2)', function() {
booleanBranch('webgl2');
});
QUnit.test( 'booleanBranch (CPU)', function() {
booleanBranch('cpu');
});
function ifElse( mode ) {
var gpu = new GPU({ mode });
var f = gpu.createKernel(function(x) {
if (x[this.thread.x] > 0) {
return 0;
} else {
return 1;
}
}, {
output : [4]
});
QUnit.assert.ok( f !== null, 'function generated test');
QUnit.assert.deepEqual(QUnit.extend([], f([1, 1, 0, 0])), [0, 0, 1, 1], 'basic return function test');
gpu.destroy();
}
QUnit.test( 'ifElse (auto)', function() {
ifElse(null);
});
QUnit.test( 'ifElse (gpu)', function() {
ifElse('gpu');
});
QUnit.test( 'ifElse (webgl)', function() {
ifElse('webgl');
});
QUnit.test( 'ifElse (webgl2)', function() {
ifElse('webgl2');
});
QUnit.test( 'ifElse (cpu)', function() {
ifElse('cpu');
});
})();