1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import * as tf from '../index';
|
18 | import { ALL_ENVS, describeWithFlags } from '../jasmine_util';
|
19 | import { expectArraysClose } from '../test_util';
|
20 | describeWithFlags('1D IFFT', ALL_ENVS, () => {
|
21 | it('should return the same value with TensorFlow (2 elements)', async () => {
|
22 | const t1Real = tf.tensor1d([1, 2]);
|
23 | const t1Imag = tf.tensor1d([1, 1]);
|
24 | const t1 = tf.complex(t1Real, t1Imag);
|
25 | expectArraysClose(await tf.spectral.ifft(t1).data(), [1.5, 1, -0.5, 0]);
|
26 | });
|
27 | it('should calculate FFT from Tensor directly', async () => {
|
28 | const t1Real = tf.tensor1d([1, 2]);
|
29 | const t1Imag = tf.tensor1d([1, 1]);
|
30 | const t1 = tf.complex(t1Real, t1Imag);
|
31 | expectArraysClose(await t1.ifft().data(), [1.5, 1, -0.5, 0]);
|
32 | });
|
33 | it('should return the same value as TensorFlow (3 elements)', async () => {
|
34 | const t1Real = tf.tensor1d([1, 2, 3]);
|
35 | const t1Imag = tf.tensor1d([0, 0, 0]);
|
36 | const t1 = tf.complex(t1Real, t1Imag);
|
37 | expectArraysClose(await tf.spectral.ifft(t1).data(), [
|
38 | 2, -3.9736431e-08, -0.49999997, -.28867507, -0.49999994, 2.8867519e-01
|
39 | ]);
|
40 | });
|
41 | it('should return the same value as TensorFlow with imaginary (3 elements)', async () => {
|
42 | const t1Real = tf.tensor1d([1, 2, 3]);
|
43 | const t1Imag = tf.tensor1d([1, 2, 3]);
|
44 | const t1 = tf.complex(t1Real, t1Imag);
|
45 | expectArraysClose(await tf.spectral.ifft(t1).data(), [2, 1.9999999, -0.21132492, -0.78867507, -0.7886752, -0.2113249]);
|
46 | });
|
47 | it('should return the same value as TensorFlow (negative 3 elements)', async () => {
|
48 | const t1Real = tf.tensor1d([-1, -2, -3]);
|
49 | const t1Imag = tf.tensor1d([-1, -2, -3]);
|
50 | const t1 = tf.complex(t1Real, t1Imag);
|
51 | expectArraysClose(await tf.spectral.ifft(t1).data(), [-2, -1.9999999, 0.21132492, 0.78867507, 0.7886752, 0.2113249]);
|
52 | });
|
53 | it('should return the same value with TensorFlow (4 elements)', async () => {
|
54 | const t1Real = tf.tensor1d([1, 2, 3, 4]);
|
55 | const t1Imag = tf.tensor1d([0, 0, 0, 0]);
|
56 | const t1 = tf.complex(t1Real, t1Imag);
|
57 | expectArraysClose(await tf.spectral.ifft(t1).data(), [2.5, 0, -0.5, -0.5, -0.5, 0, -0.5, 0.5]);
|
58 | });
|
59 | it('should return the same value as TensorFlow with imaginary (4 elements)', async () => {
|
60 | const t1Real = tf.tensor1d([1, 2, 3, 4]);
|
61 | const t1Imag = tf.tensor1d([1, 2, 3, 4]);
|
62 | const t1 = tf.complex(t1Real, t1Imag);
|
63 | expectArraysClose(await tf.spectral.ifft(t1).data(), [2.5, 2.5, 0, -1, -0.5, -0.5, -1, 0]);
|
64 | });
|
65 | });
|
66 | describeWithFlags('2D IFFT', ALL_ENVS, () => {
|
67 | it('2D: should return the same value as TensorFlow', async () => {
|
68 | const t1Real = tf.tensor2d([1, 2, 3, 4], [2, 2]);
|
69 | const t1Imag = tf.tensor2d([5, 6, 7, 8], [2, 2]);
|
70 | const t1 = tf.complex(t1Real, t1Imag);
|
71 | const y = tf.spectral.ifft(t1);
|
72 | expectArraysClose(await y.data(), [1.5, 5.5, -0.5, -0.5, 3.5, 7.5, -0.5, -0.5]);
|
73 | expect(y.shape).toEqual(t1Real.shape);
|
74 | });
|
75 | it('3D: should return the same value as TensorFlow', async () => {
|
76 | const t1Real = tf.tensor3d([1, 2, 3, 4, -1, -2, -3, -4], [2, 2, 2]);
|
77 | const t1Imag = tf.tensor3d([5, 6, 7, 8, -5, -6, -7, -8], [2, 2, 2]);
|
78 | const t1 = tf.complex(t1Real, t1Imag);
|
79 | const y = tf.spectral.ifft(t1);
|
80 | expectArraysClose(await y.data(), [
|
81 | 1.5, 5.5, -0.5, -0.5, 3.5, 7.5, -0.5, -0.5, -1.5, -5.5, 0.5, 0.5, -3.5,
|
82 | -7.5, 0.5, 0.5
|
83 | ]);
|
84 | expect(y.shape).toEqual(t1Real.shape);
|
85 | });
|
86 | });
|
87 |
|
\ | No newline at end of file |