(mode)
| 254 | |
| 255 | describe('features: add custom function with `this.output.x` in loop'); |
| 256 | function sumABThisOutputX(mode) { |
| 257 | const gpu = new GPU({ mode, functions: [customAdder] }); |
| 258 | |
| 259 | function customAdder(a, b) { |
| 260 | let sum = 0; |
| 261 | for (let i = 0; i < this.output.x; i++) { |
| 262 | sum += a[this.thread.x] + b[this.thread.x]; |
| 263 | } |
| 264 | return sum; |
| 265 | } |
| 266 | |
| 267 | const kernel = gpu.createKernel(function(a, b) { |
| 268 | return customAdder(a, b); |
| 269 | }, { |
| 270 | output : [6], |
| 271 | }); |
| 272 | |
| 273 | assert.ok(kernel !== null, 'function generated test'); |
| 274 | |
| 275 | const a = [1, 2, 3, 5, 6, 7]; |
| 276 | const b = [1, 1, 1, 1, 1, 1]; |
| 277 | |
| 278 | const result = kernel(a,b); |
| 279 | const expected = [12, 18, 24, 36, 42, 48]; |
| 280 | |
| 281 | assert.deepEqual(Array.from(result), expected); |
| 282 | gpu.destroy(); |
| 283 | } |
| 284 | |
| 285 | test('sumABThisOutputX auto', () => { |
| 286 | sumABThisOutputX(null); |
no test coverage detected
searching dependent graphs…