MCPcopy Index your code
hub / github.com/gpujs/gpu.js / nativeDivide

Function nativeDivide

test/features/add-custom-native-function.js:13–36  ·  view source on GitHub ↗
(mode, fn)

Source from the content-addressed store, hash-verified

11}`;
12
13function nativeDivide(mode, fn) {
14 const gpu = new GPU({ mode });
15
16 gpu.addNativeFunction('divide', fn, { returnType: 'Number' });
17
18 const f = gpu.createKernel(function(a, b) {
19 return divide(a[this.thread.x], b[this.thread.x]);
20 }, {
21 output : [6]
22 });
23
24 assert.ok(f !== null, 'function generated test');
25
26 const a = [1, 4, 3, 5, 6, 3];
27 const b = [4, 2, 6, 1, 2, 3];
28
29 const res = f(a,b);
30 const exp = [0.25, 2, 0.5, 5, 3, 1];
31
32 for(let i = 0; i < exp.length; ++i) {
33 assert.equal(res[i], exp[i], 'Result arr idx: '+i);
34 }
35 gpu.destroy();
36}
37
38test('nativeDivide auto', () => {
39 nativeDivide(null, glslDivide);

Callers 1

Calls 4

addNativeFunctionMethod · 0.95
createKernelMethod · 0.95
destroyMethod · 0.95
divideFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…