(xShape: number[], axis: number[])
| 24 | userCode: string; |
| 25 | |
| 26 | constructor(xShape: number[], axis: number[]) { |
| 27 | const rank = xShape.length; |
| 28 | if (rank > 4) { |
| 29 | throw new Error( |
| 30 | `WebGL backend: Reverse of rank-${rank} tensor is not yet supported`); |
| 31 | } |
| 32 | this.outputShape = xShape; |
| 33 | |
| 34 | if (rank === 1) { |
| 35 | this.userCode = ` |
| 36 | void main() { |
| 37 | int coord = getOutputCoords(); |
| 38 | setOutput(getX(${xShape[0]} - coord - 1)); |
| 39 | } |
| 40 | `; |
| 41 | return; |
| 42 | } |
| 43 | const getInCoord = (i: number) => { |
| 44 | if (axis.indexOf(i) !== -1 && xShape[i] !== 1) { |
| 45 | return `${xShape[i]} - coords[${i}] - 1`; |
| 46 | } |
| 47 | return `coords[${i}]`; |
| 48 | }; |
| 49 | const inCoords = xShape.map((_, i) => getInCoord(i)).join(','); |
| 50 | const type = getCoordsDataType(rank); |
| 51 | |
| 52 | this.userCode = ` |
| 53 | void main() { |
| 54 | ${type} coords = getOutputCoords(); |
| 55 | setOutput(getX(${inCoords})); |
| 56 | } |
| 57 | `; |
| 58 | } |
| 59 | } |
nothing calls this directly
no test coverage detected