license import { AddN , AddNInputs , buffer , KernelConfig , KernelFunc , Tensor , TensorInfo , TypedArray } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { assertNotComplex } from '../cpu_util' ; export function addN ( args ) { const { inputs , backend } = args ; const tensors = inputs as Tensor [ ] ; assertNotComplex ( inputs , 'addN' ) ; const vals = tensors . map ( t => backend . data . get ( t . dataId ) . values as TypedArray ) ; const outBuf = buffer ( tensors [ 0 ] . shape , tensors [ 0 ] . dtype as 'float32' ) ; const outVals = outBuf . values ; for ( let i = 0 ; i < tensors . length ; i ++ ) { const currVals = vals [ i ] ; for ( let j = 0 ; j < outVals . length ; j ++ ) { outVals [ j ] += currVals [ j ] ; } } return backend . makeTensorInfo ( outBuf . shape , outBuf . dtype , outBuf . values ) ; } export const addNConfig = { kernelName : AddN , backendName : 'cpu' , kernelFunc : addN as { } as KernelFunc } ;