license import { Complex , ComplexInputs , KernelConfig , KernelFunc , TensorInfo } from '@tensorflow/tfjs-core' ; import { MathBackendWebGL } from '../backend_webgl' ; import { identity } from './Identity' ; /**
 * In WebGL data is stored in GPU textures which can't be efficiently copied, so
 * complex tensors share data with their real and imaginary components. Complex
 * tensors' reference to the components is tracked by refCount on the individual
 * component. The refCounts are increased by the identity call.
 *
 * When a complex tensor is disposed, it will reduce the refCount on the
 * components by calling disposeData on each.
 */ export function complex ( args ) { const { inputs , backend } = args ; const { real , imag } = inputs ; const complexInfo = backend . makeTensorInfo ( real . shape , 'complex64' ) ; const complex = backend . texData . get ( complexInfo . dataId ) ; const realTensorInfo = identity ( { inputs : { x : real } , backend } ) ; const imagTensorInfo = identity ( { inputs : { x : imag } , backend } ) ; complex . complexTensorInfos = { real : realTensorInfo , imag : imagTensorInfo } ; return complexInfo ; } export const complexConfig = { kernelName : Complex , backendName : 'webgl' , kernelFunc : complex as { } as KernelFunc } ;