Skip to content

Commit c050f31

Browse files
Bug fix: Correct linking for list/range iterations (#527)
Some uses of "for each" in algorithms were linking to the map iteration definition in Infra. Fix this to point at the list iteration definition. Today I learned: this applies to iteration over ranges too! Also updated coding conventions to cover these cases.
1 parent 56cab5d commit c050f31

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

SpecCodingConventions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Example:
8989
* Use the most specific types possible (e.g. MLOperand, not generic object).
9090
* Use `[=this=]` to refer to the current object.
9191
* Use `[=map/For each=] |key| → |value| of |map|` when iterating over a map, but use more specific terms for the key and value (e.g. _For each name → input of inputs:_)
92+
* Use `[=list/For each=] |item| of |list|` when iterating over a list, but use more specific terms for the item (e.g. _For each dimension of dimensions:_)
93+
* Use `[=list/For each=] |index| in [=the range=] X to Y, inclusive` when iterating over a numeric range; a range is implicitly an ordered set which is a type of list. Specify _inclusive_ or _exclusive_ regarding the upper bound, for clarity.
9294
* Use "let" to introduce a variable and "set" to update a variable or assign to a property.
9395
* Use « » notation for literal lists, which helps make it clear that they are not JavaScript arrays.
9496

index.bs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,11 +1878,11 @@ partial interface MLGraphBuilder {
18781878
1. Let |desc| be |inputs|[0].{{MLOperand/[[descriptor]]}}.
18791879
1. If |axis| is greater than or equal to the [=rank=] of |desc|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
18801880
1. Set |desc|.{{MLOperandDescriptor/dimensions}}[|axis|] to 0.
1881-
1. [=map/For each=] |index| in [=the range=] 0 to the [=rank=] of |inputs|, exclusive:
1881+
1. [=list/For each=] |index| in [=the range=] 0 to the [=rank=] of |inputs|, exclusive:
18821882
1. Let |input| be |inputs|[|index|].
18831883
1. If [=validating MLOperand=] given |input| and [=this=] returns false, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
18841884
1. If |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dataType}} is not equal to |inputs|[0].{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dataType}}, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
1885-
1. [=map/For each=] |dim| in [=the range=] 0 to the [=rank=] of |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}, exclusive:
1885+
1. [=list/For each=] |dim| in [=the range=] 0 to the [=rank=] of |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}, exclusive:
18861886
<div class="note">
18871887
If the shape of each corresponding dimension and type of the operands, except for those of the dimension given by |axis|, is not the same, fail.
18881888
</div>
@@ -2007,7 +2007,7 @@ Data truncation will occur when the values in the range exceed the range of the
20072007
1. Make a request to the underlying platform to:
20082008
1. Create an [=implementation-defined=] platform memory buffer the size of |size| multiplied by sizeof(|descriptor|.{{MLOperandDescriptor/dataType}}).
20092009
2. Store the beginning address to that memory buffer as a pointer |buffer| of the corresponding data type.
2010-
1. [=map/For each=] |index| in [=the range=] 0 to |size|, exclusive:
2010+
1. [=list/For each=] |index| in [=the range=] 0 to |size|, exclusive:
20112011
1. Set |buffer|[|index|] to |start| + (|index| * |step|).
20122012
1. Make a request to the underlying platform to:
20132013
1. Create an [=implementation-defined=] platform operand |constantImpl| to represent a constant operand, given |descriptor|.
@@ -2878,7 +2878,7 @@ partial interface MLGraphBuilder {
28782878
1. Let |inputDesc| be |input|.{{MLOperand/[[descriptor]]}}.
28792879
1. If the sequence length of |newShape| is not equal to the [=rank=] of |inputDesc|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
28802880
1. Let |outputDesc| be a copy of |inputDesc|.
2881-
1. [=map/For each=] |index| in [=the range=] 0 to the [=rank=] of |input|, exclusive:
2881+
1. [=list/For each=] |index| in [=the range=] 0 to the [=rank=] of |input|, exclusive:
28822882
1. Let |size| be the |input|.{{MLOperand/shape()}}[|index|].
28832883
1. If |size| is not equal to 1 and not equal to |newShape|[index], then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
28842884
1. If |size| is equal to 1, then let |outputDesc|.{{MLOperandDescriptor/dimensions}}[|index|] be |newShape|[|index|].
@@ -3845,7 +3845,7 @@ The {{MLLayerNormalizationOptions}} members are:
38453845
<div class=algorithm-steps>
38463846
1. If the [=rank=] of |options|.{{MLLayerNormalizationOptions/scale}} is not equal to the [=list/size=] of |options|.{{MLLayerNormalizationOptions/axes}}, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
38473847
1. If the [=rank=] of |options|.{{MLLayerNormalizationOptions/bias}} is not equal to the [=list/size=] of |options|.{{MLLayerNormalizationOptions/axes}}, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3848-
1. [=map/For each=] |index| in [=the range=] 0 to the [=list/size=] of |options|.{{MLLayerNormalizationOptions/axes}}, exclusive:
3848+
1. [=list/For each=] |index| in [=the range=] 0 to the [=list/size=] of |options|.{{MLLayerNormalizationOptions/axes}}, exclusive:
38493849
1. Let |axis| be |options|.{{MLLayerNormalizationOptions/axes}}[|index|].
38503850
1. If |axis| is greater or equal to the [=list/size=] of |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
38513851
1. Let |size| be |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}[|axis|].
@@ -4548,7 +4548,7 @@ partial interface MLGraphBuilder {
45484548
1. If |sizeB| is 1 and |sizeA| is not, then append 1 to |shapeB| to become [ |shapeB| | 1 ] and let |sizeB| be 2.
45494549
1. If |shapeA|[|sizeA| - 1] is not equal to |shapeB|[0], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
45504550
1. Let |shape| be an array whose size |size| is the maximum of |sizeA| and |sizeB|.
4551-
1. [=map/For each=] |index| in [=the range=] 0 to |size|, exclusive:
4551+
1. [=list/For each=] |index| in [=the range=] 0 to |size|, exclusive:
45524552
1. Set |shape|[|index|] to the maximum of |shapeA|[|index|] and |shapeB|[|index|].
45534553
1. Return |shape|.
45544554
</div>
@@ -6252,7 +6252,7 @@ dictionary MLOperandDescriptor {
62526252
</summary>
62536253
<div class=algorithm-steps>
62546254
1. Let |elementLength| be 1.
6255-
1. [=map/For each=] |dimension| of |desc|.{{MLOperandDescriptor/dimensions}}:
6255+
1. [=list/For each=] |dimension| of |desc|.{{MLOperandDescriptor/dimensions}}:
62566256
1. Set |elementLength| to |elementLength| × |dimension|.
62576257
1. Let |elementSize| be the [=element size=] of one of the {{ArrayBufferView}} types that matches |desc|.{{MLOperandDescriptor/dataType}} according to [this table](#appendices-mloperanddatatype-arraybufferview-compatibility).
62586258
1. Return |elementLength| × |elementSize|.

0 commit comments

Comments
 (0)