Skip to content

Commit 6e99b01

Browse files
inexorabletashfdwr
andauthored
Bug fix: Fix MLGraphBuilder.input()'s handling of scalars (#575)
* Bug fix: Fix MLGraphBuilder.input()'s handling of scalars. Fixes #502 MLOperandDescriptor was updated in c320472 to always have dimensions, defaulted to an empty list for scalars. That makes the current prose for input() incorrect. Issue #502 already tracked correcting it, so let's simplify - just change the logic for "is a scalar?" and drop the bogus assert. * Remove conditional and fix check dimensions to allow 0 * Factor byte length check into checking dimensions * Oops, this should go too. * type -> dataType * (1) simplify (2) move into MLOperandDescriptor (3) link to #456 * Restore dimension check and reorder byte length to last * Fix build for missing dimensions --------- Co-authored-by: Dwayne Robinson <[email protected]>
1 parent 4ad9a63 commit 6e99b01

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

index.bs

+21-19
Original file line numberDiff line numberDiff line change
@@ -1604,8 +1604,7 @@ Create a constant {{MLOperand}} of the specified data type and shape that contai
16041604
<div class="note">
16051605
The permissions and context validity have been checked by [[#api-mlgraphbuilder-constructor]] steps.
16061606
</div>
1607-
1. If |descriptor|'s [=byte length=] is not supported by the underlying platform, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
1608-
1. If the [=checking dimensions=] given |descriptor|.{{MLOperandDescriptor/dataType}} and |descriptor|.{{MLOperandDescriptor/dimensions}} returns false, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
1607+
1. If [=checking dimensions=] given |descriptor| returns false, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
16091608
1. If [=validating buffer with descriptor=] given |bufferView| and |descriptor| returns false, then [=exception/throw=] a {{TypeError}}.
16101609
1. If any of the following sub-steps fail, [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
16111610
1. Let |operand| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|.
@@ -3318,10 +3317,7 @@ Create a named {{MLOperand}} based on a descriptor, that can be used as an input
33183317
The permissions and context validity have been checked by [[#api-mlgraphbuilder-constructor]] steps.
33193318
</div>
33203319
1. If |name| is empty, then [=exception/throw=] a {{TypeError}}.
3321-
1. [=Assert=]: If |descriptor|.{{MLOperandDescriptor/dimensions}} does not [=map/exist=], then |descriptor| defines a scalar input.
3322-
1. If |descriptor|.{{MLOperandDescriptor/dimensions}} [=map/exists=]:
3323-
1. If [=checking dimensions=] given |descriptor|.{{MLOperandDescriptor/dataType}} and |descriptor|.{{MLOperandDescriptor/dimensions}} returns false, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3324-
1. If |descriptor|'s [=byte length=] is not supported by the underlying platform, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3320+
1. If [=checking dimensions=] given |descriptor| returns false, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
33253321
1. If any of the following sub-steps fail, [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
33263322
1. Let |operand| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|.
33273323
1. Set |operand|.{{MLOperand/[[name]]}} to |name|.
@@ -5781,26 +5777,14 @@ The {{MLOperand}} objects are created by the methods of {{MLGraphBuilder}}, inte
57815777
</div>
57825778
</details>
57835779

5784-
<details open algorithm>
5785-
<summary>
5786-
To <dfn>check dimensions</dfn> given [=/list=] |dimensions| and {{MLOperandDataType}} |type|, run the following steps:
5787-
</summary>
5788-
<div class=algorithm-steps>
5789-
1. If |dimensions|'s [=list/size=] is 0, return false.
5790-
1. If |dimensions|'s [=list/size=] is too large to be supported by the implementation, return false.
5791-
1. If any element of |dimensions| is not a positive number, or it is too large to be supported by the implementation given |type|, return false.
5792-
1. Return true.
5793-
</div>
5794-
</details>
5795-
57965780
<details open algorithm>
57975781
<summary>
57985782
To <dfn for="MLOperand">validate MLOperand</dfn> given {{MLOperand}} |operand| and {{MLGraphBuilder}} |builder|, run the following steps:
57995783
</summary>
58005784
<div class=algorithm-steps>
58015785
1. If |builder| is not equal to |operand|.{{MLOperand/[[builder]]}}, return false.
58025786
1. Let |desc| be |operand|.{{MLOperand/[[descriptor]]}}.
5803-
1. If [=checking dimensions=] given |desc|.{{MLOperandDescriptor/dimensions}} and |desc|.{{MLOperandDescriptor/dataType}} returns false, then return false.
5787+
1. If [=checking dimensions=] given |desc| returns false, then return false.
58045788
1. Return true.
58055789
</div>
58065790
</details>
@@ -5889,6 +5873,24 @@ dictionary MLOperandDescriptor {
58895873
</div>
58905874
</details>
58915875

5876+
<details open algorithm>
5877+
<summary>
5878+
To <dfn for="MLOperandDescriptor">check dimensions</dfn> given {{MLOperandDescriptor}} |descriptor|, run the following steps:
5879+
</summary>
5880+
<div class=algorithm-steps>
5881+
1. If any element of |descriptor|.{{MLOperandDescriptor/dimensions}} is too large to be supported by the implementation, return false.
5882+
1. If |descriptor|.{{MLOperandDescriptor/dimensions}}'s [=list/size=] is too large to be supported by the implementation, return false.
5883+
5884+
Issue(456): The maximum number of operand dimensions is not defined, but native ML APIs usually have a maximum supported size.
5885+
5886+
1. If |descriptor|'s [=byte length=] is not supported by the implementation, then return false.
5887+
1. Return true.
5888+
</div>
5889+
5890+
5891+
</details>
5892+
5893+
58925894
Algorithms {#algorithms}
58935895
=====================
58945896

0 commit comments

Comments
 (0)