| 25 | packedOutput = true; |
| 26 | |
| 27 | constructor(outputShape: number[], shapes: number[][]) { |
| 28 | this.outputShape = outputShape; |
| 29 | this.variableNames = shapes.map((_, i) => `T${i}`); |
| 30 | |
| 31 | const snippets: string[] = []; |
| 32 | // Get target elements from every input tensor. |
| 33 | this.variableNames.forEach(variable => { |
| 34 | snippets.push(`vec4 v${variable} = get${variable}AtOutCoords();`); |
| 35 | }); |
| 36 | |
| 37 | // Calculate the sum of all elements. |
| 38 | const operation = this.variableNames |
| 39 | .map(variable => { |
| 40 | return `v${variable}`; |
| 41 | }) |
| 42 | .join(' + '); |
| 43 | |
| 44 | this.userCode = ` |
| 45 | void main() { |
| 46 | ${snippets.join('\n ')} |
| 47 | |
| 48 | vec4 result = ${operation}; |
| 49 | setOutput(result); |
| 50 | } |
| 51 | `; |
| 52 | } |
| 53 | } |