license import { KernelConfig , Prelu , PreluInputs , TensorInfo , TypedArray } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { assertNotComplex } from '../cpu_util' ; import { createSimpleBinaryKernelImpl } from '../utils/binary_impl' ; const preluImpl = createSimpleBinaryKernelImpl ( ( xValue , aValue ) => xValue < 0 ? aValue * xValue : xValue ) ; export function prelu ( args ) { const { inputs , backend } = args ; const { x , alpha } = inputs ; assertNotComplex ( [ x , alpha ] , 'prelu' ) ; const aVals = backend . data . get ( x . dataId ) . values as TypedArray ; const bVals = backend . data . get ( alpha . dataId ) . values as TypedArray ; const [ resultData , resultShape ] = preluImpl ( x . shape , alpha . shape , aVals , bVals , 'float32' ) ; return backend . makeTensorInfo ( resultShape , 'float32' , resultData ) ; } export const preluConfig = { kernelName : Prelu , backendName : 'cpu' , kernelFunc : prelu , } ;