From 49e76e61b0207351929729f1e6050131caf1e1f7 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 19 Jan 2024 16:03:11 -0800 Subject: [PATCH] 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 --- index.bs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/index.bs b/index.bs index 465b34ab..246ba2a5 100644 --- a/index.bs +++ b/index.bs @@ -3084,11 +3084,13 @@ partial interface MLGraphBuilder {
1. [=Assert=]: the type of |a| and |b| is {{MLOperand}}. - 1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|. - 1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|. + 1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. + 1. Let |sizeA| be the [=list/size=] of |shapeA|. + 1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. + 1. Let |sizeB| be the [=list/size=] of |shapeB|. 1. If |sizeA| is not 2 or |sizeB| is not 2, then [=exception/throw=] a "{{DataError}}" {{DOMException}}. - 1. If |options|.{{MLGemmOptions/aTranspose}} is true, then let |shapeA| be the reverse array of |shapeA|. - 1. If |options|.{{MLGemmOptions/bTranspose}} is true, then let |shapeB| be the reverse array of |shapeB|. + 1. If |options|.{{MLGemmOptions/aTranspose}} is true, then reverse the order of the items in |shapeA|. + 1. If |options|.{{MLGemmOptions/bTranspose}} is true, then reverse the order of the items in |shapeB|. 1. If |shapeA|[1] is not equal to |shapeB|[0], then [=exception/throw=] a "{{DataError}}" {{DOMException}}. 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}}.
@@ -4571,16 +4573,19 @@ partial interface MLGraphBuilder { To calculate matmul output sizes, given |a| and |b| run the following steps:
- 1. Let |shapeA| be |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeA| the [=list/size=] of |shapeA|. - 1. Let |shapeB| be |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |sizeB| the [=list/size=] of |shapeB|. + 1. Let |shapeA| be a [=list/clone=] of |a|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. + 1. Let |sizeA| be the [=list/size=] of |shapeA|. + 1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. + 1. Let |sizeB| be the [=list/size=] of |shapeB|. 1. If |sizeA| and |sizeB| is 1, return « 1 ». - 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. + 1. If |sizeA| is 1, then [=list/prepend=] 1 to |shapeA| and set |sizeA| to 2. 1. If |shapeA|[0] is not equal to |shapeB|[|sizeB| - 2], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}. - 1. If |sizeB| is 1 and |sizeA| is not, then append 1 to |shapeB| to become [ |shapeB| | 1 ] and let |sizeB| be 2. + 1. If |sizeB| is 1, then [=list/append=] 1 to |shapeB| and set |sizeB| to 2. 1. If |shapeA|[|sizeA| - 1] is not equal to |shapeB|[0], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}. - 1. Let |shape| be an array whose size |size| is the maximum of |sizeA| and |sizeB|. + 1. Let |size| is the maximum of |sizeA| and |sizeB|. + 1. Let |shape| be a new [=/list=]. 1. [=map/For each=] |index| in [=the range=] 0 to |size|, exclusive: - 1. Set |shape|[|index|] to the maximum of |shapeA|[|index|] and |shapeB|[|index|]. + 1. [=list/Append=] the maximum of |shapeA|[|index|] and |shapeB|[|index|] to |shape|. 1. Return |shape|.