JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.rawgit.com/gpujs/gpu.js/develop/bin/gpu.js"></script>
JavaScript
function kernelBug() {
let vx = this.thread.x;
let vy = this.thread.y;
let n = norm(vx,vy);
let sum = n[0] + n[1];
return sum;
}
function norm(x,y) {
let l = 1/Math.sqrt(x*x + y*y);
let nx = x*l;
let ny = y*l
return [nx, ny] ; // here is bug - we unable to return vector value.
}
function runBug() {
const gpu = new GPU();
const bug1 = gpu.createKernel(kernelBug)
.setOutput([5, 5])
.setFunctions([norm]);
console.log(bug1());
}
runBug();