license import { TensorInfo , util } from '@tensorflow/tfjs-core' ; import { MathBackendWebGL } from '../backend_webgl' ; import { reduce } from '../kernel_utils/reduce' ; import { reshape } from '../kernels/Reshape' ; export function maxImpl ( x , reduceShape , outShape , backend ) { const inSize = util . sizeFromShape ( reduceShape ) ; const xSize = util . sizeFromShape ( x . shape ) ; const batchSize = xSize / inSize ; const reshapedInput = reshape ( { inputs : { x } , attrs : { shape : [ batchSize , inSize ] } , backend } ) ; const reduced = reduce ( reshapedInput , x . dtype , 'max' , backend ) ; const reshapedOutput = reshape ( { inputs : { x : reduced } , attrs : { shape : outShape } , backend } ) ; backend . disposeIntermediateTensorInfo ( reshapedInput ) ; backend . disposeIntermediateTensorInfo ( reduced ) ; return reshapedOutput ; }