license import { EluGrad , EluGradInputs , env , KernelConfig , KernelFunc , TensorInfo } from '@tensorflow/tfjs-core' ; import { MathBackendWebGL } from '../backend_webgl' ; import { BinaryOpProgram } from '../binaryop_gpu' ; import { BinaryOpPackedProgram } from '../binaryop_packed_gpu' ; const ELU_DER = `return (b >= 1.0) ? a : a * (b + 1.0);` ; const ELU_DER_PACKED = `
  vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));
  return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));
` ; export const eluGrad = ( args ) : TensorInfo => { const { inputs , backend } = args ; const { dy , y } = inputs ; const program = env ( ) . getBool ( 'WEBGL_PACK_BINARY_OPERATIONS' ) ? new BinaryOpPackedProgram ( ELU_DER_PACKED , dy . shape , y . shape ) : new BinaryOpProgram ( ELU_DER , dy . shape , y . shape ) ; return backend . runWebGLProgram ( program , [ dy , y ] , dy . dtype ) ; } ; export const eluGradConfig = { kernelName : EluGrad , backendName : 'webgl' , kernelFunc : eluGrad as { } as KernelFunc } ;