UNPKG

1.85 kBJavaScriptView 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 { inferShape } from '../tensor_util_env';
18import { makeTensor } from './tensor_ops_util';
19/**
20 * Creates a `tf.Tensor` with the provided values, shape and dtype.
21 *
22 * ```js
23 * // Pass an array of values to create a vector.
24 * tf.tensor([1, 2, 3, 4]).print();
25 * ```
26 *
27 * ```js
28 * // Pass a nested array of values to make a matrix or a higher
29 * // dimensional tensor.
30 * tf.tensor([[1, 2], [3, 4]]).print();
31 * ```
32 *
33 * ```js
34 * // Pass a flat array and specify a shape yourself.
35 * tf.tensor([1, 2, 3, 4], [2, 2]).print();
36 * ```
37 *
38 * @param values The values of the tensor. Can be nested array of numbers,
39 * or a flat array, or a `TypedArray`. If the values are strings,
40 * they will be encoded as utf-8 and kept as `Uint8Array[]`.
41 * @param shape The shape of the tensor. Optional. If not provided,
42 * it is inferred from `values`.
43 * @param dtype The data type.
44 *
45 * @doc {heading: 'Tensors', subheading: 'Creation'}
46 */
47export function tensor(values, shape, dtype) {
48 const inferredShape = inferShape(values, dtype);
49 return makeTensor(values, shape, inferredShape, dtype);
50}
51//# sourceMappingURL=tensor.js.map
\No newline at end of file