UNPKG

1.8 kBTypeScriptView 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 { Tensor } from '../tensor';
18import { TensorLike } from '../types';
19import { DataType, Rank, ShapeMap } from '../types';
20/**
21 * Creates a `tf.Tensor` with the provided values, shape and dtype.
22 *
23 * ```js
24 * // Pass an array of values to create a vector.
25 * tf.tensor([1, 2, 3, 4]).print();
26 * ```
27 *
28 * ```js
29 * // Pass a nested array of values to make a matrix or a higher
30 * // dimensional tensor.
31 * tf.tensor([[1, 2], [3, 4]]).print();
32 * ```
33 *
34 * ```js
35 * // Pass a flat array and specify a shape yourself.
36 * tf.tensor([1, 2, 3, 4], [2, 2]).print();
37 * ```
38 *
39 * @param values The values of the tensor. Can be nested array of numbers,
40 * or a flat array, or a `TypedArray`. If the values are strings,
41 * they will be encoded as utf-8 and kept as `Uint8Array[]`.
42 * @param shape The shape of the tensor. Optional. If not provided,
43 * it is inferred from `values`.
44 * @param dtype The data type.
45 *
46 * @doc {heading: 'Tensors', subheading: 'Creation'}
47 */
48export declare function tensor<R extends Rank>(values: TensorLike, shape?: ShapeMap[R], dtype?: DataType): Tensor<R>;