Skip to content

Commit c44fe62

Browse files
Bug fix: Remove null value support in reshape()'s newShape parameter (#505)
As noted in issue #388, the reshape op build method currently supports a special null value in newShape array that instructs the implementation to compute the size of the dimension with the value null so that the total size remains constant. @fwdr proposed WebNN should only support the concrete values in newShape because this can be easily handled by framework through shape inference It appears this change has already landed in the Chromium implementation and WPTs. Fixes #388
1 parent 50a00b9 commit c44fe62

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

index.bs

+2-8
Original file line numberDiff line numberDiff line change
@@ -5316,18 +5316,15 @@ partial interface MLGraphBuilder {
53165316
Alter the shape of a tensor to a new shape. Reshape does not copy or change the content of the tensor. It just changes the tensor's logical dimensions for the subsequent operations.
53175317
<script type=idl>
53185318
partial interface MLGraphBuilder {
5319-
MLOperand reshape(MLOperand input, sequence<unsigned long?> newShape);
5319+
MLOperand reshape(MLOperand input, sequence<unsigned long> newShape);
53205320
};
53215321
</script>
53225322
<div>
53235323
**Arguments:**
53245324
- *input*: an {{MLOperand}}. The input tensor.
53255325
- *newShape*: a sequence of [=nullable type|nullable=] {{unsigned long}}. The shape of the output tensor.
53265326
The number of elements implied by *newShape* must be the same as the
5327-
number of elements in the input tensor. Only one component of
5328-
*newShape* can be the special value of `null`. The size of the dimension
5329-
with the value `null` is computed so that the total size remains
5330-
constant.
5327+
number of elements in the input tensor.
53315328

53325329
**Returns:** an {{MLOperand}}. The output tensor. The values of the output
53335330
tensor are the same as values of the input tensor. The shape of the output
@@ -5344,11 +5341,8 @@ partial interface MLGraphBuilder {
53445341
1. If |newShape| is a scalar [=number=], set |outputShape| to « 1 ».
53455342
1. Otherwise, if |newShape| is an array of {{unsigned long}}:
53465343
1. If the [=list/size=] of |newShape| is 0, set |outputShape| to « 1 » (reshaping to scalar).
5347-
1. If |newShape| contains more than one `null` value, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
53485344
1. If any value in |newShape| is 0, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
53495345
1. Let |inputElementCount| be the product of all elements in |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
5350-
1. If |newShape| contains a `null` value, set that value to |inputElementCount| divided by the product of all other values in |newShape|.
5351-
1. If that value is too large for {{unsigned long}}, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
53525346
1. If product of all values in |newShape| is not equal to |inputElementCount|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
53535347
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}.
53545348
1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |newShape|.

0 commit comments

Comments
 (0)