license import { KernelConfig , KernelFunc , LeakyRelu , LeakyReluAttrs , LeakyReluInputs , TensorInfo , TypedArray , util } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { assertNotComplex } from '../cpu_util' ; export function leakyRelu ( args ) { const { inputs , backend , attrs } = args ; const { x } = inputs ; const { alpha } = attrs ; assertNotComplex ( [ x ] , 'leakyRelu' ) ; const xSize = util . sizeFromShape ( x . shape ) ; const xVals = backend . data . get ( x . dataId ) . values as TypedArray ; const outVals = util . getTypedArrayFromDType ( 'float32' , xSize ) ; for ( let i = 0 ; i < xVals . length ; i ++ ) { outVals [ i ] = xVals [ i ] < 0 ? alpha * xVals [ i ] : xVals [ i ] ; } return backend . makeTensorInfo ( x . shape , 'float32' , outVals ) ; } export const leakyReluConfig = { kernelName : LeakyRelu , backendName : 'cpu' , kernelFunc : leakyRelu as { } as KernelFunc } ;