(mode, fn)
| 11 | }`; |
| 12 | |
| 13 | function 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 | |
| 38 | test('nativeDivide auto', () => { |
| 39 | nativeDivide(null, glslDivide); |
no test coverage detected
searching dependent graphs…