license import { KernelConfig , Softplus } from '@tensorflow/tfjs-core' ; import { unaryKernelFunc } from '../utils/unary_utils' ; const epsilon = 1.1920928955078125e-7 ; const threshold = Math . log ( epsilon ) + 2.0 ; export const softplus = unaryKernelFunc ( Softplus , ( xi ) => { const tooLarge = xi > - threshold ; const tooSmall = xi < threshold ; const expX = Math . exp ( xi ) ; let result ; if ( tooSmall ) { result = expX ; } else if ( tooLarge ) { result = xi ; } else { result = Math . log ( 1.0 + expX ) ; } return result ; } ) ; export const softplusConfig = { kernelName : Softplus , backendName : 'cpu' , kernelFunc : softplus , } ;