UNPKG

2.13 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17import * as tf from '../index';
18import { ALL_ENVS, describeWithFlags } from '../jasmine_util';
19import { expectArraysClose } from '../test_util';
20describeWithFlags('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//# sourceMappingURL=complex_ops_test.js.map
\No newline at end of file