Skip to content

Commit c5314ea

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 479ce17 commit c5314ea

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
@@ -3080,11 +3080,13 @@ partial interface MLGraphBuilder {
30803080
The <dfn method for=MLGraphBuilder>gemm(|a|, |b|, |options|)</dfn> method steps are:
30813081
</summary>
30823082
<div class=algorithm-steps>
3083-
1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|.
3084-
1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|.
3083+
1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
3084+
1. Let |sizeA| be the [=list/size=] of |shapeA|.
3085+
1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
3086+
1. Let |sizeB| be the [=list/size=] of |shapeB|.
30853087
1. If |sizeA| is not 2 or |sizeB| is not 2, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3086-
1. If |options|.{{MLGemmOptions/aTranspose}} is true, then let |shapeA| be the reverse array of |shapeA|.
3087-
1. If |options|.{{MLGemmOptions/bTranspose}} is true, then let |shapeB| be the reverse array of |shapeB|.
3088+
1. If |options|.{{MLGemmOptions/aTranspose}} is true, then reverse the order of the items in |shapeA|.
3089+
1. If |options|.{{MLGemmOptions/bTranspose}} is true, then reverse the order of the items in |shapeB|.
30883090
1. If |shapeA|[1] is not equal to |shapeB|[0], then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
30893091
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}}.
30903092
<div class="note">
@@ -4540,16 +4542,19 @@ partial interface MLGraphBuilder {
45404542
To <dfn dfn-for=MLGraphBuilder>calculate matmul output sizes</dfn>, given |a| and |b| run the following steps:
45414543
</summary>
45424544
<div class=algorithm-steps>
4543-
1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|.
4544-
1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|.
4545-
1. If |sizeA| and |sizeB| is 1, return the [=/list=] « 1 ».
4546-
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.
4545+
1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
4546+
1. Let |sizeA| be the [=list/size=] of |shapeA|.
4547+
1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
4548+
1. Let |sizeB| be the [=list/size=] of |shapeB|.
4549+
1. If |sizeA| and |sizeB| is 1, return « 1 ».
4550+
1. If |sizeA| is 1, then [=list/prepend=] 1 to |shapeA| and set |sizeA| to 2.
45474551
1. If |shapeA|[0] is not equal to |shapeB|[|sizeB| - 2], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4548-
1. If |sizeB| is 1 and |sizeA| is not, then append 1 to |shapeB| to become [ |shapeB| | 1 ] and let |sizeB| be 2.
4552+
1. If |sizeB| is 1, then [=list/append=] 1 to |shapeB| and set |sizeB| to 2.
45494553
1. If |shapeA|[|sizeA| - 1] is not equal to |shapeB|[0], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4550-
1. Let |shape| be an array whose size |size| is the maximum of |sizeA| and |sizeB|.
4554+
1. Let |size| be the maximum of |sizeA| and |sizeB|.
4555+
1. Let |shape| be a new [=/list=].
45514556
1. [=list/For each=] |index| in [=the range=] 0 to |size|, exclusive:
4552-
1. Set |shape|[|index|] to the maximum of |shapeA|[|index|] and |shapeB|[|index|].
4557+
1. [=list/Append=] the maximum of |shapeA|[|index|] and |shapeB|[|index|] to |shape|.
45534558
1. Return |shape|.
45544559
</div>
45554560
</details>

0 commit comments

Comments
 (0)