license import { backend_util , KernelConfig , KernelFunc , SparseToDense , SparseToDenseAttrs , SparseToDenseInputs , TensorInfo } from '@tensorflow/tfjs-core' ; import { MathBackendWebGL } from '../backend_webgl' ; import { ScatterProgram } from '../scatter_gpu' ; import { reshape } from './Reshape' ; export function sparseToDense ( args ) { const { inputs , backend , attrs } = args ; const { sparseIndices , sparseValues , defaultValue } = inputs ; const { outputShape } = attrs ; const { sliceRank , numUpdates , strides , outputSize } = backend_util . calculateShapes ( sparseValues , sparseIndices , outputShape ) ; const sumDupeIndices = false ; const program = new ScatterProgram ( numUpdates , sliceRank , sparseIndices . shape . length , sparseValues . shape . length , strides , [ outputSize , 1 ] , sumDupeIndices ) ; const res = backend . runWebGLProgram ( program , [ sparseValues , sparseIndices , defaultValue ] , sparseValues . dtype ) ; const reshaped = reshape ( { inputs : { x : res } , backend , attrs : { shape : outputShape } } ) ; backend . disposeIntermediateTensorInfo ( res ) ; return reshaped ; } export const sparseToDenseConfig = { kernelName : SparseToDense , backendName : 'webgl' , kernelFunc : sparseToDense as { } as KernelFunc } ;