license import { GPGPUProgram } from './gpgpu_math' ; export class AddNProgram implements GPGPUProgram { variableNames : string [ ] ; outputShape : number [ ] = [ ] ; userCode : string ; constructor ( outputShape , shapes ) { this . outputShape = outputShape ; this . variableNames = shapes . map ( ( _ , i ) => `T${ i }` ) ; const snippets = [ ] ; this . variableNames . forEach ( variable => { snippets . push ( `float v${ variable } = get${ variable }AtOutCoords();` ) ; } ) ; const operation = this . variableNames . map ( variable => { return `v${ variable }` ; } ) . join ( ' + ' ) ; this . userCode = `
      void main() {
        ${ snippets . join ( '\n        ' ) }

        float result = ${ operation };
        setOutput(result);
      }
    ` ; } }