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

Function deepAssertShapeConsistency

tfjs-core/src/tensor_util_env.ts:57–79  ·  view source on GitHub ↗
(
    val: TensorLike, shape: number[], indices: number[])

Source from the content-addressed store, hash-verified

55}
56
57function deepAssertShapeConsistency(
58 val: TensorLike, shape: number[], indices: number[]) {
59 indices = indices || [];
60 if (!(Array.isArray(val)) && !isTypedArray(val)) {
61 assert(
62 shape.length === 0,
63 () => `Element arr[${indices.join('][')}] is a primitive, ` +
64 `but should be an array/TypedArray of ${shape[0]} elements`);
65 return;
66 }
67 assert(
68 shape.length > 0,
69 () => `Element arr[${indices.join('][')}] should be a primitive, ` +
70 `but is an array of ${val.length} elements`);
71 assert(
72 val.length === shape[0],
73 () => `Element arr[${indices.join('][')}] should have ${shape[0]} ` +
74 `elements, but has ${val.length} elements`);
75 const subShape = shape.slice(1);
76 for (let i = 0; i < val.length; ++i) {
77 deepAssertShapeConsistency(val[i], subShape, indices.concat(i));
78 }
79}
80
81function assertDtype(
82 expectedDtype: DataType|'numeric'|'string_or_numeric',

Callers 1

inferShapeFunction · 0.85

Calls 5

isTypedArrayFunction · 0.90
assertFunction · 0.90
joinMethod · 0.80
sliceMethod · 0.65
concatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…