forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdestructured-assignment.js
More file actions
103 lines (81 loc) · 2.34 KB
/
destructured-assignment.js
File metadata and controls
103 lines (81 loc) · 2.34 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
91
92
93
94
95
96
97
98
99
100
101
102
103
const { assert, skip, test, module: describe, only } = require('qunit');
const { GPU } = require('../../src');
describe('features: destructured assignment');
function testObject(mode) {
const gpu = new GPU({ mode });
const kernel = gpu.createKernel(function() {
const { thread: { x, y } } = this;
return x + y;
}, { output: [2, 2] });
assert.deepEqual(kernel(), [new Float32Array([0, 1]), new Float32Array([1, 2])]);
}
test('object auto', () => {
testObject();
});
test('object gpu', () => {
testObject('gpu');
});
(GPU.isWebGLSupported ? test : skip)('object webgl', () => {
testObject('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('object webgl2', () => {
testObject('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('object headlessgl', () => {
testObject('headlessgl');
});
test('object cpu', () => {
testObject('cpu');
});
function testNestedObject(mode) {
const gpu = new GPU({ mode });
const kernel = gpu.createKernel(function() {
const { x, y } = this.thread;
return x + y;
}, { output: [2, 2] });
assert.deepEqual(kernel(), [new Float32Array([0, 1]), new Float32Array([1, 2])]);
}
test('nested object auto', () => {
testNestedObject();
});
test('nested object gpu', () => {
testNestedObject('gpu');
});
(GPU.isWebGLSupported ? test : skip)('nested object webgl', () => {
testNestedObject('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('nested object webgl2', () => {
testNestedObject('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('nested object headlessgl', () => {
testNestedObject('headlessgl');
});
test('nested object cpu', () => {
testNestedObject('cpu');
});
function testArray(mode) {
const gpu = new GPU({ mode });
const kernel = gpu.createKernel(function(array) {
const [first, second] = array;
return first + second;
}, { output: [1], argumentTypes: { array: 'Array(2)' } });
assert.deepEqual(kernel([1, 2]), new Float32Array([3]));
}
test('array auto', () => {
testArray();
});
test('array gpu', () => {
testArray('gpu');
});
(GPU.isWebGLSupported ? test : skip)('array webgl', () => {
testArray('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('array webgl2', () => {
testArray('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('array headlessgl', () => {
testArray('headlessgl');
});
test('array cpu', () => {
testArray('cpu');
});