(mode)
| 174 | describe('features: mixed argument casting'); |
| 175 | |
| 176 | function mixedArgumentCasting(mode) { |
| 177 | const gpu = new GPU({ |
| 178 | mode, |
| 179 | functions: [divide], |
| 180 | nativeFunctions: [{ |
| 181 | // deliberately add, rather than divide, to ensure native functions are treated as more important than regular ones |
| 182 | name: 'divide', |
| 183 | source: `float divide(int a, float b) { |
| 184 | return float(a + int(b)); |
| 185 | }` |
| 186 | }] |
| 187 | }); |
| 188 | |
| 189 | function divide(a,b) { |
| 190 | return a / b; |
| 191 | } |
| 192 | |
| 193 | const kernel = gpu.createKernel(function(a, b) { |
| 194 | return divide(a[this.thread.x], b[this.thread.x]); |
| 195 | }, { |
| 196 | output : [6] |
| 197 | }); |
| 198 | |
| 199 | const a = [1, 4, 3, 5, 6, 3]; |
| 200 | const b = [4, 2, 6, 1, 2, 3]; |
| 201 | |
| 202 | const res = kernel(a,b); |
| 203 | const exp = [5, 6, 9, 6, 8, 6]; |
| 204 | |
| 205 | assert.deepEqual(Array.from(res), exp); |
| 206 | gpu.destroy(); |
| 207 | } |
| 208 | |
| 209 | test('mixedArgumentCasting (GPU only) auto', () => { |
| 210 | mixedArgumentCasting(null); |
no test coverage detected
searching dependent graphs…