Skip to content

Commit c320472

Browse files
authored
Fix dimensions for 0D scalars (#476)
* Fix dimensions for 0D scalars * Code review comments * reshape CR feedback * More CR feedback * Minor cleanup * Fix bikeshed validation on LSTM tensor names * Fix reshape bad merge * Unbracket MLCommandEncoder in status text to appease bikeshed * CR feedback * Fix empty reshape dimensions to 1, not 0
1 parent 55183f7 commit c320472

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

index.bs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,10 +1815,7 @@ Data truncation will occur when the specified value exceeds the range of the spe
18151815
</div>
18161816
1. Let |descriptor| be a new {{MLOperandDescriptor}}.
18171817
1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |type|.
1818-
1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to `undefined`.
1819-
<div class="note">
1820-
In the case of a scalar constant, |descriptor|.{{MLOperandDescriptor/dimensions}} is ignored.
1821-
</div>
1818+
1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to an empty [=/list=].
18221819
1. If any of the following sub-steps fail, [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
18231820
1. Let |operand| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|.
18241821
1. Make a request to the underlying platform to:
@@ -3995,9 +3992,7 @@ partial interface MLGraphBuilder {
39953992
</summary>
39963993
<div class=algorithm-steps>
39973994
1. Let |numDirections| be 1 if |options|.{{MLLstmOptions/direction}} is {{MLRecurrentNetworkDirection/"forward"}}, or otherwise let it be 2.
3998-
<div class="issue">
3999-
The shape of |input|, |weight| or |recurrentWeight| could be also checked here.
4000-
</div>
3995+
1. If the [=rank=] of |input| or |weight| or |recurrentWeight| is not 3, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
40013996
1. If |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}[0] is not equal to |steps|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
40023997
1. Let |batchSize| be |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}[1].
40033998
1. If |options|.{{MLLstmOptions/bias}} [=map/exists=]:
@@ -5120,12 +5115,10 @@ partial interface MLGraphBuilder {
51205115
</summary>
51215116
<div class=algorithm-steps>
51225117
1. Let |outputShape| be an empty array of {{unsigned long}}.
5123-
1. If |newShape| is a scalar [=number=], set |outputShape| to the [=/list=] « 1 ».
5124-
1. Otherwise, if |newShape| is an array of {{unsigned long}}:
5125-
1. If the [=list/size=] of |newShape| is 0, set |outputShape| to the [=/list=] « 1 » (reshaping to scalar).
5126-
1. If any value in |newShape| is 0, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
5127-
1. Let |inputElementCount| be the product of all elements in |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
5128-
1. If product of all values in |newShape| is not equal to |inputElementCount|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
5118+
1. If the [=list/size=] of |newShape| is 0, set |outputShape| to an empty [=/list=] for a scalar.
5119+
1. If any value in |newShape| is 0, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
5120+
1. Let |inputElementCount| be the product of all elements in |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. Empty dimensions yield an |inputElementCount| of 1.
5121+
1. If product of all values in |newShape| is not equal to |inputElementCount|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
51295122
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}.
51305123
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |newShape|.
51315124
1. If any of the following sub-steps fail, [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
@@ -5997,7 +5990,7 @@ The {{MLOperand}} objects are created by the methods of {{MLGraphBuilder}}, inte
59975990
<div class=algorithm-steps>
59985991
1. If |builder| is not equal to |operand|.{{MLOperand/[[builder]]}}, return false.
59995992
1. Let |desc| be |operand|.{{MLOperand/[[descriptor]]}}.
6000-
1. If |desc|.{{MLOperandDescriptor/dimensions}} [=map/exists=] and [=checking dimensions=] given |desc|.{{MLOperandDescriptor/dimensions}} and |desc|.{{MLOperandDescriptor/dataType}} returns false, then return false.
5993+
1. If [=checking dimensions=] given |desc|.{{MLOperandDescriptor/dimensions}} and |desc|.{{MLOperandDescriptor/dataType}} returns false, then return false.
60015994
1. Return true.
60025995
</div>
60035996
</details>
@@ -6069,7 +6062,7 @@ dictionary MLOperandDescriptor {
60696062
required MLOperandDataType dataType;
60706063

60716064
// The dimensions field is only required for tensor operands.
6072-
sequence<unsigned long> dimensions;
6065+
sequence<unsigned long> dimensions = [];
60736066
};
60746067
</script>
60756068

0 commit comments

Comments
 (0)