From c880a33452fc28711269872c49272636e24ad92c Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Mon, 22 Jul 2024 09:56:48 -0700 Subject: [PATCH 1/6] Add helper for creating MLOperandDescriptor to simplify steps The only non-trivial bits are a few cases where in the previous steps the shape was calculated after the MLOperandDescriptor was created, but this would not be an observable change to script. --- index.bs | 102 ++++++++++++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 62 deletions(-) diff --git a/index.bs b/index.bs index d071c962..ed1b47e0 100644 --- a/index.bs +++ b/index.bs @@ -1103,6 +1103,16 @@ dictionary MLOperandDescriptor { :: The shape of the operand. It is empty for scalar operands, and non-empty for tensor operands. +
+ + To create an {{MLOperandDescriptor}} given {{MLOperandDataType}} |dataType| and [=/list=] |dimensions|, run the following steps: + + 1. Let |descriptor| be a new {{MLOperandDescriptor}}. + 1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |dataType|. + 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to a [=list/clone=] of |dimensions|. + 1. Return |descriptor|. +
+
The byte length of an {{MLOperandDescriptor}} |desc| is the value returned by the following steps: @@ -1380,9 +1390,7 @@ Data truncation will occur when the specified value exceeds the range of the spe 1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. 1. Set |value| to the result of [=casting=] |value| to |type|. - 1. Let |descriptor| be a new {{MLOperandDescriptor}}. - 1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |type|. - 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to an empty [=/list=]. + 1. Let |descriptor| be the result of [=creating an MLOperandDescriptor=] given |type| and « ». 1. *Make graph connections:* 1. Let |operand| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|. 1. Add |operand| to [=this=]'s [=MLGraphBuilder/graph=]'s [=computational graph/constants=] with |value| as value. @@ -1482,9 +1490,7 @@ partial interface MLGraphBuilder { 1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. 1. Let |outputShape| be the result of [=MLGraphBuilder/calculating reduction output sizes=] given |input|'s [=MLOperand/shape=], « |axis| », and |options|.{{MLArgMinMaxOptions/keepDimensions}}. If that returns failure, then [=exception/throw=] a {{TypeError}}. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to {{MLOperandDataType/"int64"}}. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |outputShape|. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given {{MLOperandDataType/"int64"}} and |outputShape|. 1. *Make graph connections:* 1. Let |operator| be an [=operator=] for the |op| operation, given |options|. 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|. @@ -1815,9 +1821,7 @@ partial interface MLGraphBuilder { 1. If |inputs| [=list/is empty=], then [=exception/throw=] a {{TypeError}}. 1. Let |first| be |inputs|[0]. 1. If |axis| is greater than or equal to |first|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |first|'s [=MLOperand/dataType=]. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to a [=list/clone=] of |first|'s [=MLOperand/shape=]. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |first|'s [=MLOperand/dataType=] and |first|'s [=MLOperand/shape=]. 1. Set |desc|.{{MLOperandDescriptor/dimensions}}[|axis|] to |first|'s [=MLOperand/shape=][|axis|]. 1. [=list/For each=] |index| in [=the range=] 1 to |inputs|'s [=list/size=], exclusive: 1. Let |input| be |inputs|[|index|]. @@ -2028,9 +2032,7 @@ partial interface MLGraphBuilder { :: Let |outputShape| be « |batches|, floor( |outputSizes|[0] ), floor( |outputSizes|[1] ), |outputChannels| ». 1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |outputShape|. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|. 1. Let |operator| be an [=operator=] for the "conv2d" operation, given |options| and |filter|. @@ -2240,9 +2242,7 @@ partial interface MLGraphBuilder { :: Let |outputShape| be « |batches|, floor( |outputSizes|[0] ), floor( |outputSizes|[1] ), |outputChannels| ». 1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |outputShape|. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|. 1. Let |operator| be an [=operator=] for the "convTranspose2d" operation, given |options| and |filter|. @@ -2300,10 +2300,9 @@ partial interface MLGraphBuilder { 1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. 1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |a| and |b| returns false, then [=exception/throw=] a {{TypeError}}. 1. If |a|'s [=MLOperand/dataType=] is not equal to |b|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. - 1. Let |descriptor| be a new {{MLOperandDescriptor}}. - 1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |a|'s [=MLOperand/dataType=]. - 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to the result of [=bidirectionally broadcasting the shapes=] |a|'s [=MLOperand/shape=] and |b|'s [=MLOperand/shape=]. + 1. Let |outputShape| be the result of [=bidirectionally broadcasting the shapes=] |a|'s [=MLOperand/shape=] and |b|'s [=MLOperand/shape=]. 1. If that returns failure, then [=exception/throw=] a {{TypeError}}. + 1. Let |descriptor| be the result of [=creating an MLOperandDescriptor=] given |a|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|. 1. Let |operator| be an [=operator=] for the |op| operation, given |a| and |b|. @@ -2419,9 +2418,7 @@ Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/les 1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |a| and |b| returns false, then [=exception/throw=] a {{TypeError}}. 1. If |a|'s [=MLOperand/dataType=] is not equal to |b|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. 1. Let |outputShape| be the result of [=bidirectionally broadcasting the shapes=] |a|'s [=MLOperand/shape=] and |b|'s [=MLOperand/shape=]. If that returns failure, then [=exception/throw=] a {{TypeError}}. - 1. Let |descriptor| be a new {{MLOperandDescriptor}}. - 1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to {{MLOperandDataType/"uint8"}}. - 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to |outputShape|. + 1. Let |descriptor| be the result of [=creating an MLOperandDescriptor=] given {{MLOperandDataType/"uint8"}} and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|. 1. Let |operator| be an [=operator=] for the |op| operation, given |a| and (if |op| is not "logicalNot") |b|. @@ -2722,10 +2719,9 @@ partial interface MLGraphBuilder { 1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. - 1. Let |outputDescriptor| be a new {{MLOperandDescriptor}}. - 1. Set |outputDescriptor|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. - 1. Set |outputDescriptor|.{{MLOperandDescriptor/dimensions}} to the result of [=unidirectionally broadcasting the shapes=] |input|'s [=MLOperand/shape=] and |newShape|. + 1. Let |outputShape| be the result of [=unidirectionally broadcasting the shapes=] |input|'s [=MLOperand/shape=] and |newShape|. 1. If that returns failure, then [=exception/throw=] a {{TypeError}}. + 1. Let |outputDescriptor| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |outputDescriptor|. 1. Let |operator| be an [=operator=] for the "expand" operation, given |input| and |newShape|. @@ -2798,9 +2794,7 @@ partial interface MLGraphBuilder { 1. If |dimCount| is less than or equal to |axis| then [=iteration/continue=]. 1. Set |shapeOutput|[|rankOutput| + |dimCount| - |axis| - 1] to |size|. 1. Increment |dimCount| by one. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |shapeOutput|. - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |shapeOutput|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given |desc|. 1. Let |operator| be an [=operator=] for the "gather" operation, given |input|, |indices|, and |options|. @@ -2985,9 +2979,7 @@ partial interface MLGraphBuilder { 1. If |options|.{{MLGemmOptions/c}} [=map/exists=]: 1. If it is not [=unidirectionally broadcastable=] to the shape « |shapeA|[0], |shapeB|[1] », then [=exception/throw=] a {{TypeError}}. 1. If its [=MLOperand/dataType=] is not equal to |a|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |shapeA|[0], |shapeB|[1] ». - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |a|'s [=MLOperand/dataType=]. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |a|'s [=MLOperand/dataType=] and « |shapeA|[0], |shapeB|[1] ». 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|. 1. Let |operator| be an [=operator=] for the "gemm" operation, given |options|. @@ -3148,13 +3140,9 @@ partial interface MLGraphBuilder { 1. Otherwise: 1. Let |activations| be « {{MLRecurrentNetworkActivation/"sigmoid"}}, {{MLRecurrentNetworkActivation/"tanh"}} ». 1. *Calculate the output shape:* - 1. Let |desc0| be a new {{MLOperandDescriptor}}. - 1. Set |desc0|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |numDirections|, |batchSize|, |hiddenSize| ». - 1. Set |desc0|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. + 1. Let |desc0| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and « |numDirections|, |batchSize|, |hiddenSize| ». 1. If |options|.{{MLGruOptions/returnSequence}} is true: - 1. Let |desc1| be a new {{MLOperandDescriptor}}. - 1. Set |desc1|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. - 1. Set |desc1|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |steps|, |numDirections|, |batchSize|, |hiddenSize| ». + 1. Let |desc1| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and « |steps|, |numDirections|, |batchSize|, |hiddenSize| ». 1. *Make graph connections:* 1. Let |operator| be an [=operator=] for the "gru" operation, given |weight|, |recurrentWeight|, |steps|, |hiddenSize| and |options| as parameters. 1. Let |output0| be the result of [=creating an MLOperand=] given [=this=] and |desc0|. @@ -3366,9 +3354,7 @@ partial interface MLGraphBuilder { 1. Let |activations| be a [=list/clone=] of |options|.{{MLGruCellOptions/activations}}. 1. Otherwise: 1. Let |activations| be « {{MLRecurrentNetworkActivation/"sigmoid"}}, {{MLRecurrentNetworkActivation/"tanh"}} ». - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |batchSize|, |hiddenSize| ». - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and « |batchSize|, |hiddenSize| ». 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|. 1. Let |operator| be an [=operator=] for the "gruCell" operation, given |weight|, |recurrentWeight|, |hiddenState|, |hiddenSize| and |options| as parameters. @@ -4072,13 +4058,9 @@ partial interface MLGraphBuilder { 1. Otherwise: 1. Let |activations| be « {{MLRecurrentNetworkActivation/"sigmoid"}}, {{MLRecurrentNetworkActivation/"tanh"}}, {{MLRecurrentNetworkActivation/"tanh"}} ». 1. *Calculate the output shape:* - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |numDirections|, |batchSize|, |hiddenSize| ». - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and « |numDirections|, |batchSize|, |hiddenSize| ». 1. If |options|.{{MLLstmOptions/returnSequence}} is true: - 1. Let |desc2| be a new {{MLOperandDescriptor}}. - 1. Set |desc2|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. - 1. Set |desc2|.{{MLOperandDescriptor/dimensions}} to the [=/list=] « |steps|, |numDirections|, |batchSize|, |hiddenSize| ». + 1. Let |desc2| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and « |steps|, |numDirections|, |batchSize|, |hiddenSize| ». 1. *Make graph connections:* 1. Let |operator| be an [=operator=] for the "lstm" operation, given |weight|, |recurrentWeight|, |steps|, |hiddenSize| and |options|. 1. Let |output0| be the result of [=creating an MLOperand=] given [=this=] and |desc|. @@ -4522,10 +4504,9 @@ partial interface MLGraphBuilder { 1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |a| and |b| returns false, then [=exception/throw=] a {{TypeError}}. 1. If |a|'s [=MLOperand/dataType=] is not {{MLOperandDataType/"float32"}} or {{MLOperandDataType/"float16"}}, then [=exception/throw=] a {{TypeError}}. 1. If |b|'s [=MLOperand/dataType=] is not equal to |a|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the result of [=MLGraphBuilder/calculating matmul output sizes=] given |a| and |b|. - 1. If that throws an error, re-[=exception/throw=] the error. - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |a|'s [=MLOperand/dataType=]. + 1. Let |outputShape| be the result of [=MLGraphBuilder/calculating matmul output sizes=] given |a| and |b|. + 1. If that throws an error, re-[=exception/throw=] the error. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |a|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|. 1. Let |operator| be an [=operator=] for the "matmul" operation. @@ -4898,10 +4879,9 @@ partial interface MLGraphBuilder { 1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |input| and |slope| returns false, then [=exception/throw=] a {{TypeError}}. 1. If |input|'s [=MLOperand/dataType=] is not {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}}, {{MLOperandDataType/"int32"}}, or {{MLOperandDataType/"int8"}}, then [=exception/throw=] a {{TypeError}}. 1. If |slope|'s [=MLOperand/dataType=] is not equal to |input|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. - 1. Let |descriptor| be a new {{MLOperandDescriptor}}. - 1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. - 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to the result of [=unidirectionally broadcasting the shapes=] |slope|'s [=MLOperand/shape=] and |input|'s [=MLOperand/shape=]. + 1. Let |outputShape| be to the result of [=unidirectionally broadcasting the shapes=] |slope|'s [=MLOperand/shape=] and |input|'s [=MLOperand/shape=]. 1. If that returns failure, then [=exception/throw=] a {{TypeError}}. + 1. Let |descriptor| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|. 1. Let |operator| be an [=operator=] for the "prelu" operation, given |slope|. @@ -5009,9 +4989,7 @@ partial interface MLGraphBuilder { 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}}. 1. Let |outputShape| be the result of [=MLGraphBuilder/calculating reduction output sizes=] given |input|'s [=MLOperand/shape=], |options|.{{MLReduceOptions/axes}} (if it [=map/exists=]), and |options|.{{MLReduceOptions/keepDimensions}}. If that returns failure, then [=exception/throw=] a {{TypeError}}. - 1. Let |desc| be a new {{MLOperandDescriptor}}. - 1. Set |desc|.{{MLOperandDescriptor/dataType}} to |input|'s [=MLOperand/dataType=]. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |outputShape|. + 1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|. 1. Let |operator| be an [=operator=] for the |op| operation, given |options|. @@ -5234,13 +5212,14 @@ partial interface MLGraphBuilder { To calculate resample output sizes given {{MLOperand}} |input| and {{MLResample2dOptions}} |options|, run the following steps: - 1. Let |desc| be a new {{MLOperandDescriptor}} initialized to |input|.{{MLOperand/[[descriptor]]}}. + 1. Let |inputDescriptor| be |input|.{{MLOperand/[[descriptor]]}}. + 1. Let |outputShape| be a [=list/clone=] of |inputDescriptor|.{{MLOperandDescriptor/dimensions}}. 1. [=list/For each=] |index| in [=the range=] 0 to |options|.{{MLResample2dOptions/axes}}'s [=list/size=], exclusive: 1. If |options|.{{MLResample2dOptions/sizes}} [=map/exists=], then let |size| be |options|.{{MLResample2dOptions/sizes}}[|index|]. 1. Otherwise, let |size| be floor(|input|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] * |options|.{{MLResample2dOptions/scales}}[|index|]). 1. If |size| is not a [=valid dimension=], then return failure. - 1. Set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |size|. - 1. Return |desc|. + 1. Set |outputShape|[|options|.{{MLResample2dOptions/axes}}[|index|]] to |size|. + 1. Return the result of [=creating an MLOperandDescriptor=] given |inputDescriptor|.{{MLOperandDescriptor/dataType}} and |outputShape|.
@@ -5873,11 +5852,10 @@ partial interface MLGraphBuilder { 1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |condition|, |trueValue|, and |falseValue| returns false, then [=exception/throw=] a {{TypeError}}. 1. If |condition|'s [=MLOperand/dataType=] is not equal to {{MLOperandDataType/"uint8"}}, then [=exception/throw=] a {{TypeError}}. 1. If |trueValue|'s [=MLOperand/dataType=] is not equal to |falseValue|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. - 1. Let |descriptor| be a new {{MLOperandDescriptor}}. - 1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |trueValue|'s [=MLOperand/dataType=]. - 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to the result of [=bidirectionally broadcasting the shapes=] |trueValue|'s [=MLOperand/shape=] and |falseValue|'s [=MLOperand/shape=]. + 1. Let |outputShape| be the result of [=bidirectionally broadcasting the shapes=] |trueValue|'s [=MLOperand/shape=] and |falseValue|'s [=MLOperand/shape=]. 1. If that returns failure, then [=exception/throw=] a {{TypeError}}. - 1. If |condition| is not [=bidirectionally broadcastable=] to |descriptor|.{{MLOperandDescriptor/dimensions}}, then [=exception/throw=] a {{TypeError}}. + 1. If |condition| is not [=bidirectionally broadcastable=] to |outputShape|, then [=exception/throw=] a {{TypeError}}. + 1. Let |descriptor| be the result of [=creating an MLOperandDescriptor=] given |trueValue|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|. 1. Let |operator| be an [=operator=] for the "where" operation, given |condition|, |trueValue| and |falseValue|. From eabc742610a6dfe6791efc30cddaa27f1d87b37f Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Wed, 24 Jul 2024 08:41:12 -0700 Subject: [PATCH 2/6] whitespace change to trigger build --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index dd0d5a49..e95e2b19 100644 --- a/index.bs +++ b/index.bs @@ -1472,7 +1472,7 @@ partial interface MLGraphBuilder { : keepDimensions :: If true, retains reduced dimensions with [=list/size=] 1. - + : outputDataType :: An {{MLOperandDataType}}. The output data type. From efef0906660e9863656e86895fbc26e9722d2c2c Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Wed, 24 Jul 2024 09:48:33 -0700 Subject: [PATCH 3/6] unrelated fix to trigger action --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index e95e2b19..8dd4a2f3 100644 --- a/index.bs +++ b/index.bs @@ -1746,7 +1746,7 @@ partial interface MLGraphBuilder { - input: an {{MLOperand}}. The input tensor. - options: an optional {{MLClampOptions}}. The optional parameters of the operation. **Returns:** - - an {{MLOperand}}. The output tensor of the same shape as *operand*. + - an {{MLOperand}}. The output tensor of the same shape as *input*.
From a5e21ff0f1d183d9189f2eebf349a6b1a41942e4 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Thu, 25 Jul 2024 09:51:02 -0700 Subject: [PATCH 4/6] Broadcast condition too Co-authored-by: Ningxin Hu --- index.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 8dd4a2f3..fb158f28 100644 --- a/index.bs +++ b/index.bs @@ -5860,7 +5860,8 @@ partial interface MLGraphBuilder { 1. If |trueValue|'s [=MLOperand/dataType=] is not equal to |falseValue|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}. 1. Let |outputShape| be the result of [=bidirectionally broadcasting the shapes=] |trueValue|'s [=MLOperand/shape=] and |falseValue|'s [=MLOperand/shape=]. 1. If that returns failure, then [=exception/throw=] a {{TypeError}}. - 1. If |condition| is not [=bidirectionally broadcastable=] to |outputShape|, then [=exception/throw=] a {{TypeError}}. + 1. Let |outputShape| be the result of [=bidirectionally broadcasting the shapes=] |condition|'s [=MLOperand/shape=] and |outputShape]. + 1. If that returns failure, then [=exception/throw=] a {{TypeError}}. 1. Let |descriptor| be the result of [=creating an MLOperandDescriptor=] given |trueValue|'s [=MLOperand/dataType=] and |outputShape|. 1. *Make graph connections:* 1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|. From c9385429e7ff860b75608ef15fe0fd3a58c65fbb Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Thu, 25 Jul 2024 09:54:39 -0700 Subject: [PATCH 5/6] Use "set" to update Also, retain usage of "bidirectionally broadcastable" --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index fb158f28..761fe904 100644 --- a/index.bs +++ b/index.bs @@ -5832,7 +5832,7 @@ partial interface MLGraphBuilder { ### where ### {#api-mlgraphbuilder-where} Select the values from the trueValue or the falseValue tensor depending on the corresponding values of the condition tensor, where non-zero is true and zero is false. The condition tensor is often the output of one of the element-wise logical operations. -The input tensors will be broadcasted according to [[!numpy-broadcasting-rule]] to the final output shape. The [=MLOperand/rank=] of the output tensor is the maximum [=MLOperand/rank=] of the input tensors. +The input tensors must be [=bidirectionally broadcastable=] and will be broadcasted according to [[!numpy-broadcasting-rule]] to the final output shape. 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.