Skip to content

Commit 30acaf4

Browse files
Rewrite to match Chromium impl
1 parent 54965a1 commit 30acaf4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

index.bs

+15-15
Original file line numberDiff line numberDiff line change
@@ -4326,8 +4326,8 @@ partial interface MLGraphBuilder {
43264326

43274327
<div>
43284328
**Arguments:**
4329-
- *a*: an {{MLOperand}}. The first N-dimensional input tensor.
4330-
- *b*: an {{MLOperand}}. The second N-dimensional input tensor.
4329+
- *a*: an {{MLOperand}}. The first input tensor which is at least 2-D.
4330+
- *b*: an {{MLOperand}}. The second input tensor which is at least 2-D.
43314331

43324332
**Returns:** an {{MLOperand}}. The output tensor that contains the matrix
43334333
product of two input tensors.
@@ -4337,9 +4337,6 @@ partial interface MLGraphBuilder {
43374337
- If both *a* and *b* are 2-dimensional, they are multiplied like conventional
43384338
matrices and produce a 2-dimensional tensor as the output.
43394339
- If either *a* or *b* is `N`-dimensional where `N > 2`, it is treated as a stack of matrices with dimensions corresponding to the last two indices. The matrix multiplication will be broadcasted accordingly by following the [[!numpy-broadcasting-rule]]. The output is a `N`-dimensional tensor whose rank is the maximum [=rank=] of the input tensors. For each dimension, except the last two, of the output tensor, its size is the maximum size along that dimension of the input tensors.
4340-
- If *a* is 1-dimensional, it is converted to a 2-dimensional tensor by prepending a 1 to its dimensions.
4341-
- If *b* is 1-dimensional, it is converted to a 2-dimensional tensor by by appending a 1 to its dimensions.
4342-
- If both *a* and *b* are 1-dimensional, the operation is a vector dot-product, which produces a scalar output.
43434340
</div>
43444341

43454342
<details open algorithm>
@@ -4351,16 +4348,19 @@ partial interface MLGraphBuilder {
43514348
1. Let |sizeA| be the [=list/size=] of |shapeA|.
43524349
1. Let |shapeB| be a [=list/clone=] of |b|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
43534350
1. Let |sizeB| be the [=list/size=] of |shapeB|.
4354-
1. If |sizeA| and |sizeB| is 1, return « 1 ».
4355-
1. If |sizeA| is 1, then [=list/prepend=] 1 to |shapeA| and set |sizeA| to 2.
4356-
1. If |shapeA|[0] is not equal to |shapeB|[|sizeB| - 2], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4357-
1. If |sizeB| is 1, then [=list/append=] 1 to |shapeB| and set |sizeB| to 2.
4358-
1. If |shapeA|[|sizeA| - 1] is not equal to |shapeB|[0], then [=exception/throw=] an "{{OperationError}}" {{DOMException}}.
4359-
1. Let |size| be the maximum of |sizeA| and |sizeB|.
4360-
1. Let |shape| be a new [=/list=].
4361-
1. [=list/For each=] |index| in [=the range=] 0 to |size|, exclusive:
4362-
1. [=list/Append=] the maximum of |shapeA|[|index|] and |shapeB|[|index|] to |shape|.
4363-
1. Return |shape|.
4351+
1. If either |sizeA| or |sizeB| is less than 2, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
4352+
1. Let |colsA| be |shapeA|[|sizeA| - 1].
4353+
1. Let |rowsA| be |shapeA|[|sizeA| - 2].
4354+
1. Let |colsB| be |shapeB|[|sizeB| - 1].
4355+
1. Let |rowsB| be |shapeB|[|sizeB| - 2].
4356+
1. If |colsA| is not equal to |rowsB|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
4357+
1. Let |slicedA| be a [=list/clone=] of |shapeA| with the last 2 items [=list/removed=].
4358+
1. Let |slicedB| be a [=list/clone=] of |shapeB| with the last 2 items [=list/removed=].
4359+
1. If both |sizeA| and |sizeB| are greater than 2, then let |outputShape| be the result of [=bidirectionally broadcasting the shapes=] |slicedA| and |slicedB|. If that returns failure, then [=exception/throw=] a "{{DataError}}" {{DOMException}}.
4360+
1. Otherwise, if both |sizeA| and |sizeB| are equal to 2, then let |outputShape| be an empty [=/list=].
4361+
1. Otherwise, let |outputShape| be the [=list/size|longer=] of |slicedA| or |slicedB|.
4362+
1. [=list/Append=] « |rowsA|, |colsB| » to |outputShape|.
4363+
1. Return |outputShape|.
43644364
</div>
43654365
</details>
43664366

0 commit comments

Comments
 (0)