(args: {
inputs: TransposeInputs,
attrs: TransposeAttrs,
backend: MathBackendCPU
})
| 23 | import {transposeImpl} from './Transpose_impl'; |
| 24 | |
| 25 | export function transpose(args: { |
| 26 | inputs: TransposeInputs, |
| 27 | attrs: TransposeAttrs, |
| 28 | backend: MathBackendCPU |
| 29 | }): TensorInfo { |
| 30 | const {inputs, attrs, backend} = args; |
| 31 | const {x} = inputs; |
| 32 | const {perm} = attrs; |
| 33 | |
| 34 | assertNotComplex(x, 'transpose'); |
| 35 | |
| 36 | const xRank = x.shape.length; |
| 37 | |
| 38 | const newShape: number[] = new Array(xRank); |
| 39 | for (let i = 0; i < newShape.length; i++) { |
| 40 | newShape[i] = x.shape[perm[i]]; |
| 41 | } |
| 42 | |
| 43 | const values = backend.data.get(x.dataId).values as TypedArray; |
| 44 | const result = transposeImpl(values, x.shape, x.dtype, perm, newShape); |
| 45 | |
| 46 | const dataId = backend.write(result, newShape, x.dtype); |
| 47 | return {dataId, shape: newShape, dtype: x.dtype}; |
| 48 | } |
| 49 | |
| 50 | export const transposeConfig: KernelConfig = { |
| 51 | kernelName: Transpose, |
no test coverage detected
searching dependent graphs…