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, expectArraysEqual } from '../test_util';
|
20 | describeWithFlags('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 |
|
\ | No newline at end of file |