Skip to content

Commit 5d157b4

Browse files
authored
Add isNaN and isInfinite operators (#858)
* Add isNaN and isInfinite operators * Typo numberic * Fix missing semicolon after function prototype * Fix support limits type for unary isNan and isInfinite * Ningxin's feedback about data type restriction
1 parent 994122f commit 5d157b4

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

index.bs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,6 +3544,8 @@ partial interface MLGraphBuilder {
35443544
MLOperand logicalXor(MLOperand a,
35453545
MLOperand b,
35463546
optional MLOperatorOptions options = {});
3547+
MLOperand isNaN(MLOperand a, optional MLOperatorOptions options = {});
3548+
MLOperand isInfinite(MLOperand a, optional MLOperatorOptions options = {});
35473549
};
35483550

35493551
dictionary MLLogicalNotSupportLimits {
@@ -3562,10 +3564,12 @@ partial dictionary MLOpSupportLimits {
35623564
MLBinarySupportLimits logicalAnd;
35633565
MLBinarySupportLimits logicalOr;
35643566
MLBinarySupportLimits logicalXor;
3567+
MLLogicalNotSupportLimits isNaN;
3568+
MLLogicalNotSupportLimits isInfinite;
35653569
};
35663570
</script>
35673571

3568-
<div dfn-for="MLGraphBuilder/equal(a, b, options), MLGraphBuilder/notEqual(a, b, options), MLGraphBuilder/greater(a, b, options), MLGraphBuilder/greaterOrEqual(a, b, options), MLGraphBuilder/lesser(a, b, options), MLGraphBuilder/lesserOrEqual(a, b, options), MLGraphBuilder/logicalNot(a, options), MLGraphBuilder/logicalAnd(a, b, options), MLGraphBuilder/logicalOr(a, b, options), MLGraphBuilder/logicalXor(a, b, options)" dfn-type=argument>
3572+
<div dfn-for="MLGraphBuilder/equal(a, b, options), MLGraphBuilder/notEqual(a, b, options), MLGraphBuilder/greater(a, b, options), MLGraphBuilder/greaterOrEqual(a, b, options), MLGraphBuilder/lesser(a, b, options), MLGraphBuilder/lesserOrEqual(a, b, options), MLGraphBuilder/logicalNot(a, options), MLGraphBuilder/logicalAnd(a, b, options), MLGraphBuilder/logicalOr(a, b, options), MLGraphBuilder/logicalXor(a, b, options), MLGraphBuilder/isNaN(a, options), MLGraphBuilder/isInfinite(a, options)" dfn-type=argument>
35693573
**Arguments:**
35703574
- <dfn>a</dfn>: an {{MLOperand}}. The first input tensor.
35713575
- <dfn>b</dfn>: an {{MLOperand}}. The second input tensor when specified.
@@ -3574,7 +3578,7 @@ partial dictionary MLOpSupportLimits {
35743578
**Returns:** an {{MLOperand}}. The output tensor that contains the result of element-wise comparison of the two input tensors.
35753579
</div>
35763580

3577-
<table id=constraints-elementwise-logical class='data' link-for="MLGraphBuilder/equal(a, b, options), MLGraphBuilder/notEqual(a, b, options), MLGraphBuilder/greater(a, b, options), MLGraphBuilder/greaterOrEqual(a, b, options), MLGraphBuilder/lesser(a, b, options), MLGraphBuilder/lesserOrEqual(a, b, options), MLGraphBuilder/logicalNot(a, options), MLGraphBuilder/logicalAnd(a, b, options), MLGraphBuilder/logicalOr(a, b, options), MLGraphBuilder/logicalXor(a, b, options)">
3581+
<table id=constraints-elementwise-logical class='data' link-for="MLGraphBuilder/equal(a, b, options), MLGraphBuilder/notEqual(a, b, options), MLGraphBuilder/greater(a, b, options), MLGraphBuilder/greaterOrEqual(a, b, options), MLGraphBuilder/lesser(a, b, options), MLGraphBuilder/lesserOrEqual(a, b, options), MLGraphBuilder/logicalNot(a, options), MLGraphBuilder/logicalAnd(a, b, options), MLGraphBuilder/logicalOr(a, b, options), MLGraphBuilder/logicalXor(a, b, options), MLGraphBuilder/isNaN(a, options), MLGraphBuilder/isInfinite(a, options)">
35783582
<caption>Constraints for element-wise logical options</caption>
35793583
<thead>
35803584
<tr>
@@ -3631,6 +3635,10 @@ partial dictionary MLOpSupportLimits {
36313635
:: Support limits for operator {{MLGraphBuilder/logicalOr()}}.
36323636
: <dfn>logicalXor</dfn>
36333637
:: Support limits for operator {{MLGraphBuilder/logicalXor()}}.
3638+
: <dfn>isNaN</dfn>
3639+
:: Support limits for operator {{MLGraphBuilder/isNaN()}}.
3640+
: <dfn>isInfinite</dfn>
3641+
:: Support limits for operator {{MLGraphBuilder/isInfinite()}}.
36343642
</dl>
36353643

36363644
<div>
@@ -3645,6 +3653,8 @@ partial dictionary MLOpSupportLimits {
36453653
- *logicalAnd*: Compute the logical *and* of the two input tensors, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
36463654
- *logicalOr*: Compute the logical *or* of the two input tensors, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
36473655
- *logicalXor*: Compute the logical *xor* of the two input tensors, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
3656+
- *isNaN*: Check if the values of the input tensor are invalid numeric representations (NaN's), element-wise, returning 1's for NaN's and 0 otherwise.
3657+
- *isInfinite*: Check if the values of the input tensor are infinite, element-wise, returning 1's for positive or negative infinity and 0 otherwise.
36483658
</div>
36493659

36503660
<div class="note">
@@ -3655,11 +3665,13 @@ Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/les
36553665
<summary>
36563666
To <dfn for="MLGraphBuilder" data-lt="element-wise-logical-op">create an element-wise logical operation</dfn> given [=string=] |op|, {{MLOperand}} |a|, an optional {{MLOperand}} |b|, and {{MLOperatorOptions}} |options|, run the following steps:
36573667
</summary>
3658-
1. [=Assert=]: |op| is one of "equal", "notEqual", "greater", "greaterOrEqual", "lesser", "lesserOrEqual", "logicalNot", "logicalAnd", "logicalOr", "logicalXor".
3668+
1. [=Assert=]: |op| is one of "equal", "notEqual", "greater", "greaterOrEqual", "lesser", "lesserOrEqual", "logicalNot", "logicalAnd", "logicalOr", "logicalXor", "isNaN", "isInfinite".
36593669
1. If [=this=] [=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
36603670
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |a| returns false, then [=exception/throw=] a {{TypeError}}.
36613671
1. If |op| is one of "logicalNot", "logicalAnd", "logicalOr", "logicalXor", then:
36623672
1. If |a|'s [=MLOperand/dataType=] is not {{MLOperandDataType/"uint8"}}, then [=exception/throw=] a {{TypeError}}.
3673+
1. If |op| is one of "isNaN", "isInfinite", then:
3674+
1. If |a|'s [=MLOperand/dataType=] is not one of « {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}} », then [=exception/throw=] a {{TypeError}}.
36633675
1. If |b| is passed, then:
36643676
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |b| returns false, then [=exception/throw=] a {{TypeError}}.
36653677
1. If |a|'s [=MLOperand/dataType=] is not equal to |b|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
@@ -3749,6 +3761,20 @@ Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/les
37493761
1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error.
37503762
1. Return |output|.
37513763
</div>
3764+
3765+
<div algorithm>
3766+
The <dfn method for=MLGraphBuilder>isNaN(|a|, |options|)</dfn> method steps are:
3767+
1. Let |output| be the result of [=MLGraphBuilder/element-wise-logical-op|creating an element-wise logical operation=] given "isNaN", |a|, and |options|.
3768+
1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error.
3769+
1. Return |output|.
3770+
</div>
3771+
3772+
<div algorithm>
3773+
The <dfn method for=MLGraphBuilder>isInfinite(|a|, |options|)</dfn> method steps are:
3774+
1. Let |output| be the result of [=MLGraphBuilder/element-wise-logical-op|creating an element-wise logical operation=] given "isInfinite", |a|, and |options|.
3775+
1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error.
3776+
1. Return |output|.
3777+
</div>
37523778
</details>
37533779

37543780
### Element-wise unary operations ### {#api-mlgraphbuilder-unary}

0 commit comments

Comments
 (0)