Skip to content

Commit

Permalink
Bug fix: Remove null value support in reshape()'s newShape parameter (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
inexorabletash authored Jan 20, 2024
1 parent 50a00b9 commit c44fe62
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5316,18 +5316,15 @@ partial interface MLGraphBuilder {
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.
<script type=idl>
partial interface MLGraphBuilder {
MLOperand reshape(MLOperand input, sequence<unsigned long?> newShape);
MLOperand reshape(MLOperand input, sequence<unsigned long> newShape);
};
</script>
<div>
**Arguments:**
- *input*: an {{MLOperand}}. The input tensor.
- *newShape*: a sequence of [=nullable type|nullable=] {{unsigned long}}. The shape of the output tensor.
The number of elements implied by *newShape* must be the same as the
number of elements in the input tensor. Only one component of
*newShape* can be the special value of `null`. The size of the dimension
with the value `null` is computed so that the total size remains
constant.
number of elements in the input tensor.

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

0 comments on commit c44fe62

Please sign in to comment.