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

Function assertAndGetBroadcastShape

tfjs-core/src/ops/broadcast_util.ts:60–87  ·  view source on GitHub ↗
(
    shapeA: number[], shapeB: number[])

Source from the content-addressed store, hash-verified

58}
59
60export function assertAndGetBroadcastShape(
61 shapeA: number[], shapeB: number[]): number[] {
62 const l = Math.max(shapeA.length, shapeB.length);
63 const result = new Array(l);
64
65 for (let i = 0; i < l; i++) {
66 let a = shapeA[shapeA.length - i - 1];
67 if (a == null) {
68 a = 1;
69 }
70 let b = shapeB[shapeB.length - i - 1];
71 if (b == null) {
72 b = 1;
73 }
74 if (a === 1) {
75 result[l - i - 1] = b;
76 } else if (b === 1) {
77 result[l - i - 1] = a;
78 } else if (a !== b) {
79 const errMsg = `Operands could not be broadcast together with shapes ` +
80 `${shapeA} and ${shapeB}.`;
81 throw Error(errMsg);
82 } else {
83 result[l - i - 1] = a;
84 }
85 }
86 return result;
87}

Callers 15

Mod_grad.tsFile · 0.90
Multiply_grad.tsFile · 0.90
FloorDiv_grad.tsFile · 0.90
Atan2_grad.tsFile · 0.90
greater_Function · 0.90
lessEqual_Function · 0.90
squaredDifference_Function · 0.90
maximum_Function · 0.90
where_Function · 0.90
greaterEqual_Function · 0.90
minimum_Function · 0.90
notEqual_Function · 0.90

Calls 2

ErrorFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…