From db82503f70e273d60e050cf817e9fb59066ea197 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Mon, 20 May 2024 13:37:45 -0700 Subject: [PATCH 1/2] Add missing validation for pad(), slice(), and split() Noticed during a review of the Chromium prototype. These are all pretty obvious except for slice() where there is subtlety for 0-size dimensions. I added an issue linking to #391 since the steps will need to be revised depending on how that issue is resolved. --- index.bs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 1a109ce9..80441f96 100644 --- a/index.bs +++ b/index.bs @@ -4462,7 +4462,8 @@ partial interface MLGraphBuilder { The pad(|input|, |beginningPadding|, |endingPadding|, |options|) method steps are: 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. - 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}}". + 1. If |input|'s [=MLOperand/rank=] is 0, then [=exception/throw=] a {{TypeError}} + 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}}. 1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}. 1. Let |outputShape| be the result of [=MLGraphBuilder/calculating padding output sizes=] given |input|, |beginningPadding| and |endingPadding|. 1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}. @@ -5294,6 +5295,13 @@ partial interface MLGraphBuilder { 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. [=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}}. + + Issue(391): If 0-size dimensions are allowed, revise these steps. + + 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. *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| and |sizes|. @@ -5539,10 +5547,12 @@ partial interface MLGraphBuilder { 1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}. 1. Let |axis| be |options|.{{MLSplitOptions/axis}}. + 1. If |axis| is greater than or equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}. 1. If |splits| is an {{unsigned long}}: 1. If |input|'s [=MLOperand/shape=][|axis|] % |splits| is not 0, then [=exception/throw=] a {{TypeError}}. 1. Otherwise, let |splitCount| be |splits|. 1. If |splits| is a sequence of {{unsigned long}}: + 1. If any of its elements is equal to 0, then [=exception/throw=] a {{TypeError}}. 1. If the sum of its elements is not equal to |input|'s [=MLOperand/shape=][|axis|], then [=exception/throw=] a {{TypeError}}. 1. Otherwise, let |splitCount| be |splits|'s [=list/size=]. 1. *Make graph connections:* From 962ca97be0adc271367cce16c2ff8867edad9c9b Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Tue, 21 May 2024 09:09:07 -0700 Subject: [PATCH 2/2] Add another note for split() --- index.bs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.bs b/index.bs index 80441f96..cad5f6ee 100644 --- a/index.bs +++ b/index.bs @@ -5553,6 +5553,9 @@ partial interface MLGraphBuilder { 1. Otherwise, let |splitCount| be |splits|. 1. If |splits| is a sequence of {{unsigned long}}: 1. If any of its elements is equal to 0, then [=exception/throw=] a {{TypeError}}. + + Issue(391): If 0-size dimensions are allowed, revise the above step. + 1. If the sum of its elements is not equal to |input|'s [=MLOperand/shape=][|axis|], then [=exception/throw=] a {{TypeError}}. 1. Otherwise, let |splitCount| be |splits|'s [=list/size=]. 1. *Make graph connections:*