You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/SpecCodingConventions.md
+2
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,8 @@ Example:
110
110
* Use "let" to introduce a variable and "set" to update a variable or assign to a property.
111
111
* Use « » notation for literal lists, which helps make it clear that they are not JavaScript arrays.
112
112
* 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".
114
+
* Only use single capital letters as variable names when referring to tensors; i.e. prefer `|shapeA|` to `|A|`, but tensor `|T|` is okay.
1. If |variance|'s [=MLOperand/rank=] is not 1, then [=exception/throw=] a {{TypeError}}.
1563
1563
1. If |variance|'s [=MLOperand/shape=][0] is not equal to |input|'s [=MLOperand/shape=][|options|.{{MLBatchNormalizationOptions/axis}}], then [=exception/throw=] a {{TypeError}}.
1564
1564
1. If |options|.{{MLBatchNormalizationOptions/scale}}[=map/exists=]:
1565
-
1. If its [=list/size=] is not 1, then [=exception/throw=] a {{TypeError}}.
1565
+
1. If its [=MLOperand/rank=] is not 1, then [=exception/throw=] a {{TypeError}}.
1566
1566
1. If |options|.{{MLBatchNormalizationOptions/scale}}'s [=MLOperand/shape=][0] is not equal to |input|'s [=MLOperand/shape=][|options|.{{MLBatchNormalizationOptions/axis}}], then [=exception/throw=] a {{TypeError}}.
1567
1567
1. If |options|.{{MLBatchNormalizationOptions/bias}}[=map/exists=]:
1568
-
1. If its [=list/size=] is not 1, then [=exception/throw=] a {{TypeError}}.
1568
+
1. If its [=MLOperand/rank=] is not 1, then [=exception/throw=] a {{TypeError}}.
1569
1569
1. If |options|.{{MLBatchNormalizationOptions/bias}}'s [=MLOperand/shape=][0] is not equal to |input|'s [=MLOperand/shape=][|options|.{{MLBatchNormalizationOptions/axis}}], then [=exception/throw=] a {{TypeError}}.
1570
1570
1. *Make graph connections:*
1571
1571
1. Let |operator| be an [=operator=] for the batchNormalization operation, given |input|, |mean|, |variance| and |options|.
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}}.
1903
1903
1. If |options|.{{MLConv2dOptions/activation}}[=map/exists=], and [=MLGraphBuilder/validating activation=] with [=this=] and it returns false, then [=exception/throw=] a {{TypeError}}.
1904
-
1. Let |inputSize| be |input|'s [=MLOperand/rank=].
1905
-
1. Let |filterSize| be |filter|'s [=MLOperand/rank=].
1906
-
1. If |inputSize| is not 4, then [=exception/throw=] a {{TypeError}}.
1907
-
1. If |filterSize| is not 4, then [=exception/throw=] a {{TypeError}}.
1904
+
1. If |input|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
1905
+
1. If |filter|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
1908
1906
1. If |input|'s [=MLOperand/dataType=] is not the same as |filter|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
1909
1907
1. If |options|.{{MLConv2dOptions/padding}} does not [=map/exist=], set it to the [=/list=] « 0, 0, 0, 0 ».
1910
1908
1. Else if |options|.{{MLConv2dOptions/padding}}'s [=list/size=] is not 4, then [=exception/throw=] a {{TypeError}}.
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}}.
2119
2117
1. If |options|.{{MLConvTranspose2dOptions/activation}}[=map/exists=], and [=MLGraphBuilder/validating activation=] with [=this=] and it returns false, then [=exception/throw=] a {{TypeError}}.
2120
-
1. Let |inputSize| be |input|'s [=MLOperand/rank=].
2121
-
1. Let |filterSize| be |filter|'s [=MLOperand/rank=].
2122
-
1. If |inputSize| is not 4, then [=exception/throw=] a {{TypeError}}.
2123
-
1. If |filterSize| is not 4, then [=exception/throw=] a {{TypeError}}.
2118
+
1. If |input|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
2119
+
1. If |filter|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
2124
2120
1. If |input|'s [=MLOperand/dataType=] is not the same as |filter|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
2125
2121
1. If |options|.{{MLConvTranspose2dOptions/padding}} does not [=map/exist=], set it to the [=/list=] « 0, 0, 0, 0 ».
2126
2122
1. Else if |options|.{{MLConvTranspose2dOptions/padding}}'s [=list/size=] is not 4, then [=exception/throw=] a {{TypeError}}.
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.
4761
4755
</summary>
4762
-
1. Let |inputSize| be |inputShape|'s [=list/size=].
4763
-
1. If |axes| is not given, let |axes| be [=the range=] 0 to |inputSize|, exclusive.
4756
+
1. Let |inputRank| be |inputShape|'s [=list/size=].
4757
+
1. If |axes| is not given, let |axes| be [=the range=] 0 to |inputRank|, exclusive.
4764
4758
1. If |keepDimensions| is true, then:
4765
4759
1. Let |outputShape| be a [=list/clone=] of |inputShape|.
4766
4760
1. [=list/For each=] |axis| of |axes|:
4767
4761
1. Set |outputShape|[|axis|] to 1.
4768
4762
1. Otherwise:
4769
4763
1. Let |outputShape| be an empty [=/list=].
4770
-
1. [=list/For each=] |index| in [=the range=] 0 to |inputSize|, exclusive:
4764
+
1. [=list/For each=] |index| in [=the range=] 0 to |inputRank|, exclusive:
4771
4765
1. If |axes| does not [=list/contain=] |index|, then [=list/append=] |inputShape|[|index|].
The <dfn method for=MLGraphBuilder>slice(|input|, |starts|, |sizes|)</dfn> method steps are:
5190
5184
</summary>
5191
5185
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}.
5192
-
1. If |sizes|'s [=list/size=]is 0, then [=exception/throw=] a {{TypeError}}.
5186
+
1. If any of |sizes|'s [=list/items=]are 0, then [=exception/throw=] a {{TypeError}}.
5193
5187
1. If |starts|'s [=list/size=] and |sizes|'s [=list/size=] are not both equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}.
5194
5188
1. *Make graph connections:*
5195
5189
1. Let |output| be the result of [=copying an MLOperand=] given |input|.
@@ -5787,17 +5781,17 @@ Broadcasting refers to how operations treat tensors with different shapes, and f
5787
5781
5788
5782
<details open algorithm>
5789
5783
<summary>
5790
-
To <dfn data-lt="unidirectionally broadcasting the shapes">unidirectionally broadcast the shapes</dfn> |A| and |B|, perform the following steps. |A| and |B| are [=/lists=] of positive integers, representing the dimensions of tensors, and the steps return a new [=/list=] of positive integers, or failure.
5784
+
To <dfn data-lt="unidirectionally broadcasting the shapes">unidirectionally broadcast the shapes</dfn> |shapeA| and |shapeB|, perform the following steps. |shapeA| and |shapeB| are [=/lists=] of positive integers, representing the dimensions of tensors, and the steps return a new [=/list=] of positive integers, or failure.
5791
5785
</summary>
5792
5786
5793
-
1. Let |sizeA| be |A|'s [=list/size=].
5794
-
1. Let |sizeB| be |B|'s [=list/size=].
5787
+
1. Let |sizeA| be |shapeA|'s [=list/size=].
5788
+
1. Let |sizeB| be |shapeB|'s [=list/size=].
5795
5789
1. If |sizeB| > |sizeA|, then return failure.
5796
-
1. Let |paddedB| be a [=list/clone=] of |B|.
5790
+
1. Let |paddedB| be a [=list/clone=] of |shapeB|.
5797
5791
1. While |paddedB|'s [=list/size=] is less than |sizeA|, [=list/prepend=] 1 to |paddedB|.
5798
5792
1. Let |outputShape| be a new [=/list=].
5799
5793
1. [=list/For each=] |index| in [=the range=] 0 to |sizeA|, exclusive:
5800
-
1. Let |dimA| be |A|[|index|].
5794
+
1. Let |dimA| be |shapeA|[|index|].
5801
5795
1. Let |dimB| be |paddedB|[|index|].
5802
5796
1. If |dimA| is not equal to |dimB| and |dimA| is not equal to 1, then return failure.
5803
5797
1. [=list/Append=] |dimA| to |outputShape|.
@@ -5806,20 +5800,20 @@ To <dfn data-lt="unidirectionally broadcasting the shapes">unidirectionally broa
5806
5800
</details>
5807
5801
5808
5802
<p algorithm>
5809
-
|A| is <dfn>unidirectionally broadcastable</dfn> to |B| if [=unidirectionally broadcasting the shapes=] |A| and |B| does not result in failure.
5803
+
|shapeA| is <dfn>unidirectionally broadcastable</dfn> to |shapeB| if [=unidirectionally broadcasting the shapes=] |shapeA| and |shapeB| does not result in failure.
5810
5804
</p>
5811
5805
5812
5806
<details open algorithm>
5813
5807
<summary>
5814
-
To <dfn data-lt="bidirectionally broadcasting the shapes">bidirectionally broadcast the shapes</dfn> |A| and |B|, perform the following steps. |A| and |B| are [=/lists=] of positive integers, representing the dimensions of tensors, and the steps return a new [=/list=] of positive integers, or failure.
5808
+
To <dfn data-lt="bidirectionally broadcasting the shapes">bidirectionally broadcast the shapes</dfn> |shapeA| and |shapeB|, perform the following steps. |shapeA| and |shapeB| are [=/lists=] of positive integers, representing the dimensions of tensors, and the steps return a new [=/list=] of positive integers, or failure.
5815
5809
</summary>
5816
5810
5817
-
1. Let |sizeA| be |A|'s [=list/size=].
5818
-
1. Let |sizeB| be |B|'s [=list/size=].
5811
+
1. Let |sizeA| be |shapeA|'s [=list/size=].
5812
+
1. Let |sizeB| be |shapeB|'s [=list/size=].
5819
5813
1. Let |outputSize| be the maximum of |sizeA| and |sizeB|.
5820
-
1. Let |paddedA| be a [=list/clone=] of |A|.
5814
+
1. Let |paddedA| be a [=list/clone=] of |shapeA|.
5821
5815
1. While |paddedA|'s [=list/size=] is less than |outputSize|, [=list/prepend=] 1 to |paddedA|.
5822
-
1. Let |paddedB| be a [=list/clone=] of |B|.
5816
+
1. Let |paddedB| be a [=list/clone=] of |shapeB|.
5823
5817
1. While |paddedB|'s [=list/size=] is less than |outputSize|, [=list/prepend=] 1 to |paddedB|.
5824
5818
1. Let |outputShape| be a new [=/list=].
5825
5819
1. [=list/For each=] |index| in [=the range=] 0 to |outputSize|, exclusive:
@@ -5832,7 +5826,7 @@ To <dfn data-lt="bidirectionally broadcasting the shapes">bidirectionally broadc
5832
5826
</details>
5833
5827
5834
5828
<p algorithm>
5835
-
|A| is <dfn>bidirectionally broadcastable</dfn> to |B| if [=bidirectionally broadcasting the shapes=] |A| and |B| does not result in failure.
5829
+
|shapeA| is <dfn>bidirectionally broadcastable</dfn> to |shapeB| if [=bidirectionally broadcasting the shapes=] |shapeA| and |shapeB| does not result in failure.
0 commit comments