license import { KernelConfig , KernelFunc , NumericDataType , TensorInfo , TopK , TopKAttrs , TopKInputs , TypedArray } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { assertNotComplex } from '../cpu_util' ; import { topKImpl } from './TopK_impl' ; export function topK ( args ) { const { inputs , backend , attrs } = args ; const { x } = inputs ; const { k , sorted } = attrs ; assertNotComplex ( x , 'topk' ) ; const xVals = backend . data . get ( x . dataId ) . values as TypedArray ; const [ allTopKVals , allTopKIndices ] = topKImpl ( xVals , x . shape , x . dtype as NumericDataType , k , sorted ) ; return [ backend . makeTensorInfo ( allTopKVals . shape , allTopKVals . dtype , allTopKVals . values ) , backend . makeTensorInfo ( allTopKIndices . shape , allTopKIndices . dtype , allTopKIndices . values ) ] ; } export const topKConfig = { kernelName : TopK , backendName : 'cpu' , kernelFunc : topK as { } as KernelFunc } ;