forked from tensorflow/tfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IFFT.ts
56 lines (45 loc) · 1.81 KB
/
IFFT.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {IFFT, IFFTInputs, KernelConfig, KernelFunc, TensorInfo, util} from '@tensorflow/tfjs-core';
import {MathBackendCPU} from '../backend_cpu';
import {fftBatch} from '../utils/fft_utils';
import {reshape} from './Reshape';
export function ifft(args: {inputs: IFFTInputs, backend: MathBackendCPU}):
TensorInfo {
const {inputs, backend} = args;
const {input} = inputs;
const inputSize = util.sizeFromShape(input.shape);
// Collapse all outer dimensions to a single batch dimension.
const innerDimensionSize = input.shape[input.shape.length - 1];
const batch = inputSize / innerDimensionSize;
const input2D = reshape({
inputs: {x: input},
backend,
attrs: {shape: [batch, innerDimensionSize]}
});
const result = fftBatch(input2D, true, backend);
const resultReshaped =
reshape({inputs: {x: result}, backend, attrs: {shape: input.shape}});
backend.disposeIntermediateTensorInfo(input2D);
backend.disposeIntermediateTensorInfo(result);
return resultReshaped;
}
export const ifftConfig: KernelConfig = {
kernelName: IFFT,
backendName: 'cpu',
kernelFunc: ifft as unknown as KernelFunc
};