(
public op: CumOpType, public outputShape: number[], exclusive: boolean,
reverse: boolean)
| 28 | customUniforms = [{name: 'index', type: 'float' as UniformType}]; |
| 29 | |
| 30 | constructor( |
| 31 | public op: CumOpType, public outputShape: number[], exclusive: boolean, |
| 32 | reverse: boolean) { |
| 33 | const rank = this.outputShape.length; |
| 34 | const initVal = this.op === CumOpType.Prod ? '1.0' : '0.0'; |
| 35 | const val = |
| 36 | exclusive ? initVal : `getX(${getCoords(rank, 'coords', this.op)})`; |
| 37 | const length = this.outputShape[this.outputShape.length - 1]; |
| 38 | let condition = ''; |
| 39 | let idxString = ''; |
| 40 | // When exclusive is set, the cum op becomes roll op that copies the |
| 41 | // value from the previous index based on the direction specified by the |
| 42 | // reverse flag. |
| 43 | if (exclusive) { |
| 44 | condition = reverse ? `end != ${length - 1}` : 'end != 0'; |
| 45 | idxString = reverse ? 'end + 1' : 'end - 1'; |
| 46 | } else { |
| 47 | condition = reverse ? `end + pow2 < ${length}` : 'end >= pow2'; |
| 48 | idxString = (reverse ? 'end + pow2' : 'end - pow2'); |
| 49 | } |
| 50 | |
| 51 | this.userCode = ` |
| 52 | void main() { |
| 53 | ${getCoordsDataType(rank)} coords = getOutputCoords(); |
| 54 | int end = ${getFinalCoord(rank, 'coords', this.op)}; |
| 55 | float val = ${val}; |
| 56 | int pow2 = int(pow(2.0, index)); |
| 57 | if (${condition}) { |
| 58 | int idx = ${idxString}; |
| 59 | ${getFinalCoord(rank, 'coords', this.op)} = idx; |
| 60 | val ${this.op}= getX(${getCoords(rank, 'coords', this.op)}); |
| 61 | } |
| 62 | setOutput(val); |
| 63 | } |
| 64 | `; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | function getCoords(rank: number, name: string, op: CumOpType): string { |
nothing calls this directly
no test coverage detected