Skip to content

Commit a610b9e

Browse files
Conventions: Use "rank" for variable names, when appropriate
Fixes #588
1 parent 60b8e0a commit a610b9e

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

docs/SpecCodingConventions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Example:
110110
* Use "let" to introduce a variable and "set" to update a variable or assign to a property.
111111
* Use « » notation for literal lists, which helps make it clear that they are not JavaScript arrays.
112112
* When referring to abstract properties, use the short possessive form `|object|'s [=property=]`. Avoid the wordier `the [=property=] of |object|` form.
113+
* Use "rank" when describing the number of dimensions of a tensor (e.g. in variable names) rather than the ambiguous "size".
113114

114115

115116
### Method Definitions

index.bs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,10 +1897,8 @@ partial interface MLGraphBuilder {
18971897
</summary>
18981898
1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |input|, |filter|, and |options|.{{MLConv2dOptions/bias}} (if it [=map/exists=]) returns false, then [=exception/throw=] a {{TypeError}}.
18991899
1. If |options|.{{MLConv2dOptions/activation}} [=map/exists=], and [=MLGraphBuilder/validating activation=] with [=this=] and it returns false, then [=exception/throw=] a {{TypeError}}.
1900-
1. Let |inputSize| be |input|'s [=MLOperand/rank=].
1901-
1. Let |filterSize| be |filter|'s [=MLOperand/rank=].
1902-
1. If |inputSize| is not 4, then [=exception/throw=] a {{TypeError}}.
1903-
1. If |filterSize| is not 4, then [=exception/throw=] a {{TypeError}}.
1900+
1. If |input|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
1901+
1. If |filter|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
19041902
1. If |input|'s [=MLOperand/dataType=] is not the same as |filter|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
19051903
1. If |options|.{{MLConv2dOptions/padding}} does not [=map/exist=], set it to the [=/list=] « 0, 0, 0, 0 ».
19061904
1. Else if |options|.{{MLConv2dOptions/padding}}'s [=list/size=] is not 4, then [=exception/throw=] a {{TypeError}}.
@@ -2113,10 +2111,8 @@ partial interface MLGraphBuilder {
21132111
</summary>
21142112
1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |input|, |filter|, and |options|.{{MLConvTranspose2dOptions/bias}} (if it [=map/exists=]) returns false, then [=exception/throw=] a {{TypeError}}.
21152113
1. If |options|.{{MLConvTranspose2dOptions/activation}} [=map/exists=], and [=MLGraphBuilder/validating activation=] with [=this=] and it returns false, then [=exception/throw=] a {{TypeError}}.
2116-
1. Let |inputSize| be |input|'s [=MLOperand/rank=].
2117-
1. Let |filterSize| be |filter|'s [=MLOperand/rank=].
2118-
1. If |inputSize| is not 4, then [=exception/throw=] a {{TypeError}}.
2119-
1. If |filterSize| is not 4, then [=exception/throw=] a {{TypeError}}.
2114+
1. If |input|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
2115+
1. If |filter|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
21202116
1. If |input|'s [=MLOperand/dataType=] is not the same as |filter|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
21212117
1. If |options|.{{MLConvTranspose2dOptions/padding}} does not [=map/exist=], set it to the [=/list=] « 0, 0, 0, 0 ».
21222118
1. Else if |options|.{{MLConvTranspose2dOptions/padding}}'s [=list/size=] is not 4, then [=exception/throw=] a {{TypeError}}.
@@ -2872,11 +2868,9 @@ partial interface MLGraphBuilder {
28722868
The <dfn method for=MLGraphBuilder>gemm(|a|, |b|, |options|)</dfn> method steps are:
28732869
</summary>
28742870
1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |a| and |b| returns false, then [=exception/throw=] a {{TypeError}}.
2871+
1. If |a|'s [=MLOperand/rank=] is not 2 or |b|'s [=MLOperand/rank=] is not 2, then [=exception/throw=] a {{TypeError}}.
28752872
1. Let |shapeA| be a [=list/clone=] of |a|'s [=MLOperand/shape=].
2876-
1. Let |sizeA| be |shapeA|'s [=list/size=].
28772873
1. Let |shapeB| be a [=list/clone=] of |b|'s [=MLOperand/shape=].
2878-
1. Let |sizeB| be |shapeB|'s [=list/size=].
2879-
1. If |sizeA| is not 2 or |sizeB| is not 2, then [=exception/throw=] a {{TypeError}}.
28802874
1. If |options|.{{MLGemmOptions/aTranspose}} is true, then reverse the order of the items in |shapeA|.
28812875
1. If |options|.{{MLGemmOptions/bTranspose}} is true, then reverse the order of the items in |shapeB|.
28822876
1. If |shapeA|[1] is not equal to |shapeB|[0], then [=exception/throw=] a {{TypeError}}.
@@ -4282,17 +4276,17 @@ partial interface MLGraphBuilder {
42824276

42834277
<details open algorithm>
42844278
<summary>
4285-
To <dfn dfn-for=MLGraphBuilder>calculate matmul output sizes</dfn>, given |a| and |b| run the following steps:
4279+
To <dfn dfn-for=MLGraphBuilder>calculate matmul output sizes</dfn>, given {{MLOperand}} |a| and {{MLOperand}} |b| run the following steps:
42864280
</summary>
42874281
1. Let |shapeA| be a [=list/clone=] of |a|'s [=MLOperand/shape=]
4288-
1. Let |sizeA| be |shapeA|'s [=list/size=].
4282+
1. Let |rankA| be |a|'s [=MLOperand/rank=].
42894283
1. Let |shapeB| be a [=list/clone=] of |b|'s [=MLOperand/shape=]
4290-
1. Let |sizeB| be |shapeB|'s [=list/size=].
4291-
1. If either |sizeA| or |sizeB| is less than 2, then [=exception/throw=] a {{TypeError}}.
4292-
1. Let |colsA| be |shapeA|[|sizeA| - 1].
4293-
1. Let |rowsA| be |shapeA|[|sizeA| - 2].
4294-
1. Let |colsB| be |shapeB|[|sizeB| - 1].
4295-
1. Let |rowsB| be |shapeB|[|sizeB| - 2].
4284+
1. Let |rankB| be |b|'s [=MLOperand/rank=].
4285+
1. If either |rankA| or |rankB| is less than 2, then [=exception/throw=] a {{TypeError}}.
4286+
1. Let |colsA| be |shapeA|[|rankA| - 1].
4287+
1. Let |rowsA| be |shapeA|[|rankA| - 2].
4288+
1. Let |colsB| be |shapeB|[|rankB| - 1].
4289+
1. Let |rowsB| be |shapeB|[|rankB| - 2].
42964290
1. If |colsA| is not equal to |rowsB|, then [=exception/throw=] a {{TypeError}}.
42974291
1. Let |batchShapeA| be a [=list/clone=] of |shapeA| with the spatial dimensions (last 2 items) [=list/removed=].
42984292
1. Let |batchShapeB| be a [=list/clone=] of |shapeB| with the spatial dimensions (last 2 items) [=list/removed=].
@@ -4755,15 +4749,15 @@ partial interface MLGraphBuilder {
47554749
<summary>
47564750
To <dfn for="MLGraphBuilder">calculate reduction output sizes</dfn>, given a [=/list=] of unsigned integers |inputShape|, a optional [=/list=] of unsigned integers |axes|, and [=/boolean=] |keepDimensions|, perform the following steps. They return a new [=/list=] of unsigned integers.
47574751
</summary>
4758-
1. Let |inputSize| be |inputShape|'s [=list/size=].
4759-
1. If |axes| is not given, let |axes| be [=the range=] 0 to |inputSize|, exclusive.
4752+
1. Let |inputRank| be |inputShape|'s [=list/size=].
4753+
1. If |axes| is not given, let |axes| be [=the range=] 0 to |inputRank|, exclusive.
47604754
1. If |keepDimensions| is true, then:
47614755
1. Let |outputShape| be a [=list/clone=] of |inputShape|.
47624756
1. [=list/For each=] |axis| of |axes|:
47634757
1. Set |outputShape|[|axis|] to 1.
47644758
1. Otherwise:
47654759
1. Let |outputShape| be an empty [=/list=].
4766-
1. [=list/For each=] |index| in [=the range=] 0 to |inputSize|, exclusive:
4760+
1. [=list/For each=] |index| in [=the range=] 0 to |inputRank|, exclusive:
47674761
1. If |axes| does not [=list/contain=] |index|, then [=list/append=] |inputShape|[|index|].
47684762
1. Return |outputShape|.
47694763
</details>

0 commit comments

Comments
 (0)