diff --git a/index.bs b/index.bs index 6e3a9342..b3ec9d12 100644 --- a/index.bs +++ b/index.bs @@ -1042,7 +1042,7 @@ Note: `dispatch()` itself provides no signal that graph execution has completed. 'C': outputTensorC }; context.dispatch(graph, inputs, outputs); - + // 6. Read back the computed result. const result = await context.readTensor(outputTensorC); console.log('Output value:', new Float32Array(result)); // [1, 1, 1, 1] @@ -2919,6 +2919,94 @@ partial dictionary MLOpSupportLimits { 1. Return |output|. + +### cumulativeSum ### {#api-mlgraphbuilder-cumulativesum} +Compute the accumulated sum of a series of values along the given axis, either including or excluding the current value. + + + + + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/cumulativeSum()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}[=/any data type|any=][=/any rank|N=]
*output*[=/same type as|same as=] {{input}}[=/same rank as|same as=] {{input}}
+ +{{MLCumulativeSumOptions}} has the following members: +
+ : exclusive + :: + Whether to include or exclude the current value in the output, meaning inclusive presum addition (see https://en.wikipedia.org/wiki/Prefix_sum) or exclusive post-sum addition. Given input *[1,2,3,4]*, inclusive addition would yield an output of *[1,3,6,10]* whereas exclusive would yield *[0,1,3,6]*. The default is inclusive. + + : reversed + :: + Whether to reverse the summation direction along the active axis to instead start from the high coordinate to low coordinate. Given input *[1,2,3,4]*, inclusive forward addition would yield an output of *[1,3,6,10]* whereas backward summation would yield *[10,9,7,4]*. The default is exclusive. +
+ +
+ **Arguments:** + - input: an {{MLOperand}}. The input tensor. + - axis: an {{unsigned long}} scalar. The axis the summation will be performed on. Its value must be in the range [0, N-1] where N is *input*'s [=MLOperand/rank=]. + - options: an {{MLCumulativeSumOptions}}. Specifies the optional parameters of the operation. + + **Returns:** + - an {{MLOperand}}. The output tensor of the same shape as *input*. +
+ +{{MLOpSupportLimits}} has the following member for {{MLGraphBuilder/cumulativeSum()}}: +
+ : cumulativeSum + :: Support limits for operator {{MLGraphBuilder/cumulativeSum()}}. +
+ +
+ + The cumulativeSum(|input|, |axis|, |options|) method steps are: + + 1. If [=this=] [=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. + 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. + 1. If |input|'s [=MLOperand/dataType=] is not one of its [=/allowed data types=] (according to [this table](#constraints-cumulativesum)), then [=exception/throw=] a {{TypeError}}. + 1. If |axis| is greater than or equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}. + 1. *Make graph connections:* + 1. Let |output| be the result of [=copying an MLOperand=] given |input|. + 1. Let |operator| be an [=operator=] for the "cumulativeSum" operation and |options|. + 1. Set |output|.{{MLOperand/[[operator]]}} to |operator|. + 1. Set |operator|'s [=operator/input=] to |input|. + 1. Set |operator|'s [=operator/output=] to |output|. + 1. Return |output|. +
+ + ### Element-wise binary operations ### {#api-mlgraphbuilder-binary} Compute the element-wise binary addition, subtraction, multiplication, division, power, maximum and minimum of the two input tensors. @@ -3094,6 +3182,9 @@ partial interface MLGraphBuilder { MLOperand equal(MLOperand a, MLOperand b, optional MLOperatorOptions options = {}); + MLOperand notEqual(MLOperand a, + MLOperand b, + optional MLOperatorOptions options = {}); MLOperand greater(MLOperand a, MLOperand b, optional MLOperatorOptions options = {}); @@ -3107,6 +3198,15 @@ partial interface MLGraphBuilder { MLOperand b, optional MLOperatorOptions options = {}); MLOperand logicalNot(MLOperand a, optional MLOperatorOptions options = {}); + MLOperand logicalAnd(MLOperand a, + MLOperand b, + optional MLOperatorOptions options = {}); + MLOperand logicalOr(MLOperand a, + MLOperand b, + optional MLOperatorOptions options = {}); + MLOperand logicalXor(MLOperand a, + MLOperand b, + optional MLOperatorOptions options = {}); }; dictionary MLLogicalNotSupportLimits { @@ -3116,11 +3216,15 @@ dictionary MLLogicalNotSupportLimits { partial dictionary MLOpSupportLimits { MLBinarySupportLimits equal; + MLBinarySupportLimits notEqual; MLBinarySupportLimits greater; MLBinarySupportLimits greaterOrEqual; MLBinarySupportLimits lesser; MLBinarySupportLimits lesserOrEqual; MLLogicalNotSupportLimits logicalNot; + MLLogicalNotSupportLimits logicalAnd; + MLLogicalNotSupportLimits logicalOr; + MLLogicalNotSupportLimits logicalXor; }; @@ -3172,6 +3276,8 @@ partial dictionary MLOpSupportLimits {
: equal :: Support limits for operator {{MLGraphBuilder/equal()}}. + : notEqual + :: Support limits for operator {{MLGraphBuilder/notEqual()}}. : greater :: Support limits for operator {{MLGraphBuilder/greater()}}. : greaterOrEqual @@ -3182,27 +3288,37 @@ partial dictionary MLOpSupportLimits { :: Support limits for operator {{MLGraphBuilder/lesserOrEqual()}}. : logicalNot :: Support limits for operator {{MLGraphBuilder/logicalNot()}}. + : logicalAnd + :: Support limits for operator {{MLGraphBuilder/logicalAnd()}}. + : logicalOr + :: Support limits for operator {{MLGraphBuilder/logicalOr()}}. + : logicalXor + :: Support limits for operator {{MLGraphBuilder/logicalXor()}}.
**Operation types:** - *equal*: Compare if the values of the two input tensors are equal, element-wise. + - *notEqual*: Compare if the values of the two input tensors are not equal, element-wise. - *greater*: Compare if the values of the first input tensor is greater, element-wise. - *greaterOrEqual*: Compare if the values of the first input tensor is greater or equal, element-wise. - *lesser*: Compare if the values of the first input tensor is lesser, element-wise. - *lesserOrEqual*: Compare if the values of the first input tensor is lesser or equal, element-wise. - *logicalNot*: Invert the values of the input tensor to values 0 or 1, element-wise. Specifically, when the input value is non-zero, invert it to 0. Conversely, for a zero input value, invert it to 1. + - *logicalAnd*: Compute the logical *and* operator, element-wise, treating any non-zero value as true and returning elements of 0 or 1. + - *logicalOr*: Compute the logical *or* operator, element-wise, treating any non-zero value as true and returning elements of 0 or 1. + - *logicalXor*: Compute the logical *xor* operator, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
-Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/lesserOrEqual()}} can each be implemented in terms of operations {{MLGraphBuilder/logicalNot()}}, {{MLGraphBuilder/lesser()}}, and {{MLGraphBuilder/greater()}} in other words `builder.greaterOrEqual(a, b)` is `builder.logicalNot(builder.lesser(a, b))`, they are specifically defined to handle NaN cases and for performance reason to avoid double comparisons. +Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/lesserOrEqual()}} can each be implemented in terms of operations {{MLGraphBuilder/logicalNot()}}, {{MLGraphBuilder/lesser()}}, and {{MLGraphBuilder/greater()}} (in other words `builder.greaterOrEqual(a, b)` is `builder.logicalNot(builder.lesser(a, b))`), they are specifically defined to handle NaN cases and for performance reason to avoid double comparisons.
To create element-wise logical operation given [=string=] |op|, {{MLOperand}} |a|, an optional {{MLOperand}} |b|, and {{MLOperatorOptions}} |options|, run the following steps: - 1. [=Assert=]: |op| is one of "equal", "greater", "greaterOrEqual", "lesser", "lesserOrEqual", "logicalNot". + 1. [=Assert=]: |op| is one of "equal", "notEqual", "greater", "greaterOrEqual", "lesser", "lesserOrEqual", "logicalNot", "logicalAnd", "logicalOr", "logicalXor". 1. If [=this=] [=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. 1. If |op| is "logicalNot": 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |a| returns false, then [=exception/throw=] a {{TypeError}}. @@ -3233,6 +3349,12 @@ Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/les 1. Return |output|. + The notEqual(|a|, |b|, |options|) method steps are: + 1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-logical-op | create element-wise logical operation=] given "notEqual", |a|, |b|, and |options|. + 1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error. + 1. Return |output|. + +
The greater(|a|, |b|, |options|) method steps are: 1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-logical-op | create element-wise logical operation=] given "greater", |a|, |b|, and |options|. @@ -3267,6 +3389,27 @@ Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/les 1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error. 1. Return |output|.
+ +
+ The logicalAnd(|a|, |b|, |options|) method steps are: + 1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-logical-op | create element-wise logical operation=] given "logicalAnd", |a|, |b|, and |options|. + 1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error. + 1. Return |output|. +
+ +
+ The logicalOr(|a|, |b|, |options|) method steps are: + 1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-logical-op | create element-wise logical operation=] given "logicalOr", |a|, |b|, and |options|. + 1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error. + 1. Return |output|. +
+ +
+ The logicalXor(|a|, |b|, |options|) method steps are: + 1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-logical-op | create element-wise logical operation=] given "logicalXor", |a|, |b|, and |options|. + 1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error. + 1. Return |output|. +
### Element-wise unary operations ### {#api-mlgraphbuilder-unary} @@ -3284,6 +3427,7 @@ partial interface MLGraphBuilder { MLOperand neg(MLOperand input, optional MLOperatorOptions options = {}); MLOperand reciprocal(MLOperand input, optional MLOperatorOptions options = {}); MLOperand sin(MLOperand input, optional MLOperatorOptions options = {}); + MLOperand sign(MLOperand input, optional MLOperatorOptions options = {}); MLOperand sqrt(MLOperand input, optional MLOperatorOptions options = {}); MLOperand tan(MLOperand input, optional MLOperatorOptions options = {}); }; @@ -3300,12 +3444,13 @@ partial dictionary MLOpSupportLimits { MLSingleInputSupportLimits neg; MLSingleInputSupportLimits reciprocal; MLSingleInputSupportLimits sin; + MLSingleInputSupportLimits sign; MLSingleInputSupportLimits sqrt; MLSingleInputSupportLimits tan; }; -
+
**Arguments:** - input: an {{MLOperand}}. The input tensor. - options: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation. @@ -3315,7 +3460,7 @@ partial dictionary MLOpSupportLimits { tensor is the same as the shape of input tensor.
- +
@@ -3362,6 +3507,8 @@ partial dictionary MLOpSupportLimits { : sin :: Support limits for operator {{MLGraphBuilder/sin()}}. : sqrt + :: Support limits for operator {{MLGraphBuilder/sign()}}. + : sqrt :: Support limits for operator {{MLGraphBuilder/sqrt()}}. : tan :: Support limits for operator {{MLGraphBuilder/tan()}}. @@ -3380,6 +3527,7 @@ partial dictionary MLOpSupportLimits { - *neg*: Compute the numerical negative value of the input tensor, element-wise. - *reciprocal*: Compute the reciprocal of the input tensor, element-wise. - *sin*: Compute the sine of the input tensor, element-wise. + - *sign*: Compute the sign (-1, 0, 1) of the input tensor, element-wise, returning 1 if > 0, -1 if < 0, and 0 otherwise. - *sqrt*: Compute the square root of the input tensor, element-wise. - *tan*: Compute the tangent of the input tensor, element-wise. @@ -3388,7 +3536,7 @@ partial dictionary MLOpSupportLimits { To create element-wise unary operation given [=string=] |op|, {{MLOperand}} |input|, optional [=/list=] |allowedDataTypes|, and |options|, run the following steps: - 1. [=Assert=]: |op| is one of "abs", "ceil", "cos", "erf", "exp", "floor", "identity", "log", "neg", "reciprocal", "sin", "sqrt", "tan". + 1. [=Assert=]: |op| is one of "abs", "ceil", "cos", "erf", "exp", "floor", "identity", "log", "neg", "reciprocal", "sin", "sign", "sqrt", "tan". 1. If [=this=] [=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. 1. If |allowedDataTypes| is given and it does not [=list/contain=] |input|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. @@ -3482,6 +3630,13 @@ partial dictionary MLOpSupportLimits { 1. Return |output|. +
+ The sign(|input|, |options|) method steps are: + 1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-unary-op | create element-wise unary operation=] given "sign", |input|, signed types « {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}}, {{MLOperandDataType/"int32"}}, {{MLOperandDataType/"int8"}} », and |options|. + 1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error. + 1. Return |output|. +
+
The sqrt(|input|, |options|) method steps are: 1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-unary-op | create element-wise unary operation=] given "sqrt", |input|, « {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}} », and |options|. @@ -3497,6 +3652,241 @@ partial dictionary MLOpSupportLimits {
+
+
+ + The behavior of the {{MLGraphBuilder/sign()}} operation can be [EMULATED] + +
+    function sign(builder, input, options) {
+      const zero = builder.constant(input.dataType, 0);
+      const positiveOne = builder.constant(input.dataType, 1);
+      const negativeOne = builder.constant(input.dataType, -1);
+
+      return builder.where(
+        builder.greater(input, zero),
+        positiveOne,
+        builder.where(
+          builder.lesser(input, zero),
+          negativeOne,
+          zero));
+    }
+    
+
+
+ + +### dequantizeLinear ### {#api-mlgraphbuilder-dequantizelinear} +Dequantizes an integer tensor to floating point space using the scale and zero-point bias, where `output = (input - zeroPoint) * scale`. + +TODO: Elaborate on blockwise broadcasting - The operation will be [=broadcast=] according to [[!numpy-broadcasting-rule]]. The input tensors must be [=bidirectionally broadcastable=]. The [=MLOperand/rank=] of the output tensor is the maximum [=MLOperand/rank=] of the input tensors. For each dimension of the output tensor, its size is the maximum size along that dimension of the input tensors, and each dimension must be blockwise compatible with the output (e.g. given an input shape *[12]*, scales of the following shapes are blockwise compatible {*[1]*, *[3]*, *[4]*, *[6]*, *[12]*} as they are all multiples of the input dimensions, but a shape of *[5]* would not be). + + + +
+ **Arguments:** + - input: an {{MLOperand}}. The input tensor. + - scale: an {{MLOperand}}. The scale tensor to multiply each input value by after adjusting by the zero point. + - zeroPoint: an {{MLOperand}}. The zero point tensor to subtract from each input value. + - options: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation. + + **Returns:** an {{MLOperand}}. The output tensor that contains the dequantized values. +
+ +
Constraints for element-wise unary options
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/dequantizeLinear()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}{{MLOperandDataType/"uint4"}}, {{MLOperandDataType/"uint8"}}, {{MLOperandDataType/"uint32"}}, {{MLOperandDataType/"int32"}}N
{{scale}}{{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}}0 to {{input}}'s [=MLOperand/rank=]
{{zeroPoint}}[=/same type as|same as=] {{input}}0 to {{input}}'s [=MLOperand/rank=]
*output*[=/same type as|same as=] {{scale}}[=/same rank as|same as=] {{input}}
+ +{{MLQuantizationSupportLimits}} has the following members: +
+ : input + :: {{MLSupportLimits}} for input operand. + : scale + :: {{MLSupportLimits}} for scale operand. + : zeroPoint + :: {{MLSupportLimits}} for zeroPoint operand. + : output + :: {{MLSupportLimits}} for output operand. +
+ +{{MLOpSupportLimits}} has the following member for {{MLGraphBuilder/dequantizeLinear()}}: +
+ : dequantizeLinear + :: Support limits for operator {{MLGraphBuilder/dequantizeLinear()}}. +
+ +
+ + The dequantizeLinear(|input|, |scale|, |zeroPoint|, |options|) method steps are: + + 1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. + 1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |input|, |scale|, and |zeroPoint| returns false, then [=exception/throw=] a {{TypeError}}. + TODO: Add validation for scale and zero point shape. +
+ +
+
+ + The behavior of this operation can be [EMULATED] + +
+    TODO:
+    
+
+
+ + +### quantizeLinear ### {#api-mlgraphbuilder-quantizelinear} +Quantizes a floating point tensor to integer point space using the scale and zero-point bias, where `output = clamp(roundToNearestEvens(input / scale) + zeroPoint, 0, 255)`. + +TODO: Elaborate on blockwise broadcasting - The operation will be [=broadcast=] according to [[!numpy-broadcasting-rule]]. The input tensors must be [=bidirectionally broadcastable=]. The [=MLOperand/rank=] of the output tensor is the maximum [=MLOperand/rank=] of the input tensors. For each dimension of the output tensor, its size is the maximum size along that dimension of the input tensors, and each dimension must be blockwise compatible with the output (e.g. given an input shape *[12]*, scales of the following shapes are blockwise compatible {*[1]*, *[3]*, *[4]*, *[6]*, *[12]*} as they are all multiples of the input dimensions, but a shape of *[5]* would not be). + + + +
+ **Arguments:** + - input: an {{MLOperand}}. The condition tensor. + - scale: an {{MLOperand}}. The scale tensor to multiply each input value by after adjusting by the zero point. + - zeroPoint: an {{MLOperand}}. The zero point tensor to subtract from each input value. + - options: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation. + + **Returns:** an {{MLOperand}}. The output tensor that contains the quantized values. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/quantizeLinear()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}{{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}}N
{{scale}}[=/same type as|same as=] {{input}}0 to {{input}}'s [=MLOperand/rank=]
{{zeroPoint}}{{MLOperandDataType/"uint4"}}, {{MLOperandDataType/"uint8"}}, {{MLOperandDataType/"uint32"}}, {{MLOperandDataType/"int32"}}0 to {{input}}'s [=MLOperand/rank=]
*output*[=/same type as|same as=] {{zeroPoint}}[=/same rank as|same as=] {{input}}
+ +{{MLQuantizationSupportLimits}} has the following members: +
+ : input + :: {{MLSupportLimits}} for input operand. + : scale + :: {{MLSupportLimits}} for scale operand. + : zeroPoint + :: {{MLSupportLimits}} for zeroPoint operand. + : output + :: {{MLSupportLimits}} for output operand. +
+ +{{MLOpSupportLimits}} has the following member for {{MLGraphBuilder/quantizeLinear()}}: +
+ : quantizeLinear + :: Support limits for operator {{MLGraphBuilder/quantizeLinear()}}. +
+ + +
+ + The quantizeLinear(|input|, |scale|, |zeroPoint|, |options|) method steps are: + + 1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. + 1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |input|, |scale|, and |zeroPoint| returns false, then [=exception/throw=] a {{TypeError}}. + TODO: Add validation for scale and zero point shape. +
+ +
+
+ + The behavior of this operation can be [EMULATED] + +
+    TODO:
+    
+
+
+ + ### elu ### {#api-mlgraphbuilder-elu} Calculate the exponential linear unit function (ELU) on the input tensor element-wise. The calculation follows the expression `max(0, x) + alpha * (exp(min(0, x)) - 1)`. @@ -3840,25 +4230,191 @@ partial dictionary MLOpSupportLimits {
-### gelu ### {#api-mlgraphbuilder-gelu-method} -Compute the gaussian error linear unit function (GELU) of the input tensor. The calculation follows the expression `0.5 * x * (1 + erf(x / sqrt(2)))`. +### gatherElements ### {#api-mlgraphbuilder-gatherelements} +Gather values of the input tensor along an axis according to the indices. -
+
**Arguments:** - - input: an {{MLOperand}}. The input tensor. - - options: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation. + - input: an {{MLOperand}}. The input N-D tensor from which the values are gathered. + - indices: an {{MLOperand}}. The indices N-D tensor of the input values to gather. The values must be of type {{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}} or {{MLOperandDataType/"int64"}}, and must be in the range -N (inclusive) to N (exclusive) where N is the size of the input dimension indexed by *options.axis*, and a negative index means indexing from the end of the dimension. + - options: an optional {{MLGatherOptions}}. The optional parameters of the operation. - **Returns:** + **Returns:** an {{MLOperand}}. The output N-D tensor of [=MLOperand/rank=] equal to the [=MLOperand/rank=] of *input*. +
+ +{{MLGatherSupportLimits}} has the following members: +
+ : input + :: {{MLSupportLimits}} for input operand. + : indices + :: {{MLSupportLimits}} for indices operand. + : output + :: {{MLSupportLimits}} for output operand. +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/gatherElements()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}[=/any data type|any=]> 1
{{indices}}{{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}}, {{MLOperandDataType/"int64"}}*input*'s [=MLOperand/rank=]
*output*[=/same type as|same as=] {{input}}*input*'s [=MLOperand/rank=]
+ +{{MLOpSupportLimits}} has the following members for {{MLGraphBuilder/gatherElements()}}: +
+ : gatherElements + :: Support limits for operator {{MLGraphBuilder/gatherElements()}}. +
+ +
+ The {{MLGraphBuilder/gatherElements(input, indices, options)/indices}} parameter to {{MLGraphBuilder/gatherElements()}} can not be clamped to the allowed range when the graph is built because the inputs are not known until execution. Implementations can introduce {{MLGraphBuilder/clamp()}} in the compiled graph if the required clamping behavior is not provided by the underlying platform. Similarly, if the underlying platform does not support negative indices, the implementation can introduce operations in the compiled graph to transform a negative index from the end of the dimension into a positive index. +
+ +
+ + The gatherElements(|input|, |indices|, |options|) method steps are: + + TODO: +
+ +
+
+ + Examples of how gatherElements works in different slicing schemes. + +
+    TODO:
+  
+
+
+ +### gatherND ### {#api-mlgraphbuilder-gathernd} +Gather values of the input tensor along an axis according to the indices. + + + +
+ **Arguments:** + - input: an {{MLOperand}}. The input N-D tensor from which the values are gathered. + - indices: an {{MLOperand}}. The indices N-D tensor of the input values to gather. The values must be of type {{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}} or {{MLOperandDataType/"int64"}}, and must be in the range -N (inclusive) to N (exclusive) where N is the size of the input dimension indexed by *options.axis*, and a negative index means indexing from the end of the dimension. + - options: an optional {{MLOperatorOptions}}. The optional parameters of the operation. + + **Returns:** an {{MLOperand}}. The output N-D tensor of [=MLOperand/rank=] equal to the *input*'s [=MLOperand/rank=] + *indices*'s [=MLOperand/rank=] - *indices*'s [=MLOperand/shape=][-1] - 1. +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/gatherND()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}[=/any data type|any=]> 1
{{indices}}{{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}}, {{MLOperandDataType/"int64"}}> 1
*output*[=/same type as|same as=] {{input}}*input*'s [=MLOperand/rank=] + *indices*'s [=MLOperand/rank=] - *indices*'s [=MLOperand/shape=][-1] - 1
+ +{{MLOpSupportLimits}} has the following members for {{MLGraphBuilder/gatherND()}}: +
+ : gatherND + :: Support limits for operator {{MLGraphBuilder/gatherND()}}. +
+ +
+ The {{MLGraphBuilder/gatherND(input, indices, options)/indices}} parameter to {{MLGraphBuilder/gatherND()}} can not be clamped to the allowed range when the graph is built because the inputs are not known until execution. Implementations can introduce {{MLGraphBuilder/clamp()}} in the compiled graph if the required clamping behavior is not provided by the underlying platform. Similarly, if the underlying platform does not support negative indices, the implementation can introduce operations in the compiled graph to transform a negative index from the end of the dimension into a positive index. +
+ +
+ + The gatherND(|input|, |indices|, |options|) method steps are: + + TODO: +
+ +
+
+ + Examples of how gatherND works in different slicing schemes. + +
+    TODO:
+  
+
+
+ +### gelu ### {#api-mlgraphbuilder-gelu-method} +Compute the gaussian error linear unit function (GELU) of the input tensor. The calculation follows the expression `0.5 * x * (1 + erf(x / sqrt(2)))`. + + + +
+ **Arguments:** + - input: an {{MLOperand}}. The input tensor. + - options: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation. + + **Returns:** - an {{MLOperand}}. The output tensor of the same shape as *input*.
@@ -5086,6 +5642,7 @@ partial dictionary MLOpSupportLimits { : axes :: The indices to the input dimensions to reduce. When this member is not present, it is treated as if all dimensions except the first were given (e.g. for a 4-D input tensor, axes = [1,2,3]). That is, the reduction for the mean and variance values are calculated across all the input features for each independent batch. If empty, no dimensions are reduced. + : epsilon :: A small value to prevent computational error due to divide-by-zero. @@ -7256,6 +7813,299 @@ partial dictionary MLOpSupportLimits { 1. Return |output|. +### reverse ### {#api-mlgraphbuilder-reverse-method} +Reverse a tensor along the given axes. + + + +{{MLReverseOptions}} has the following members: +
+ : axes + :: + The indices to the input dimensions to reverse. When this member is not present, it is treated as if all dimensions are reversed. If explicitly passed as empty, no dimensions are reversed. +
+ +
+ **Arguments:** + - input: an {{MLOperand}}. The input tensor. + - options: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation. + + **Returns:** + - an {{MLOperand}}. The output tensor of the same shape as *input*. +
+ + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/reverse()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}[=/any data type|any=][=/any rank|N=]
*output*[=/same type as|same as=] {{input}}[=/same rank as|same as=] {{input}}
+ +{{MLOpSupportLimits}} has the following member for {{MLGraphBuilder/reverse()}}: +
+ : reverse + :: Support limits for operator {{MLGraphBuilder/reverse()}}. +
+ +
+ + The reverse(|input|, |options|) method steps are: + + 1. If [=this=] [=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. + 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. + 1. If |input|'s [=MLOperand/dataType=] is not one of its [=/allowed data types=] (according to [this table](#constraints-reverse)), then [=exception/throw=] a {{TypeError}}. + 1. *Make graph connections:* + 1. Let |output| be the result of [=copying an MLOperand=] given |input|. + 1. Let |operator| be an [=operator=] for the "reverse" operation and |options|. + 1. Set |output|.{{MLOperand/[[operator]]}} to |operator|. + 1. Set |operator|'s [=operator/input=] to |input|. + 1. Set |operator|'s [=operator/output=] to |output|. + 1. Return |output|. +
+ +### scatterElements ### {#api-mlgraphbuilder-scatterelements} +Scatter values from the updates tensor along an axis according to the indices in place of the input tensor. + + + +{{MLScatterOptions}} has the following members: +
+ : axis + :: + The axis along which the scattered values are obtained. Its value must be in the range [0, N-1] where N is the [=MLOperand/rank=] of the input tensor. +
+ +
+ **Arguments:** + - input: an {{MLOperand}}. The input N-D tensor from which the values are scattered. + - indices: an {{MLOperand}}. The indices N-D tensor of the input values to scatter over. The values must be of type {{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}} or {{MLOperandDataType/"int64"}}, and must be in the range -N (inclusive) to N (exclusive) where N is the size of the input dimension indexed by *options.axis*, and a negative index means indexing from the end of the dimension. + - updates: an {{MLOperand}}. New values to replace atop the input. + - options: an optional {{MLScatterOptions}}. The optional parameters of the operation. + + **Returns:** an {{MLOperand}}. The output N-D tensor of [=MLOperand/rank=] equal to *input*'s [=MLOperand/rank=]. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/scatterElements()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}[=/any data type|any=]> 1
{{indices}}{{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}}, {{MLOperandDataType/"int64"}}{{input}}'s [=MLOperand/rank=]
{{updates}}[=/same type as|same as=] {{input}}{{input}}'s [=MLOperand/rank=] and {{indices}}'s [=MLOperand/shape=]
*output*[=/same type as|same as=] {{input}}{{input}}'s [=MLOperand/rank=]
+ +{{MLScatterSupportLimits}} has the following members: +
+ : input + :: {{MLSupportLimits}} for input operand. + : indices + :: {{MLSupportLimits}} for indices operand. + : updates + :: {{MLSupportLimits}} for updates operand. + : output + :: {{MLSupportLimits}} for output operand. +
+ +{{MLOpSupportLimits}} has the following members for {{MLGraphBuilder/scatterElements()}}: +
+ : scatterElements + :: Support limits for operator {{MLGraphBuilder/scatterElements()}}. +
+ +
+ The {{MLGraphBuilder/scatterElements(input, indices, updates, options)/indices}} parameter to {{MLGraphBuilder/scatterElements()}} can not be clamped to the allowed range when the graph is built because the inputs are not known until execution. Implementations can introduce {{MLGraphBuilder/clamp()}} in the compiled graph if the required clamping behavior is not provided by the underlying platform. Similarly, if the underlying platform does not support negative indices, the implementation can introduce operations in the compiled graph to transform a negative index from the end of the dimension into a positive index. +
+ +
+ + The scatterElements(|input|, |indices|, |updates|, |options|) method steps are: + + TODO: +
+ +
+
+ + Examples of how scatterElements works in different slicing schemes. + +
+    TODO:
+  
+
+
+ + +### scatterND ### {#api-mlgraphbuilder-scatternd} +Scatter values of the input tensor along an axis according to the indices. + + + +
+ **Arguments:** + - input: an {{MLOperand}}. The input N-D tensor from which the values are scattered. + - indices: an {{MLOperand}}. TODO: Elaborate on indices coordinate order. The indices N-D tensor of the input values to scatter. The values must be of type {{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}} or {{MLOperandDataType/"int64"}}, and must be in the range -N (inclusive) to N (exclusive) where N is the size of the input dimension indexed by *options.axis*, and a negative index means indexing from the end of the dimension. + - updates: an {{MLOperand}}. New values to replace atop the input. + - options: an optional {{MLScatterOptions}}. The optional parameters of the operation. + + **Returns:** an {{MLOperand}}. The output N-D tensor of [=MLOperand/rank=] equal to the [=MLOperand/rank=] of *input*'s [=MLOperand/rank=] + *indices*'s [=MLOperand/rank=] - *indices*'s [=MLOperand/shape=][-1] - 1. +
+ +{{MLScatterSupportLimits}} has the following members: +
+ : input + :: {{MLSupportLimits}} for input operand. + : indices + :: {{MLSupportLimits}} for indices operand. + : updates + :: {{MLSupportLimits}} for updates operand. + : output + :: {{MLSupportLimits}} for output operand. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/scatterND()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}[=/any data type|any=]> 1
{{indices}}{{MLOperandDataType/"int32"}}, {{MLOperandDataType/"uint32"}}, {{MLOperandDataType/"int64"}}> 1
{{updates}}[=/same type as|same as=] {{input}}*input*'s [=MLOperand/rank=] + *indices*'s [=MLOperand/rank=] - *indices*'s [=MLOperand/shape=][-1] - 1
*output*[=/same type as|same as=] {{input}}> 1
+ +{{MLOpSupportLimits}} has the following members for {{MLGraphBuilder/scatterND()}}: +
+ : scatterND + :: Support limits for operator {{MLGraphBuilder/scatterND()}}. +
+ +
+ The {{MLGraphBuilder/scatterND(input, indices, options)/indices}} parameter to {{MLGraphBuilder/scatterND()}} can not be clamped to the allowed range when the graph is built because the inputs are not known until execution. Implementations can introduce {{MLGraphBuilder/clamp()}} in the compiled graph if the required clamping behavior is not provided by the underlying platform. Similarly, if the underlying platform does not support negative indices, the implementation can introduce operations in the compiled graph to transform a negative index from the end of the dimension into a positive index. +
+ +
+ + The scatterND(|input|, |indices|, |updates|, |options|) method steps are: + + TODO: +
+ +
+
+ + Examples of how scatterND works in different slicing schemes. + +
+    TODO:
+  
+
+
+ ### sigmoid ### {#api-mlgraphbuilder-sigmoid-method} Compute the sigmoid function of the input tensor. The calculation follows the expression `1 / (exp(-x) + 1)`. @@ -7340,23 +8190,39 @@ partial dictionary MLOpSupportLimits { ### slice ### {#api-mlgraphbuilder-slice} Produce a slice of the input tensor. + +{{MLSliceOptions}} has the following members: +
+ : strides + :: + The stride to step over each input along each axis. + The length of the strides array must equal the [=MLOperand/rank=] of the input tensor. + The the default is an array of length [=MLOperand/rank=] consisting of all 1's. + e.g. [1,1,1] for a 3-D tensor. + Strides must be greater than zero. +
+
**Arguments:** - input: an {{MLOperand}}. The input tensor. - starts: [=sequence=]<{{unsigned long}}>. The starting index to slice of each input dimension, of length N where N is the [=MLOperand/rank=] of the input tensor. For each dimension *d* of *input*, *starts[d]* indicates the starting index to slice in that dimension. The starting index must be in the range [0, input size - 1] in that dimension. - sizes: [=sequence=]<{{unsigned long}}>. The number of elements to slice of each input dimension, of length N where N is the [=MLOperand/rank=] of the input tensor. For each dimension *d* of *input*, *sizes[d]* indicates the number of elements to slice in that dimension. The size must not be 0 and must satisfy the constraint `starting index + size <= input size` in that dimension. - - options: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation. + - options: an {{MLSliceOptions}}. Specifies the optional parameters of the operation. **Returns:** an {{MLOperand}}. The output tensor of the same rank as the input tensor with tensor values stripped to the specified starting and ending indices in each dimension.
@@ -7396,6 +8262,8 @@ partial dictionary MLOpSupportLimits { 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. 1. If any of |sizes|'s [=list/items=] are 0, then [=exception/throw=] a {{TypeError}}. 1. If |starts|'s [=list/size=] and |sizes|'s [=list/size=] are not both equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}. + 1. If |options|.{{MLSliceOptions/strides}} [=map/exists=]: + 1. If |options|.{{MLSliceOptions/strides}}'s [=list/size=] is not equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}. 1. [=list/For each=] |index| in [=the range=] 0 to |input|'s [=MLOperand/rank=], exclusive: 1. If |sizes|[|index|] is 0, then [=exception/throw=] a {{TypeError}}. @@ -7403,6 +8271,8 @@ partial dictionary MLOpSupportLimits { 1. If |starts|[|index|] is greater than or equal to |input|'s [=MLOperand/shape=][|index|], then [=exception/throw=] a {{TypeError}}. 1. If |starts|[|index|] + |sizes|[|index|] is greater than |input|'s [=MLOperand/shape=][|index|], then [=exception/throw=] a {{TypeError}}. + 1. If |options|.{{MLSliceOptions/strides}} [=map/exists=]: + 1. If |options|.{{MLSliceOptions/strides}}[|index|] is less than 1, then [=exception/throw=] a {{TypeError}}. 1. *Make graph connections:* 1. Let |output| be the result of [=copying an MLOperand=] given |input|. 1. Let |operator| be an [=operator=] for the "slice" operation, given |starts|, |sizes|, and |options|. @@ -7878,6 +8748,77 @@ partial dictionary MLOpSupportLimits {
+### tile ### {#api-mlgraphbuilder-tile} +Repeat a tensor the given number of times along each dimension. + + + +
+ **Arguments:** + - input: an {{MLOperand}}. The input N-D tensor. + - repetitions: A count per dimension of how many times to repeat that dimension. The |repetitions| [=list/size=] must match the |input|'s [=MLOperand/rank=], using 1's for any axis that should retain the same size. + - options: an optional {{MLOperatorOptions}}. The optional parameters of the operation. + + **Returns:** an {{MLOperand}}. The reversed N-D tensor. +
+ + + + + + + + + + + + + + + + + + + + +
Constraints for {{MLGraphBuilder/tile()}}
operand[=/allowed data types=][=/allowed ranks=]
{{input}}[=/any data type|any=][=/any rank|N=]
*output*[=/same type as|same as=] {{input}}[=/same rank as|same as=] {{input}}
+ +{{MLOpSupportLimits}} has the following members for {{MLGraphBuilder/tile()}}: +
+ : tile + :: Support limits for operator {{MLGraphBuilder/tile()}}. +
+ +
+ + The tile(|input|, |repetitions|, |options|) method steps are: + + 1. If [=this=] [=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. + 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. + 1. If |repetitions|'s [=list/size=] is not equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}. + 1. If |repetitions|'s values contain 0's, then [=exception/throw=] a {{TypeError}}. + + Issue(391): If 0-size dimensions are allowed, revise these steps. + + 1. *Make graph connections:* + 1. Let |output| be the result of [=copying an MLOperand=] given |input|. + 1. Let |operator| be an [=operator=] for the "tile" operation, given |options|. + 1. Set |output|.{{MLOperand/[[operator]]}} to |operator|. + 1. Set |operator|'s [=operator/input=] to |input|. + 1. Set |operator|'s [=operator/output=] to |output|. + 1. Return |output|. +
+ ### transpose ### {#api-mlgraphbuilder-transpose} Permute the dimensions of the input tensor according to the *permutation* argument.