MCPcopy Create free account
hub / github.com/gpujs/gpu.js / mixedArgumentCasting

Function mixedArgumentCasting

test/features/add-custom-native-function.js:176–207  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

174describe('features: mixed argument casting');
175
176function 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
209test('mixedArgumentCasting (GPU only) auto', () => {
210 mixedArgumentCasting(null);

Callers 1

Calls 4

createKernelMethod · 0.95
destroyMethod · 0.95
kernelFunction · 0.85
divideFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…