Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docathon][Add API Legend No.2] #69266

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,19 @@ def broadcast_tensors(

.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor

The following figure illustrates the process of broadcasting three tensors to the same dimensions.
The dimensions of the three tensors are [4, 1, 3], [2, 3], and [4, 2, 1], respectively. During broadcasting,
alignment starts from the last dimension, and for each dimension, either the sizes of the two tensors in that dimension are equal,
or one of the tensors has a dimension of 1, or one of the tensors lacks that dimension. In the figure below, in the last dimension,
Tensor3 has a size of 1, while Tensor1 and Tensor2 have sizes of 3; thus, this dimension is expanded to 3 for all tensors.
In the second-to-last dimension, Tensor1 has a size of 2, and Tensor2 and Tensor3 both have sizes of 2; hence, this dimension is expanded to 2 for all tensors.
In the third-to-last dimension, Tensor2 lacks this dimension, while Tensor1 and Tensor3 have sizes of 4; consequently,
this dimension is expanded to 4 for all tensors. Ultimately, all tensors are expanded to [4, 2, 3].
.. image:: https://githubraw.cdn.bcebos.com/PaddlePaddle/docs/develop/docs/images/api_legend/broadcast.png
sunzhongkai588 marked this conversation as resolved.
Show resolved Hide resolved
:width: 800
:alt: Illustration of BroadCast
:align: center
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved

Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
Args:
input (list|tuple): ``input`` is a Tensor list or Tensor tuple which is with data type bool,
float16, float32, float64, int32, int64, complex64, complex128. All the Tensors in ``input`` must have same data type.
Expand Down