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('complex64', ALL_ENVS, () => {
|
21 | it('tf.complex', async () => {
|
22 | const real = tf.tensor1d([3, 30]);
|
23 | const imag = tf.tensor1d([4, 40]);
|
24 | const complex = tf.complex(real, imag);
|
25 | expect(complex.dtype).toBe('complex64');
|
26 | expect(complex.shape).toEqual(real.shape);
|
27 | expectArraysClose(await complex.data(), [3, 4, 30, 40]);
|
28 | });
|
29 | it('tf.real', async () => {
|
30 | const complex = tf.complex([3, 30], [4, 40]);
|
31 | const real = tf.real(complex);
|
32 | expect(real.dtype).toBe('float32');
|
33 | expect(real.shape).toEqual([2]);
|
34 | expectArraysClose(await real.data(), [3, 30]);
|
35 | });
|
36 | it('tf.imag', async () => {
|
37 | const complex = tf.complex([3, 30], [4, 40]);
|
38 | const imag = tf.imag(complex);
|
39 | expect(imag.dtype).toBe('float32');
|
40 | expect(imag.shape).toEqual([2]);
|
41 | expectArraysClose(await imag.data(), [4, 40]);
|
42 | });
|
43 | it('throws when shapes dont match', () => {
|
44 | const real = tf.tensor1d([3, 30]);
|
45 | const imag = tf.tensor1d([4, 40, 50]);
|
46 | const re = /real and imag shapes, 2 and 3, must match in call to tf.complex\(\)/;
|
47 | expect(() => tf.complex(real, imag)).toThrowError(re);
|
48 | });
|
49 | });
|
50 |
|
\ | No newline at end of file |