Skip to content

Commit 4e6cd98

Browse files
Wording change: Tighten up output shape calculation algorithms
For gemm() - make lists that are mutated be explicit clones using Infra terminology, and simplify the wording reversing the lists. For matmul() - make lists that are mutated be explicit clones using Infra terminology, use append/prepend definitions from Infra, convert a variable change from "let" to "set" and drop use of "array". For #395
1 parent d1a02f2 commit 4e6cd98

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

index.bs

+16-11
Original file line numberDiff line numberDiff line change
@@ -3060,11 +3060,13 @@ partial interface MLGraphBuilder {
30603060
The <dfn method for=MLGraphBuilder>gemm(|a|, |b|, |options|)</dfn> method steps are:
30613061
</summary>
30623062
<div class=algorithm-steps>
3063-
1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|.
3064-
1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|.
3063+
1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
3064+
1. Let |sizeA| be the [=list/size=] of |shapeA|.
3065+
1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
3066+
1. Let |sizeB| be the [=list/size=] of |shapeB|.
30653067
1. If |sizeA| is not 2 or |sizeB| is not 2, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3066-
1. If |options|.{{MLGemmOptions/aTranspose}} is true, then let |shapeA| be the reverse array of |shapeA|.
3067-
1. If |options|.{{MLGemmOptions/bTranspose}} is true, then let |shapeB| be the reverse array of |shapeB|.
3068+
1. If |options|.{{MLGemmOptions/aTranspose}} is true, then reverse the order of the items in |shapeA|.
3069+
1. If |options|.{{MLGemmOptions/bTranspose}} is true, then reverse the order of the items in |shapeB|.
30683070
1. If |shapeA|[1] is not equal to |shapeB|[0], then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
30693071
1. If |options|.{{MLGemmOptions/c}} [=map/exists=] and is not unidirectionally broadcastable to the shape [|shapeA|[0], |shapeB|[1]] according to the [[!numpy-broadcasting-rule]], then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
30703072
<div class="note">
@@ -4514,16 +4516,19 @@ partial interface MLGraphBuilder {
45144516
To <dfn dfn-for=MLGraphBuilder>calculate matmul output sizes</dfn>, given |a| and |b| run the following steps:
45154517
</summary>
45164518
<div class=algorithm-steps>
4517-
1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|.
4518-
1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|.
4519-
1. If |sizeA| and |sizeB| is 1, return the [=/list=] « 1 ».
4520-
1. If |sizeA| is 1 and |sizeB| is not, then insert 1 in the front of |shapeA| to become [ 1 | |shapeA| ] and let |sizeA| be 2.
4519+
1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
4520+
1. Let |sizeA| be the [=list/size=] of |shapeA|.
4521+
1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
4522+
1. Let |sizeB| be the [=list/size=] of |shapeB|.
4523+
1. If |sizeA| and |sizeB| is 1, return « 1 ».
4524+
1. If |sizeA| is 1, then [=list/prepend=] 1 to |shapeA| and set |sizeA| to 2.
45214525
1. If |shapeA|[0] is not equal to |shapeB|[|sizeB| - 2], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4522-
1. If |sizeB| is 1 and |sizeA| is not, then append 1 to |shapeB| to become [ |shapeB| | 1 ] and let |sizeB| be 2.
4526+
1. If |sizeB| is 1, then [=list/append=] 1 to |shapeB| and set |sizeB| to 2.
45234527
1. If |shapeA|[|sizeA| - 1] is not equal to |shapeB|[0], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4524-
1. Let |shape| be an array whose size |size| is the maximum of |sizeA| and |sizeB|.
4528+
1. Let |size| be the maximum of |sizeA| and |sizeB|.
4529+
1. Let |shape| be a new [=/list=].
45254530
1. [=list/For each=] |index| in [=the range=] 0 to |size|, exclusive:
4526-
1. Set |shape|[|index|] to the maximum of |shapeA|[|index|] and |shapeB|[|index|].
4531+
1. [=list/Append=] the maximum of |shapeA|[|index|] and |shapeB|[|index|] to |shape|.
45274532
1. Return |shape|.
45284533
</div>
45294534
</details>

0 commit comments

Comments
 (0)