(
shapeA: number[], shapeB: number[])
| 58 | } |
| 59 | |
| 60 | export 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 | } |
no test coverage detected
searching dependent graphs…