license import { MaxPoolWithArgmax , MaxPoolWithArgmaxAttrs , MaxPoolWithArgmaxInputs } from '@tensorflow/tfjs-core' ; import { backend_util , KernelConfig , TypedArray } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { assertNotComplex } from '../cpu_util' ; import { maxPoolWithArgmaxImpl } from './MaxPoolWithArgmax_impl' ; export const maxPoolWithArgmaxConfig = { kernelName : MaxPoolWithArgmax , backendName : 'cpu' , kernelFunc : ( { inputs , attrs , backend } ) => { const { x } = inputs as MaxPoolWithArgmaxInputs ; const { filterSize , strides , pad , includeBatchInIndex } = attrs as { } as MaxPoolWithArgmaxAttrs ; const cpuBackend = backend as MathBackendCPU ; assertNotComplex ( x , 'MaxPoolWithArgmax' ) ; const values = cpuBackend . data . get ( x . dataId ) . values as TypedArray ; const convInfo = backend_util . computePool2DInfo ( x . shape as [ number , number , number , number ] , filterSize , strides , [ 1 , 1 ] , pad ) ; const [ pooled , indexes ] = maxPoolWithArgmaxImpl ( values , x . shape , x . dtype , includeBatchInIndex , convInfo ) ; const pooledDataId = cpuBackend . write ( pooled as Float32Array , convInfo . outShape , x . dtype ) ; const indexesDataId = cpuBackend . write ( indexes as Int32Array , convInfo . outShape , x . dtype ) ; return [ { dataId : pooledDataId , shape : convInfo . outShape , dtype : x . dtype } , { dataId : indexesDataId , shape : convInfo . outShape , dtype : 'int32' } ] ; } } ;