| 50 | } |
| 51 | |
| 52 | getUserCode(): string { |
| 53 | const userCode = ` |
| 54 | ${main('index')} { |
| 55 | if (index < uniforms.size) { |
| 56 | let coords = getOutputCoords(); |
| 57 | let b = coords[0]; |
| 58 | let r = coords[1]; |
| 59 | let c = coords[2]; |
| 60 | let d = coords[3]; |
| 61 | |
| 62 | let x = getX(b, r, c, d); |
| 63 | var sum = 0.0; |
| 64 | for (var i = -uniforms.radius; i <= uniforms.radius; i = i + 1) { |
| 65 | let idx = d + i; |
| 66 | if (idx >= 0 && idx < uniforms.xShape[3]) { |
| 67 | let z = getX(b, r, c, idx); |
| 68 | sum = sum + z * z; |
| 69 | } |
| 70 | } |
| 71 | ${powOperatorSnippet} |
| 72 | |
| 73 | setOutputAtIndex(index, x * powValue); |
| 74 | } |
| 75 | } |
| 76 | `; |
| 77 | return userCode; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | export class LRNSharedProgram implements WebGPUProgram { |