license import { env , KernelConfig , KernelFunc , Prelu , PreluInputs , TensorInfo } from '@tensorflow/tfjs-core' ; import { MathBackendWebGL } from '../backend_webgl' ; import { BinaryOpProgram } from '../binaryop_gpu' ; import { BinaryOpPackedProgram } from '../binaryop_packed_gpu' ; export const PRELU = `return (a < 0.) ? b * a : a;` ; export const PRELU_PACKED = `
  vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
  return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
` ; export function prelu ( args ) { const { inputs , backend } = args ; const { x , alpha } = inputs ; const program = env ( ) . getBool ( 'WEBGL_PACK_BINARY_OPERATIONS' ) ? new BinaryOpPackedProgram ( PRELU_PACKED , x . shape , alpha . shape ) : new BinaryOpProgram ( PRELU , x . shape , alpha . shape ) ; return backend . runWebGLProgram ( program , [ x , alpha ] , 'float32' ) ; } export const preluConfig = { kernelName : Prelu , backendName : 'webgl' , kernelFunc : prelu as { } as KernelFunc } ;