/** * @param {Map} map */ function convertMapToType(map) { return `{ ${Array.from(map).map(([key, value]) => `${key}: ${value}`).join(', ')} }`; }
function inputX(mode) { const gpu = new GPU({ mode }); const kernel = gpu.createKernel(function(a) { return a[this.thread.x]; }) .setOutput([9]); const a = new Float32Array(9); a.set([1,2,3,4,5,6,7,8,9]); const result = kernel(input(a, [3, 3])); assert.deepEqual(Array.from(result), [1,2,3,4,5,6,7,8,9]); gpu.destroy(); }
function readFromTexture(mode) { const gpu = new GPU({ mode }); const noTexture = makeKernel(gpu); const texture = makeKernel(gpu) .setPipeline(true); const result = noTexture(A); const textureResult = texture(A).toArray(gpu); assert.deepEqual(result.map((v) => Array.from(v)), A); assert.deepEqual(textureResult.map((v) => Array.from(v)), A); assert.deepEqual(textureResult, result); gpu.destroy(); }
function whenEnabledCallsCorrectRenderFunction2D(mode) { const gpu = new GPU({ mode }); const fn = gpu.createKernel(function() { return 1 }, { output: [2, 2], precision: 'single', optimizeFloatMemory: true, }); const result = fn(); assert.equal(fn.TextureConstructor.name, 'GLTextureMemoryOptimized2D'); assert.equal(fn.formatValues, utils.erectMemoryOptimized2DFloat); assert.deepEqual(result.map(row => Array.from(row)), [[1,1],[1,1]]); }
function inputZYX(mode) { const gpu = new GPU({ mode }); const kernel = gpu.createKernel(function(a) { return a[this.thread.z][this.thread.y][this.thread.x]; }) .setOutput([2, 4, 4]); const a = new Float32Array(32); a.set([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]); const result = kernel(input(a, [2, 4, 4])); assert.deepEqual(result.map(function(v) { return v.map(function(v) { return Array.from(v); }); }), [[[1,2],[3,4],[5,6],[7,8]],[[9,10],[11,12],[13,14],[15,16]],[[17,18],[19,20],[21,22],[23,24]],[[25,26],[27,28],[29,30],[31,32]]]); gpu.destroy(); }
function inputYX(mode) { const gpu = new GPU({ mode }); const kernel = gpu.createKernel(function(a) { return a[this.thread.y][this.thread.x]; }) .setOutput([3, 3]); const a = new Float32Array(9); a.set([1,2,3,4,5,6,7,8,9]); const result = kernel(input(a, [3, 3])); assert.deepEqual(result.map(function(v) { return Array.from(v); }), [[1,2,3],[4,5,6],[7,8,9]]); gpu.destroy(); }
Array.from({length: Math.min(total, length)}, (_, sampleIndex) => { let indexRemaining = sampleIndex; const combination = []; for (let i = combinations.length - 1; i >= 0; i--) { const items = combinations[i]; const {length} = items; const index = indexRemaining % length; indexRemaining = (indexRemaining - index) / length; combination.unshift(items[index]); } return combination; })