license import { ENGINE } from '../engine' ; import { Transpose , TransposeAttrs , TransposeInputs } from '../kernel_names' ; import { NamedAttrMap } from '../kernel_registry' ; import { Tensor } from '../tensor' ; import { NamedTensorMap } from '../tensor_types' ; import { convertToTensor } from '../tensor_util_env' ; import { TensorLike } from '../types' ; import * as util from '../util' ; import { op } from './operation' ; param x param perm doc function transpose_ < T extends Tensor > ( x , perm ? ) { const $x = convertToTensor ( x , 'x' , 'transpose' ) ; if ( perm == null ) { perm = $x . shape . map ( ( s , i ) => i ) . reverse ( ) ; } util . assert ( $x . rank === perm . length , ( ) => `Error in transpose: rank of input ${ $x . rank } ` + `must match length of perm ${ perm }.` ) ; perm . forEach ( axis => { util . assert ( axis >= 0 && axis < $x . rank , ( ) => `All entries in 'perm' must be between 0 and ${ $x . rank - 1 }` + ` but got ${ perm }` ) ; } ) ; if ( $x . rank <= 1 ) { return $x . clone ( ) ; } const inputs = { x : $x } ; const attrs = { perm } ; return ENGINE . runKernel ( Transpose , inputs as { } as NamedTensorMap , attrs as { } as NamedAttrMap ) ; } export const transpose = op ( { transpose_ } ) ;