Skip to content

Commit

Permalink
Use broadcasting definition in expand(), rather than bespoke steps
Browse files Browse the repository at this point in the history
This matches the Chromium implementation.
  • Loading branch information
inexorabletash committed Feb 6, 2024
1 parent 440b1a1 commit 1b63ff7
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2842,17 +2842,12 @@ partial interface MLGraphBuilder {
<div class="note">
The permissions and context validity have been checked by [[#api-mlgraphbuilder-constructor]] steps.
</div>
1. If any of the following steps fail, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
1. Let |inputDesc| be |input|.{{MLOperand/[[descriptor]]}}.
1. If the sequence length of |newShape| is not equal to the [=rank=] of |inputDesc|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
1. Let |outputDesc| be a copy of |inputDesc|.
1. [=list/For each=] |index| in [=the range=] 0 to the [=rank=] of |input|, exclusive:
Issue: Can this be replaced with [=unidirectionally broadcasting the shapes=] |inputDesc| and |newShape|.
1. Let |size| be the |input|.{{MLOperand/shape()}}[|index|].
1. If |size| is not equal to 1 and not equal to |newShape|[index], then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
1. If |size| is equal to 1, then let |outputDesc|.{{MLOperandDescriptor/dimensions}}[|index|] be |newShape|[|index|].
1. Let |descriptor| be a new {{MLOperandDescriptor}}.
1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dataType}}.
1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to the result of [=unidirectionally broadcasting the shapes=] |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}} and |newShape|.
1. If that returns failure, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
1. If any of the following sub-steps fail, [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |outputDesc|.
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|.
1. Make a request to the underlying platform to:
1. Create [=platform operator=] |expandImpl| for this method, given |input| and |newShape|.
1. Set |output|.{{MLOperand/[[operator]]}} to |expandImpl|.
Expand Down

0 comments on commit 1b63ff7

Please sign in to comment.