JSFiddle - React, Tailwind, and code Playground

by robertleeplummerjr

HTML

<script src="https://unpkg.com/gpu.js@1.10.1/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]);    
            gpu.addFunction(norm, { returnType: 'Array(2)'});  
            console.log(bug1());
        }
        
runBug();