Skip to content

Commit ec64348

Browse files
authored
Merge pull request #707 from inexorabletash/style-punctuate-steps
Style: Ensure algorithm steps end in '.' or ':'
2 parents 74b9831 + c337d90 commit ec64348

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

index.bs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,11 @@ The <dfn dfn-for=MLContextOptions dfn-type=dict-member>powerPreference</dfn> opt
750750
To <dfn>create a context</dfn> given [=realm=] |realm| and |options| (a {{GPUDevice}} or {{MLContextOptions}}), run these steps:
751751
</summary>
752752
1. Let |context| be a new {{MLContext}} object with |realm|.
753-
1. If |options| is a {{GPUDevice}} object,
753+
1. If |options| is a {{GPUDevice}} object:
754754
1. Set |context|.{{MLContext/[[contextType]]}} to "[=context type/webgpu=]".
755755
1. Set |context|.{{MLContext/[[deviceType]]}} to {{MLDeviceType/"gpu"}}.
756756
1. Set |context|.{{MLContext/[[powerPreference]]}} to {{MLPowerPreference/"default"}}.
757-
1. Otherwise,
757+
1. Otherwise:
758758
1. Set |context|.{{MLContext/[[contextType]]}} to "[=context type/default=]".
759759
1. If |options|["{{MLContextOptions/deviceType}}"] [=map/exists=], then set |context|.{{MLContext/[[deviceType]]}} to |options|["{{MLContextOptions/deviceType}}"]. Otherwise, set |context|.{{MLContext/[[deviceType]]}} to {{MLDeviceType/"cpu"}}.
760760
1. If |options|["{{MLContextOptions/powerPreference}}"] [=map/exists=], then set |context|.{{MLContext/[[powerPreference]]}} to |options|["{{MLContextOptions/powerPreference}}"]. Otherwise, set |context|.{{MLContext/[[powerPreference]]}} to {{MLPowerPreference/"default"}}.
@@ -2106,7 +2106,7 @@ partial interface MLGraphBuilder {
21062106
1. Let |filterInputChannels| be |filterShape|[3].
21072107
</dl>
21082108
1. If |inputChannels| is not equal to |filterInputChannels|, then [=exception/throw=] a {{TypeError}}.
2109-
1. Let |outputChannels| be |filterOutputChannels| * |options|.{{MLConvTranspose2dOptions/groups}}
2109+
1. Let |outputChannels| be |filterOutputChannels| * |options|.{{MLConvTranspose2dOptions/groups}}.
21102110
1. If |options|.{{MLConvTranspose2dOptions/bias}} [=map/exists=]:
21112111
1. If its [=MLOperand/shape=] is not equal to « |outputChannels| », then [=exception/throw=] a {{TypeError}}.
21122112
1. If its [=MLOperand/dataType=] is not equal to |input|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
@@ -3234,8 +3234,8 @@ partial interface MLGraphBuilder {
32343234
1. If |options|.{{MLGruCellOptions/activations}} [=map/exists=], and [=MLGraphBuilder/validating activation=] with [=this=] and any [=list/item=] in it returns false, then [=exception/throw=] a {{TypeError}}.
32353235
1. If |input|'s [=MLOperand/dataType=] is not {{MLOperandDataType/"float32"}} or {{MLOperandDataType/"float16"}}, then [=exception/throw=] a {{TypeError}}.
32363236
1. If |input|'s [=MLOperand/rank=] is not 2, then [=exception/throw=] a {{TypeError}}.
3237-
1. Let |batchSize| be |input|'s [=MLOperand/shape=][0];
3238-
1. Let |inputSize| be |input|'s [=MLOperand/shape=][1];
3237+
1. Let |batchSize| be |input|'s [=MLOperand/shape=][0].
3238+
1. Let |inputSize| be |input|'s [=MLOperand/shape=][1].
32393239
1. If the [=MLOperand/dataType=] of any of |weight|, |recurrentWeight|, or |hiddenState| is not equal to |input|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
32403240
1. If |weight|'s [=MLOperand/shape=] is not equal to « 3 * |hiddenSize|, |inputSize| », then [=exception/throw=] a {{TypeError}}.
32413241
1. If |recurrentWeight|'s [=MLOperand/shape=] is not equal to « 3 * |hiddenSize|, |hiddenSize| », then [=exception/throw=] a {{TypeError}}.
@@ -4410,9 +4410,9 @@ partial interface MLGraphBuilder {
44104410
<summary>
44114411
To <dfn dfn-for=MLGraphBuilder>calculate matmul output sizes</dfn>, given {{MLOperand}} |a| and {{MLOperand}} |b| run the following steps:
44124412
</summary>
4413-
1. Let |shapeA| be a [=list/clone=] of |a|'s [=MLOperand/shape=]
4413+
1. Let |shapeA| be a [=list/clone=] of |a|'s [=MLOperand/shape=].
44144414
1. Let |rankA| be |a|'s [=MLOperand/rank=].
4415-
1. Let |shapeB| be a [=list/clone=] of |b|'s [=MLOperand/shape=]
4415+
1. Let |shapeB| be a [=list/clone=] of |b|'s [=MLOperand/shape=].
44164416
1. Let |rankB| be |b|'s [=MLOperand/rank=].
44174417
1. If either |rankA| or |rankB| is less than 2, then [=exception/throw=] a {{TypeError}}.
44184418
1. Let |colsA| be |shapeA|[|rankA| - 1].
@@ -4509,7 +4509,7 @@ partial interface MLGraphBuilder {
45094509
The <dfn method for=MLGraphBuilder>pad(|input|, |beginningPadding|, |endingPadding|, |options|)</dfn> method steps are:
45104510
</summary>
45114511
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}.
4512-
1. If |input|'s [=MLOperand/rank=] is 0, then [=exception/throw=] a {{TypeError}}
4512+
1. If |input|'s [=MLOperand/rank=] is 0, then [=exception/throw=] a {{TypeError}}.
45134513
1. If |beginningPadding|'s [=list/size=] and |endingPadding|'s [=list/size=] are not both equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}.
45144514
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}.
45154515
1. Let |outputShape| be the result of [=MLGraphBuilder/calculating padding output sizes=] given |input|, |beginningPadding| and |endingPadding|.
@@ -4692,7 +4692,7 @@ partial interface MLGraphBuilder {
46924692
1. Let |outputSizes| be the result of [=MLGraphBuilder/calculating conv2d output sizes=] given |inputHeight|, |inputWidth|, |windowDimensions|[0], |windowDimensions|[1], |padding|, |strides|, and |dilations|.
46934693
1. Let |outputHeight| be |outputSizes|[0].
46944694
1. Let |outputWidth| be |outputSizes|[1].
4695-
1. Switch on |roundingType|
4695+
1. Switch on |roundingType|:
46964696
<dl class=switch>
46974697
: {{MLRoundingType/"floor"}}
46984698
::
@@ -4965,7 +4965,7 @@ partial interface MLGraphBuilder {
49654965

49664966
<div algorithm>
49674967
The <dfn method for=MLGraphBuilder>reduceMean(|input|, |options|)</dfn> method steps are:
4968-
1. Let |output| be the result of running the [=MLGraphBuilder/reduce-op | create reduce operation=] given "reduceMean", |input|, |options|, and « {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}} »
4968+
1. Let |output| be the result of running the [=MLGraphBuilder/reduce-op | create reduce operation=] given "reduceMean", |input|, |options|, and « {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}} ».
49694969
1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error.
49704970
1. Return |output|.
49714971
</div>

tools/lint.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,20 @@ for (const pre of root.querySelectorAll('pre.highlight:not(.idl)')) {
257257
}
258258
}
259259

260+
// Ensure algorithm steps end in '.' or ':'.
261+
for (const match of source.matchAll(/^ *\d+\. .*$/mg)) {
262+
let str = match[0].trim();
263+
264+
// Strip asterisks from things like "1. *Make graph connections.*"
265+
const match2 = str.match(/^(\d+\. )\*(.*)\*$/);
266+
if (match2) {
267+
str = match2[1] + match2[2];
268+
}
269+
270+
const match3 = str.match(/[^.:]$/);
271+
if (match3) {
272+
error(`Algorithm steps should end with '.' or ':': ${format(match3)}`);
273+
}
274+
}
275+
260276
globalThis.process.exit(exitCode);

0 commit comments

Comments
 (0)