(
input: TensorInfo, inverse: boolean,
cpuBackend: MathBackendCPU)
| 95 | } |
| 96 | |
| 97 | export function fftImpl( |
| 98 | input: TensorInfo, inverse: boolean, |
| 99 | cpuBackend: MathBackendCPU): {real: Float32Array, imag: Float32Array} { |
| 100 | const inputSize = util.sizeFromShape(input.shape); |
| 101 | |
| 102 | const inputVals = cpuBackend.data.get(input.dataId); |
| 103 | |
| 104 | const realVals = |
| 105 | cpuBackend.data.get(inputVals.complexTensorInfos.real.dataId).values as |
| 106 | Float32Array; |
| 107 | |
| 108 | const imagVals = |
| 109 | cpuBackend.data.get(inputVals.complexTensorInfos.imag.dataId).values as |
| 110 | Float32Array; |
| 111 | |
| 112 | if (isExponentOf2(inputSize)) { |
| 113 | const result = |
| 114 | fftRadix2(realVals, imagVals, inputSize, inverse, cpuBackend); |
| 115 | |
| 116 | const resultShape = [input.shape[0], input.shape[1]]; |
| 117 | |
| 118 | if (inverse) { |
| 119 | const realInfo: TensorInfo = |
| 120 | cpuBackend.makeTensorInfo(resultShape, 'float32', result.real); |
| 121 | const imagInfo: TensorInfo = |
| 122 | cpuBackend.makeTensorInfo(resultShape, 'float32', result.imag); |
| 123 | |
| 124 | const sizeInfo: TensorInfo = cpuBackend.makeTensorInfo( |
| 125 | [], 'float32', |
| 126 | util.createScalarValue(inputSize as unknown as 'float32', 'float32')); |
| 127 | const sizeInfoCopy = |
| 128 | identity({inputs: {x: sizeInfo}, backend: cpuBackend}); |
| 129 | |
| 130 | const divRealInfo = |
| 131 | realDivConfig.kernelFunc( |
| 132 | {inputs: {a: realInfo, b: sizeInfo}, backend: cpuBackend}) as |
| 133 | TensorInfo; |
| 134 | const divImagInfo = |
| 135 | realDivConfig.kernelFunc( |
| 136 | {inputs: {a: imagInfo, b: sizeInfoCopy}, backend: cpuBackend}) as |
| 137 | TensorInfo; |
| 138 | |
| 139 | const divRealVals = |
| 140 | cpuBackend.data.get(divRealInfo.dataId).values as Float32Array; |
| 141 | const divImagVals = |
| 142 | cpuBackend.data.get(divImagInfo.dataId).values as Float32Array; |
| 143 | |
| 144 | cpuBackend.disposeIntermediateTensorInfo(realInfo); |
| 145 | cpuBackend.disposeIntermediateTensorInfo(imagInfo); |
| 146 | cpuBackend.disposeIntermediateTensorInfo(sizeInfo); |
| 147 | cpuBackend.disposeIntermediateTensorInfo(sizeInfoCopy); |
| 148 | cpuBackend.disposeIntermediateTensorInfo(divRealInfo); |
| 149 | cpuBackend.disposeIntermediateTensorInfo(divImagInfo); |
| 150 | |
| 151 | return {real: divRealVals, imag: divImagVals}; |
| 152 | } |
| 153 | |
| 154 | return result; |
no test coverage detected
searching dependent graphs…