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 { expectValuesInRange } from '../test_util';
|
20 | describeWithFlags('randomUniform', ALL_ENVS, () => {
|
21 | it('should return a random 1D float32 array', async () => {
|
22 | const shape = [10];
|
23 |
|
24 | let result = tf.randomUniform(shape, 0, 2.5);
|
25 | expect(result.dtype).toBe('float32');
|
26 | expectValuesInRange(await result.data(), 0, 2.5);
|
27 | result = tf.randomUniform(shape, 0, 1.5, 'float32');
|
28 | expect(result.dtype).toBe('float32');
|
29 | expectValuesInRange(await result.data(), 0, 1.5);
|
30 | });
|
31 | it('should return a random 1D int32 array', async () => {
|
32 | const shape = [10];
|
33 | const result = tf.randomUniform(shape, 0, 2, 'int32');
|
34 | expect(result.dtype).toBe('int32');
|
35 | expectValuesInRange(await result.data(), 0, 2);
|
36 | });
|
37 | it('should return a random 1D bool array', async () => {
|
38 | const shape = [10];
|
39 | const result = tf.randomUniform(shape, 0, 1, 'bool');
|
40 | expect(result.dtype).toBe('bool');
|
41 | expectValuesInRange(await result.data(), 0, 1);
|
42 | });
|
43 | it('should return a random 2D float32 array', async () => {
|
44 | const shape = [3, 4];
|
45 |
|
46 | let result = tf.randomUniform(shape, 0, 2.5);
|
47 | expect(result.dtype).toBe('float32');
|
48 | expectValuesInRange(await result.data(), 0, 2.5);
|
49 | result = tf.randomUniform(shape, 0, 1.5, 'float32');
|
50 | expect(result.dtype).toBe('float32');
|
51 | expectValuesInRange(await result.data(), 0, 1.5);
|
52 | });
|
53 | it('should return a random 2D int32 array', async () => {
|
54 | const shape = [3, 4];
|
55 | const result = tf.randomUniform(shape, 0, 2, 'int32');
|
56 | expect(result.dtype).toBe('int32');
|
57 | expectValuesInRange(await result.data(), 0, 2);
|
58 | });
|
59 | it('should return a random 2D bool array', async () => {
|
60 | const shape = [3, 4];
|
61 | const result = tf.randomUniform(shape, 0, 1, 'bool');
|
62 | expect(result.dtype).toBe('bool');
|
63 | expectValuesInRange(await result.data(), 0, 1);
|
64 | });
|
65 | it('should return a random 3D float32 array', async () => {
|
66 | const shape = [3, 4, 5];
|
67 |
|
68 | let result = tf.randomUniform(shape, 0, 2.5);
|
69 | expect(result.dtype).toBe('float32');
|
70 | expectValuesInRange(await result.data(), 0, 2.5);
|
71 | result = tf.randomUniform(shape, 0, 1.5, 'float32');
|
72 | expect(result.dtype).toBe('float32');
|
73 | expectValuesInRange(await result.data(), 0, 1.5);
|
74 | });
|
75 | it('should return a random 3D int32 array', async () => {
|
76 | const shape = [3, 4, 5];
|
77 | const result = tf.randomUniform(shape, 0, 2, 'int32');
|
78 | expect(result.dtype).toBe('int32');
|
79 | expectValuesInRange(await result.data(), 0, 2);
|
80 | });
|
81 | it('should return a random 3D bool array', async () => {
|
82 | const shape = [3, 4, 5];
|
83 | const result = tf.randomUniform(shape, 0, 1, 'bool');
|
84 | expect(result.dtype).toBe('bool');
|
85 | expectValuesInRange(await result.data(), 0, 1);
|
86 | });
|
87 | it('should return a random 4D float32 array', async () => {
|
88 | const shape = [3, 4, 5, 6];
|
89 |
|
90 | let result = tf.randomUniform(shape, 0, 2.5);
|
91 | expect(result.dtype).toBe('float32');
|
92 | expectValuesInRange(await result.data(), 0, 2.5);
|
93 | result = tf.randomUniform(shape, 0, 1.5, 'float32');
|
94 | expect(result.dtype).toBe('float32');
|
95 | expectValuesInRange(await result.data(), 0, 1.5);
|
96 | });
|
97 | it('should return a random 4D int32 array', async () => {
|
98 | const shape = [3, 4, 5, 6];
|
99 | const result = tf.randomUniform(shape, 0, 2, 'int32');
|
100 | expect(result.dtype).toBe('int32');
|
101 | expectValuesInRange(await result.data(), 0, 2);
|
102 | });
|
103 | it('should return a random 4D bool array', async () => {
|
104 | const shape = [3, 4, 5, 6];
|
105 | const result = tf.randomUniform(shape, 0, 1, 'bool');
|
106 | expect(result.dtype).toBe('bool');
|
107 | expectValuesInRange(await result.data(), 0, 1);
|
108 | });
|
109 | it('should return a random 5D float32 array', async () => {
|
110 | const shape = [2, 3, 4, 5, 6];
|
111 |
|
112 | let result = tf.randomUniform(shape, 0, 2.5);
|
113 | expect(result.dtype).toBe('float32');
|
114 | expectValuesInRange(await result.data(), 0, 2.5);
|
115 | result = tf.randomUniform(shape, 0, 1.5, 'float32');
|
116 | expect(result.dtype).toBe('float32');
|
117 | expectValuesInRange(await result.data(), 0, 1.5);
|
118 | });
|
119 | it('should return a random 5D int32 array', async () => {
|
120 | const shape = [2, 3, 4, 5, 6];
|
121 | const result = tf.randomUniform(shape, 0, 2, 'int32');
|
122 | expect(result.dtype).toBe('int32');
|
123 | expectValuesInRange(await result.data(), 0, 2);
|
124 | });
|
125 | it('should return a random 5D bool array', async () => {
|
126 | const shape = [2, 3, 4, 5, 6];
|
127 | const result = tf.randomUniform(shape, 0, 1, 'bool');
|
128 | expect(result.dtype).toBe('bool');
|
129 | expectValuesInRange(await result.data(), 0, 1);
|
130 | });
|
131 | });
|
132 |
|
\ | No newline at end of file |