Skip to content

Commit 4eda710

Browse files
authored
Fix unidirectionally broadcast the shapes steps (#663)
* Fix unidirectionally broadcast the shapes steps Fix #622 * Update the call sites of "unidirectionally broadcasting the shapes" * Reverse the order of `shapeFrom` and `shapeTo`
1 parent f133ff0 commit 4eda710

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

index.bs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5903,26 +5903,26 @@ Broadcasting refers to how operations treat tensors with different shapes, and f
59035903

59045904
<details open algorithm>
59055905
<summary>
5906-
To <dfn data-lt="unidirectionally broadcasting the shapes">unidirectionally broadcast the shapes</dfn> |shapeA| and |shapeB|, perform the following steps. |shapeA| and |shapeB| are [=/lists=] of positive integers, representing the dimensions of tensors, and the steps return a new [=/list=] of positive integers, or failure.
5906+
To <dfn data-lt="unidirectionally broadcasting the shapes">unidirectionally broadcast the shapes</dfn> |shapeFrom| and |shapeTo|, perform the following steps. |shapeFrom| and |shapeTo| are [=/lists=] of positive integers, representing the dimensions of tensors, and the steps return a new [=/list=] of positive integers, or failure.
59075907
</summary>
59085908

5909-
1. Let |sizeA| be |shapeA|'s [=list/size=].
5910-
1. Let |sizeB| be |shapeB|'s [=list/size=].
5911-
1. If |sizeB| > |sizeA|, then return failure.
5912-
1. Let |paddedB| be a [=list/clone=] of |shapeB|.
5913-
1. While |paddedB|'s [=list/size=] is less than |sizeA|, [=list/prepend=] 1 to |paddedB|.
5909+
1. Let |sizeFrom| be |shapeFrom|'s [=list/size=].
5910+
1. Let |sizeTo| be |shapeTo|'s [=list/size=].
5911+
1. If |sizeFrom| > |sizeTo|, then return failure.
5912+
1. Let |paddedShapeFrom| be a [=list/clone=] of |shapeFrom|.
5913+
1. While |paddedShapeFrom|'s [=list/size=] is less than |sizeTo|, [=list/prepend=] 1 to |paddedShapeFrom|.
59145914
1. Let |outputShape| be a new [=/list=].
5915-
1. [=list/For each=] |index| in [=the range=] 0 to |sizeA|, exclusive:
5916-
1. Let |dimA| be |shapeA|[|index|].
5917-
1. Let |dimB| be |paddedB|[|index|].
5918-
1. If |dimA| is not equal to |dimB| and |dimA| is not equal to 1, then return failure.
5919-
1. [=list/Append=] |dimA| to |outputShape|.
5915+
1. [=list/For each=] |index| in [=the range=] 0 to |sizeTo|, exclusive:
5916+
1. Let |dimFrom| be |paddedShapeFrom|[|index|].
5917+
1. Let |dimTo| be |shapeTo|[|index|].
5918+
1. If |dimTo| is not equal to |dimFrom| and |dimFrom| is not equal to 1, then return failure.
5919+
1. [=list/Append=] |dimTo| to |outputShape|.
59205920
1. Return |outputShape|.
59215921

59225922
</details>
59235923

59245924
<p algorithm>
5925-
|shapeA| is <dfn>unidirectionally broadcastable</dfn> to |shapeB| if [=unidirectionally broadcasting the shapes=] |shapeA| and |shapeB| does not result in failure.
5925+
|shapeFrom| is <dfn>unidirectionally broadcastable</dfn> to |shapeTo| if [=unidirectionally broadcasting the shapes=] |shapeFrom| and |shapeTo| does not result in failure.
59265926
</p>
59275927

59285928
<details open algorithm>

0 commit comments

Comments
 (0)