You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Applies matrix multiplication to two tensors. `matmul` follows
529
-
the complete broadcast rules,
530
-
and its behavior is consistent with `np.matmul`.
531
-
532
-
Currently, the input tensors' number of dimensions can be any, `matmul` can be used to
533
-
achieve the `dot`, `matmul` and `batchmatmul`.
534
-
535
-
The actual behavior depends on the shapes of :math:`x`, :math:`y` and the
536
-
flag values of :attr:`transpose_x`, :attr:`transpose_y`. Specifically:
537
-
538
-
- If a transpose flag is specified, the last two dimensions of the tensor
539
-
are transposed. If the tensor is ndim-1 of shape, the transpose is invalid. If the tensor
540
-
is ndim-1 of shape :math:`[D]`, then for :math:`x` it is treated as :math:`[1, D]`, whereas
541
-
for :math:`y` it is the opposite: It is treated as :math:`[D, 1]`.
542
-
543
-
The multiplication behavior depends on the dimensions of `x` and `y`. Specifically:
544
-
545
-
- If both tensors are 1-dimensional, the dot product result is obtained.
546
-
547
-
- If both tensors are 2-dimensional, the matrix-matrix product is obtained.
548
-
549
-
- If the `x` is 1-dimensional and the `y` is 2-dimensional,
550
-
a `1` is prepended to its dimension in order to conduct the matrix multiply.
551
-
After the matrix multiply, the prepended dimension is removed.
552
-
553
-
- If the `x` is 2-dimensional and `y` is 1-dimensional,
554
-
the matrix-vector product is obtained.
555
-
556
-
- If both arguments are at least 1-dimensional and at least one argument
557
-
is N-dimensional (where N > 2), then a batched matrix multiply is obtained.
558
-
If the first argument is 1-dimensional, a 1 is prepended to its dimension
559
-
in order to conduct the batched matrix multiply and removed after.
560
-
If the second argument is 1-dimensional, a 1 is appended to its
561
-
dimension for the purpose of the batched matrix multiple and removed after.
562
-
The non-matrix (exclude the last two dimensions) dimensions are
563
-
broadcasted according the broadcast rule.
564
-
For example, if input is a (j, 1, n, m) tensor and the other is a (k, m, p) tensor,
565
-
out will be a (j, k, n, p) tensor.
566
-
567
-
Args:
568
-
x (Tensor): The input tensor which is a Tensor.
569
-
y (Tensor): The input tensor which is a Tensor.
570
-
transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication. Default is False.
571
-
transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication. Default is False.
572
-
name (str|None, optional): If set None, the layer will be named automatically. For more information, please refer to :ref:`api_guide_Name`. Default is None.
573
-
out (Tensor, optional): The output tensor. If set, the result will be stored in this tensor. Default is None.
574
-
575
-
Returns:
576
-
Tensor: The output Tensor.
577
-
578
-
Examples:
579
-
580
-
.. code-block:: python
581
-
582
-
>>> import paddle
583
-
584
-
>>> # vector * vector
585
-
>>> x = paddle.rand([10])
586
-
>>> y = paddle.rand([10])
587
-
>>> z = paddle.matmul(x, y)
588
-
>>> print(z.shape)
589
-
[]
590
-
591
-
>>> # matrix * vector
592
-
>>> x = paddle.rand([10, 5])
593
-
>>> y = paddle.rand([5])
594
-
>>> z = paddle.matmul(x, y)
595
-
>>> print(z.shape)
596
-
[10]
597
-
598
-
>>> # batched matrix * broadcasted vector
599
-
>>> x = paddle.rand([10, 5, 2])
600
-
>>> y = paddle.rand([2])
601
-
>>> z = paddle.matmul(x, y)
602
-
>>> print(z.shape)
603
-
[10, 5]
604
-
605
-
>>> # batched matrix * batched matrix
606
-
>>> x = paddle.rand([10, 5, 2])
607
-
>>> y = paddle.rand([10, 2, 5])
608
-
>>> z = paddle.matmul(x, y)
609
-
>>> print(z.shape)
610
-
[10, 5, 5]
611
-
612
-
>>> # batched matrix * broadcasted matrix
613
-
>>> x = paddle.rand([10, 1, 5, 2])
614
-
>>> y = paddle.rand([1, 3, 2, 5])
615
-
>>> z = paddle.matmul(x, y)
616
-
>>> print(z.shape)
617
-
[10, 3, 5, 5]
618
-
619
-
""",
620
-
""" def matmul(
621
-
x: Tensor,
622
-
y: Tensor,
623
-
transpose_x: bool = False,
624
-
transpose_y: bool = False,
625
-
name: str | None = None,
626
-
*,
627
-
out: Tensor | None = None,
628
-
) -> Tensor""",
629
-
)
525
+
# add_doc_and_signature(
526
+
# "matmul",
527
+
# """
528
+
# Applies matrix multiplication to two tensors. `matmul` follows
529
+
# the complete broadcast rules,
530
+
# and its behavior is consistent with `np.matmul`.
531
+
532
+
# Currently, the input tensors' number of dimensions can be any, `matmul` can be used to
533
+
# achieve the `dot`, `matmul` and `batchmatmul`.
534
+
535
+
# The actual behavior depends on the shapes of :math:`x`, :math:`y` and the
536
+
# flag values of :attr:`transpose_x`, :attr:`transpose_y`. Specifically:
537
+
538
+
# - If a transpose flag is specified, the last two dimensions of the tensor
539
+
# are transposed. If the tensor is ndim-1 of shape, the transpose is invalid. If the tensor
540
+
# is ndim-1 of shape :math:`[D]`, then for :math:`x` it is treated as :math:`[1, D]`, whereas
541
+
# for :math:`y` it is the opposite: It is treated as :math:`[D, 1]`.
542
+
543
+
# The multiplication behavior depends on the dimensions of `x` and `y`. Specifically:
544
+
545
+
# - If both tensors are 1-dimensional, the dot product result is obtained.
546
+
547
+
# - If both tensors are 2-dimensional, the matrix-matrix product is obtained.
548
+
549
+
# - If the `x` is 1-dimensional and the `y` is 2-dimensional,
550
+
# a `1` is prepended to its dimension in order to conduct the matrix multiply.
551
+
# After the matrix multiply, the prepended dimension is removed.
552
+
553
+
# - If the `x` is 2-dimensional and `y` is 1-dimensional,
554
+
# the matrix-vector product is obtained.
555
+
556
+
# - If both arguments are at least 1-dimensional and at least one argument
557
+
# is N-dimensional (where N > 2), then a batched matrix multiply is obtained.
558
+
# If the first argument is 1-dimensional, a 1 is prepended to its dimension
559
+
# in order to conduct the batched matrix multiply and removed after.
560
+
# If the second argument is 1-dimensional, a 1 is appended to its
561
+
# dimension for the purpose of the batched matrix multiple and removed after.
562
+
# The non-matrix (exclude the last two dimensions) dimensions are
563
+
# broadcasted according the broadcast rule.
564
+
# For example, if input is a (j, 1, n, m) tensor and the other is a (k, m, p) tensor,
565
+
# out will be a (j, k, n, p) tensor.
566
+
567
+
# Args:
568
+
# x (Tensor): The input tensor which is a Tensor.
569
+
# y (Tensor): The input tensor which is a Tensor.
570
+
# transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication. Default is False.
571
+
# transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication. Default is False.
572
+
# name (str|None, optional): If set None, the layer will be named automatically. For more information, please refer to :ref:`api_guide_Name`. Default is None.
573
+
# out (Tensor, optional): The output tensor. If set, the result will be stored in this tensor. Default is None.
0 commit comments