UNPKG

2.47 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2020 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, expectArraysEqual } from '../test_util';
20describeWithFlags('linspace', ALL_ENVS, () => {
21 it('start stop', async () => {
22 const a = tf.linspace(1, 10, 10);
23 expectArraysEqual(await a.data(), [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]);
24 expect(a.shape).toEqual([10]);
25 const b = tf.linspace(12, 17, 8);
26 expectArraysClose(await b.data(), [
27 12., 12.71428571, 13.42857143, 14.14285714, 14.85714286, 15.57142857,
28 16.28571429, 17.
29 ]);
30 expect(b.shape).toEqual([8]);
31 const c = tf.linspace(9, 0, 6);
32 expectArraysClose(await c.data(), [9., 7.2, 5.4, 3.6, 1.8, 0.]);
33 expect(c.shape).toEqual([6]);
34 });
35 it('negative start stop', async () => {
36 const a = tf.linspace(-4, 5, 6);
37 expectArraysClose(await a.data(), [-4., -2.2, -0.4, 1.4, 3.2, 5.]);
38 expect(a.shape).toEqual([6]);
39 });
40 it('start negative stop', async () => {
41 const a = tf.linspace(4, -5, 6);
42 expectArraysClose(await a.data(), [4., 2.2, 0.4, -1.4, -3.2, -5.]);
43 expect(a.shape).toEqual([6]);
44 });
45 it('negative start negative stop', async () => {
46 const a = tf.linspace(-4, -5, 6);
47 expectArraysClose(await a.data(), [-4., -4.2, -4.4, -4.6, -4.8, -5.]);
48 expect(a.shape).toEqual([6]);
49 const b = tf.linspace(-9, -4, 5);
50 expectArraysClose(await b.data(), [-9., -7.75, -6.5, -5.25, -4.]);
51 expect(b.shape).toEqual([5]);
52 });
53 it('should throw with no samples', () => {
54 expect(() => tf.linspace(2, 10, 0)).toThrow();
55 });
56});
57//# sourceMappingURL=linspace_test.js.map
\No newline at end of file