(args: {inputs: ComplexAbsInputs, backend: MathBackendCPU})
| 21 | |
| 22 | export const complexAbs = |
| 23 | (args: {inputs: ComplexAbsInputs, backend: MathBackendCPU}) => { |
| 24 | const {x} = args.inputs; |
| 25 | const cpuBackend = args.backend; |
| 26 | const resultValues = new Float32Array(util.sizeFromShape(x.shape)); |
| 27 | const complexVals = cpuBackend.data.get(x.dataId); |
| 28 | const real = complexVals.complexTensorInfos.real; |
| 29 | const imag = complexVals.complexTensorInfos.imag; |
| 30 | const realVals = cpuBackend.data.get(real.dataId).values as Float32Array; |
| 31 | const imagVals = cpuBackend.data.get(imag.dataId).values as Float32Array; |
| 32 | for (let i = 0; i < realVals.length; i++) { |
| 33 | const real = realVals[i]; |
| 34 | const imag = imagVals[i]; |
| 35 | resultValues[i] = Math.hypot(real, imag); |
| 36 | } |
| 37 | |
| 38 | return cpuBackend.makeOutput(resultValues, x.shape, 'float32'); |
| 39 | }; |
| 40 | |
| 41 | export const complexAbsConfig: KernelConfig = { |
| 42 | kernelName: ComplexAbs, |
nothing calls this directly
no test coverage detected
searching dependent graphs…