You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`
Copy file name to clipboardExpand all lines: index.bs
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -5903,26 +5903,26 @@ Broadcasting refers to how operations treat tensors with different shapes, and f
5903
5903
5904
5904
<details open algorithm>
5905
5905
<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.
5907
5907
</summary>
5908
5908
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|.
5914
5914
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|.
5920
5920
1. Return |outputShape|.
5921
5921
5922
5922
</details>
5923
5923
5924
5924
<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.
0 commit comments