license import { ENGINE } from '../engine' ; import { Cast , CastAttrs , CastInputs } from '../kernel_names' ; import { NamedAttrMap } from '../kernel_registry' ; import { Tensor } from '../tensor' ; import { NamedTensorMap } from '../tensor_types' ; import { convertToTensor } from '../tensor_util_env' ; import { DataType , TensorLike } from '../types' ; import * as util from '../util' ; import { op } from './operation' ; param x param dtype doc function cast_ < T extends Tensor > ( x , dtype ) { const $x = convertToTensor ( x , 'x' , 'cast' ) ; if ( ! util . isValidDtype ( dtype ) ) { throw new Error ( `Failed to cast to unknown dtype ${ dtype }` ) ; } if ( dtype === 'string' && $x . dtype !== 'string' || dtype !== 'string' && $x . dtype === 'string' ) { throw new Error ( 'Only strings can be casted to strings' ) ; } const inputs = { x : $x } ; const attrs = { dtype } ; return ENGINE . runKernel ( Cast , inputs as { } as NamedTensorMap , attrs as { } as NamedAttrMap ) ; } export const cast = op ( { cast_ } ) ;