(
xVals: TypedArray, xShape: number[], dtype: DataType, perm: number[],
newShape: number[])
| 19 | import {util} from '@tensorflow/tfjs-core'; |
| 20 | |
| 21 | export function transposeImpl( |
| 22 | xVals: TypedArray, xShape: number[], dtype: DataType, perm: number[], |
| 23 | newShape: number[]): TypedArray { |
| 24 | const xRank = xShape.length; |
| 25 | const xSize = util.sizeFromShape(xShape); |
| 26 | const xStrides = util.computeStrides(xShape); |
| 27 | const newStrides = util.computeStrides(newShape); |
| 28 | |
| 29 | const result = util.getTypedArrayFromDType( |
| 30 | dtype as NumericDataType, util.sizeFromShape(newShape)); |
| 31 | |
| 32 | for (let i = 0; i < xSize; ++i) { |
| 33 | const loc = util.indexToLoc(i, xRank, xStrides); |
| 34 | |
| 35 | // Permute location. |
| 36 | const newLoc: number[] = new Array(loc.length); |
| 37 | for (let i = 0; i < newLoc.length; i++) { |
| 38 | newLoc[i] = loc[perm[i]]; |
| 39 | } |
| 40 | |
| 41 | const newIndex = util.locToIndex(newLoc, xRank, newStrides); |
| 42 | result[newIndex] = xVals[i]; |
| 43 | } |
| 44 | return result; |
| 45 | } |
no test coverage detected
searching dependent graphs…