license import { env , KernelConfig , KernelFunc , PadV2 , PadV2Attrs , PadV2Inputs , TensorInfo , util } from '@tensorflow/tfjs-core' ; import { MathBackendWebGL } from '../backend_webgl' ; import { PadProgram } from '../pad_gpu' ; import { PadPackedProgram } from '../pad_packed_gpu' ; import { fill } from './Fill' ; export const padV2 = ( args ) : TensorInfo => { const { inputs , backend , attrs } = args ; const { x } = inputs ; const { paddings , constantValue } = attrs ; if ( util . sizeFromShape ( x . shape ) === 0 ) { const outputShape = paddings . map ( ( p , i ) => p [ 0 ] + x . shape [ i ] + p [ 1 ] ) ; return fill ( { backend , attrs : { shape : outputShape , value : constantValue , dtype : x . dtype } } ) ; } const program = env ( ) . getBool ( 'WEBGL_PACK_ARRAY_OPERATIONS' ) ? new PadPackedProgram ( x . shape , paddings , constantValue ) : new PadProgram ( x . shape , paddings , constantValue ) ; const customValues = [ [ constantValue ] ] ; return backend . runWebGLProgram ( program , [ x ] , x . dtype , customValues ) ; } ; export const padV2Config = { kernelName : PadV2 , backendName : 'webgl' , kernelFunc : padV2 as { } as KernelFunc } ;