MCPcopy
hub / github.com/tensorflow/tfjs / tensor2d

Function tensor2d

tfjs-core/src/ops/tensor2d.ts:48–66  ·  view source on GitHub ↗
(
    values: TensorLike2D, shape?: [number, number],
    dtype?: DataType)

Source from the content-addressed store, hash-verified

46 * @doc {heading: 'Tensors', subheading: 'Creation'}
47 */
48export function tensor2d(
49 values: TensorLike2D, shape?: [number, number],
50 dtype?: DataType): Tensor2D {
51 assertNonNull(values);
52 if (shape != null && shape.length !== 2) {
53 throw new Error('tensor2d() requires shape to have two numbers');
54 }
55 const inferredShape = inferShape(values, dtype);
56 if (inferredShape.length !== 2 && inferredShape.length !== 1) {
57 throw new Error(
58 'tensor2d() requires values to be number[][] or flat/TypedArray');
59 }
60 if (inferredShape.length === 1 && shape == null) {
61 throw new Error(
62 'tensor2d() requires shape to be provided when `values` ' +
63 'are a flat/TypedArray');
64 }
65 return makeTensor(values, shape, inferredShape, dtype) as Tensor2D;
66}

Callers 15

constructorMethod · 0.90
models_test.tsFile · 0.90
losses_test.tsFile · 0.90
callbacks_test.tsFile · 0.90
metrics_test.tsFile · 0.90
variables_test.tsFile · 0.90
topology_test.tsFile · 0.90
training_test.tsFile · 0.90

Calls 3

assertNonNullFunction · 0.90
inferShapeFunction · 0.90
makeTensorFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…