()
| 51 | } |
| 52 | |
| 53 | getUserCode(): string { |
| 54 | const rank = this.outputShape.length; |
| 55 | const initVal = this.op === CumOpType.Prod ? '1.0' : '0.0'; |
| 56 | const val = this.exclusive ? initVal : |
| 57 | `getX(${getCoords(rank, 'coords', this.op)})`; |
| 58 | const length = this.outputShape[this.outputShape.length - 1]; |
| 59 | let condition = ''; |
| 60 | let idxString = ''; |
| 61 | // When exclusive is set, the cum op becomes roll op that copies the |
| 62 | // value from the previous index based on the direction specified by the |
| 63 | // reverse flag. |
| 64 | if (this.exclusive) { |
| 65 | condition = this.reverse ? `end != ${length - 1}` : 'end != 0'; |
| 66 | idxString = this.reverse ? 'end + 1' : 'end - 1'; |
| 67 | } else { |
| 68 | condition = this.reverse ? `end + pow2 < ${length}` : 'end >= pow2'; |
| 69 | idxString = (this.reverse ? 'end + pow2' : 'end - pow2'); |
| 70 | } |
| 71 | return ` |
| 72 | ${main('index')} { |
| 73 | if (index < uniforms.size) { |
| 74 | var coords = getCoordsFromIndex(index); |
| 75 | |
| 76 | let end = ${getFinalCoord(rank, 'coords', this.op)}; |
| 77 | var val = ${val}; |
| 78 | let pow2 = i32(pow(2.0, uniforms.index)); |
| 79 | if (${condition}) { |
| 80 | let idx = ${idxString}; |
| 81 | ${getFinalCoord(rank, 'coords', this.op)} = idx; |
| 82 | val ${this.op}= getX(${getCoords(rank, 'coords', this.op)}); |
| 83 | } |
| 84 | setOutputAtIndex(index, val); |
| 85 | } |
| 86 | } |
| 87 | `; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | function getCoords(rank: number, name: string, op: CumOpType): string { |
no test coverage detected