You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce "valid dimension", used as needed when calculating operand shapes (#641)
* resample2d: Validate that dimensions are valid unsigned longs
If explicit sizes aren't provided, the size of an output dimension is
calculated as shape[i] * scales[i] which could be larger than can be
represented as a dimension in MLOperandDescriptor.
Explicitly validate and throw if this constraint isn't satisfied.
Fixes#610
* Introduce 'valid dimension' term
* Validate calculated dimensions when determining output shapes
* Update index.bs
Co-authored-by: Ningxin Hu <[email protected]>
* Update index.bs
Co-authored-by: Dwayne Robinson <[email protected]>
---------
Co-authored-by: Ningxin Hu <[email protected]>
Co-authored-by: Dwayne Robinson <[email protected]>
If the shape of each corresponding dimension and type of the operands, except for those of the dimension given by |axis|, is not the same, fail.
1769
1776
</div>
1770
1777
1. If |dim| is not equal to |axis| and if |input|'s [=MLOperand/shape=][|dim|] is not equal to |first|'s [=MLOperand/shape=][|dim|], then [=exception/throw=] a {{TypeError}}.
1771
-
1. If |dim| is equal to |axis|, add to |desc|.{{MLOperandDescriptor/dimensions}}[|axis|] the value of |input|'s [=MLOperand/shape=][|dim|].
1778
+
1. If |dim| is equal to |axis|:
1779
+
1. Let |size| be the sum of |desc|.{{MLOperandDescriptor/dimensions}}[|axis|] and |input|'s [=MLOperand/shape=][|dim|].
1780
+
1. If |size| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
1781
+
1. Set |desc|.{{MLOperandDescriptor/dimensions}}[|axis|] to |size|.
1772
1782
1. *Make graph connections:*
1773
1783
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
1774
1784
1. Let |operator| be an [=operator=] for the concat operation, given |inputs| and |axis|.
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}.
4450
4462
1. If |beginningPadding|'s [=list/size=] and |endingPadding|'s [=list/size=] are not both equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a "{{TypeError}}".
4451
4463
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}.
4452
-
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the result of [=MLGraphBuilder/calculating padding output sizes=] given |input|, |beginningPadding| and |endingPadding|.
4464
+
1. Let |outputShape| be the result of [=MLGraphBuilder/calculating padding output sizes=] given |input|, |beginningPadding| and |endingPadding|.
4465
+
1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
4466
+
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |outputShape|.
4453
4467
1. *Make graph connections:*
4454
4468
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
4455
4469
1. Let |operator| be an [=operator=] for the padding operation, given |beginningPadding|, |endingPadding| and |options|.
1. If |options|.{{MLPool2dOptions/dilations}}'s [=list/size=] is not 2, then [=exception/throw=] a {{TypeError}}.
4668
4682
1. If any value in |options|.{{MLPool2dOptions/dilations}} is not greater than 0, then [=exception/throw=] a {{TypeError}}.
4669
4683
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}.
4684
+
1. Let |outputShape| be the result of [=MLGraphBuilder/calculating pool2d output sizes=] given |options|.{{MLPool2dOptions/layout}}, |input|'s [=MLOperand/shape=], |options|.{{MLPool2dOptions/roundingType}}, |options|.{{MLPool2dOptions/windowDimensions}}, |options|.{{MLPool2dOptions/padding}}, |options|.{{MLPool2dOptions/strides}}, |options|.{{MLPool2dOptions/dilations}}, and |options|.{{MLPool2dOptions/outputSizes}} (if it [=map/exists=]).
4685
+
1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
4686
+
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |outputShape|.
4670
4687
1. *Make graph connections:*
4671
-
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to the result of [=MLGraphBuilder/calculating pool2d output sizes=] given |options|.{{MLPool2dOptions/layout}}, |input|'s [=MLOperand/shape=], |options|.{{MLPool2dOptions/roundingType}}, |options|.{{MLPool2dOptions/windowDimensions}}, |options|.{{MLPool2dOptions/padding}}, |options|.{{MLPool2dOptions/strides}}, |options|.{{MLPool2dOptions/dilations}}, and |options|.{{MLPool2dOptions/outputSizes}} (if it [=map/exists=]).
4672
4688
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
4673
4689
1. Let |operator| be an [=operator=] for the |op| pooling operation, given |options|.
4674
4690
1. Set |output|.{{MLOperand/[[operator]]}} to |operator|.
1. Let |desc| be a new {{MLOperandDescriptor}} initialized to |input|.{{MLOperand/[[descriptor]]}}.
5085
5101
1. For |index| in [=the range=] 0 to |options|.{{MLResample2dOptions/axes}}'s [=list/size=], exclusive:
5086
-
1. If |options|.{{MLResample2dOptions/sizes}}[=map/exists=], set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |options|.{{MLResample2dOptions/sizes}}[|index|].
5087
-
1. Otherwise, set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to floor(|input|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] * |options|.{{MLResample2dOptions/scales}}[|index|]).
5102
+
1. If |options|.{{MLResample2dOptions/sizes}}[=map/exists=], then let |size| be |options|.{{MLResample2dOptions/sizes}}[|index|].
5103
+
1. Otherwise, let |size| be floor(|input|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] * |options|.{{MLResample2dOptions/scales}}[|index|]).
5104
+
1. If |size| is not a [=valid dimension=], then return failure.
5105
+
1. Set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |size|.
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}.
5096
5114
1. If |input|'s [=MLOperand/rank=] is not 4, then [=exception/throw=] a {{TypeError}}.
5097
5115
1. If [=MLGraphBuilder/checking resample options=] given |options| returns false, then [=exception/throw=] a {{TypeError}}.
5098
-
1. Let |desc| be the result of [=MLGraphBuilder/calculating resample output sizes=] given |input| and |options|.
5116
+
1. Let |desc| be the result of [=MLGraphBuilder/calculating resample output sizes=] given |input| and |options|. If that returns failure, then [=exception/throw=] a {{TypeError}}.
5099
5117
1. *Make graph connections:*
5100
5118
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
5101
5119
1. Let |operator| be an [=operator=] for the resample 2D operation, given |options|.
0 commit comments