MCPcopy Create free account
hub / github.com/tensorflow/tfjs / mergeElementShape

Function mergeElementShape

tfjs-converter/src/executor/tensor_utils.ts:87–113  ·  view source on GitHub ↗
(
    elementShapeA: number|number[], elementShapeB: number|number[])

Source from the content-addressed store, hash-verified

85}
86
87export function mergeElementShape(
88 elementShapeA: number|number[], elementShapeB: number|number[]): number|
89 number[] {
90 if (typeof elementShapeA === 'number') {
91 return elementShapeB;
92 }
93 if (typeof elementShapeB === 'number') {
94 return elementShapeA;
95 }
96
97 if (elementShapeA.length !== elementShapeB.length) {
98 throw new Error(`Incompatible ranks during merge: ${elementShapeA} vs. ${
99 elementShapeB}`);
100 }
101
102 const result: number[] = [];
103 for (let i = 0; i < elementShapeA.length; ++i) {
104 const dim0 = elementShapeA[i];
105 const dim1 = elementShapeB[i];
106 if (dim0 >= 0 && dim1 >= 0 && dim0 !== dim1) {
107 throw new Error(`Incompatible shape during merge: ${elementShapeA} vs. ${
108 elementShapeB}`);
109 }
110 result[i] = dim0 >= 0 ? dim0 : dim1;
111 }
112 return result;
113}

Callers 2

splitFunction · 0.90
inferElementShapeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…