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 | */
|
17 | import { ENGINE } from '../engine';
|
18 | import { Range } from '../kernel_names';
|
19 | /**
|
20 | * Creates a new `tf.Tensor1D` filled with the numbers in the range provided.
|
21 | *
|
22 | * The tensor is a is half-open interval meaning it includes start, but
|
23 | * excludes stop. Decrementing ranges and negative step values are also
|
24 | * supported.sv
|
25 | *
|
26 | *
|
27 | * ```js
|
28 | * tf.range(0, 9, 2).print();
|
29 | * ```
|
30 | *
|
31 | * @param start An integer start value
|
32 | * @param stop An integer stop value
|
33 | * @param step An integer increment (will default to 1 or -1)
|
34 | * @param dtype The data type of the output tensor. Defaults to 'float32'.
|
35 | *
|
36 | * @doc {heading: 'Tensors', subheading: 'Creation'}
|
37 | */
|
38 | export function range(start, stop, step = 1, dtype = 'float32') {
|
39 | if (step === 0) {
|
40 | throw new Error('Cannot have a step of zero');
|
41 | }
|
42 | const attrs = { start, stop, step, dtype };
|
43 | return ENGINE.runKernel(Range, {} /* inputs */, attrs);
|
44 | }
|
45 | //# sourceMappingURL=range.js.map |
\ | No newline at end of file |