Skip to content

Commit 54965a1

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 d48e394 commit 54965a1

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
@@ -2892,11 +2892,13 @@ partial interface MLGraphBuilder {
28922892
The <dfn method for=MLGraphBuilder>gemm(|a|, |b|, |options|)</dfn> method steps are:
28932893
</summary>
28942894
<div class=algorithm-steps>
2895-
1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|.
2896-
1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|.
2895+
1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
2896+
1. Let |sizeA| be the [=list/size=] of |shapeA|.
2897+
1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
2898+
1. Let |sizeB| be the [=list/size=] of |shapeB|.
28972899
1. If |sizeA| is not 2 or |sizeB| is not 2, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
2898-
1. If |options|.{{MLGemmOptions/aTranspose}} is true, then let |shapeA| be the reverse array of |shapeA|.
2899-
1. If |options|.{{MLGemmOptions/bTranspose}} is true, then let |shapeB| be the reverse array of |shapeB|.
2900+
1. If |options|.{{MLGemmOptions/aTranspose}} is true, then reverse the order of the items in |shapeA|.
2901+
1. If |options|.{{MLGemmOptions/bTranspose}} is true, then reverse the order of the items in |shapeB|.
29002902
1. If |shapeA|[1] is not equal to |shapeB|[0], then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
29012903
1. If |options|.{{MLGemmOptions/c}} [=map/exists=] and is not [=unidirectionally broadcastable=] to the shape [|shapeA|[0], |shapeB|[1]], then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
29022904
<div class="note">
@@ -4345,16 +4347,19 @@ partial interface MLGraphBuilder {
43454347
To <dfn dfn-for=MLGraphBuilder>calculate matmul output sizes</dfn>, given |a| and |b| run the following steps:
43464348
</summary>
43474349
<div class=algorithm-steps>
4348-
1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|.
4349-
1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|.
4350-
1. If |sizeA| and |sizeB| is 1, return the [=/list=] « 1 ».
4351-
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.
4350+
1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
4351+
1. Let |sizeA| be the [=list/size=] of |shapeA|.
4352+
1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
4353+
1. Let |sizeB| be the [=list/size=] of |shapeB|.
4354+
1. If |sizeA| and |sizeB| is 1, return « 1 ».
4355+
1. If |sizeA| is 1, then [=list/prepend=] 1 to |shapeA| and set |sizeA| to 2.
43524356
1. If |shapeA|[0] is not equal to |shapeB|[|sizeB| - 2], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4353-
1. If |sizeB| is 1 and |sizeA| is not, then append 1 to |shapeB| to become [ |shapeB| | 1 ] and let |sizeB| be 2.
4357+
1. If |sizeB| is 1, then [=list/append=] 1 to |shapeB| and set |sizeB| to 2.
43544358
1. If |shapeA|[|sizeA| - 1] is not equal to |shapeB|[0], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4355-
1. Let |shape| be an array whose size |size| is the maximum of |sizeA| and |sizeB|.
4359+
1. Let |size| be the maximum of |sizeA| and |sizeB|.
4360+
1. Let |shape| be a new [=/list=].
43564361
1. [=list/For each=] |index| in [=the range=] 0 to |size|, exclusive:
4357-
1. Set |shape|[|index|] to the maximum of |shapeA|[|index|] and |shapeB|[|index|].
4362+
1. [=list/Append=] the maximum of |shapeA|[|index|] and |shapeB|[|index|] to |shape|.
43584363
1. Return |shape|.
43594364
</div>
43604365
</details>

0 commit comments

Comments
 (0)