Skip to content

[API Compatibility] Add view_as_complex and view_as_real #7377

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 additions & 0 deletions docs/api/paddle/view_as_complex_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. _cn_api_paddle_view_as_complex:

view_as_complex
-------------------------------

.. py:function:: paddle.view_as_complex(input)


获取实数张量 ``input`` 的一个视图,将其视为一个复数张量。

输入 Tensor 的数据类型是 'float32' 或者 'float64',输出 Tensor 的数据类型相应为 'complex64' 或者 'complex128'。

输入 Tensor 的形状是 ``(*, 2)`` (其中 ``*`` 表示任意形状),亦即,输入的最后一维的大小必须是 2,这对应着复数的实部和虚部。输出 Tensor 的形状是 ``(*,)``。

下图展示了一个 view_as_complex 简单的使用情形。一个形状为[2, 3, 2]的实数 Tensor 经过 view_as_complex 转换,最后一个长度为 2 的维度被合并为复数,形状变为[2, 3]。

返回的复数张量是输入实数张量的一个视图,这意味着二者共享同一块内存区域。

.. figure:: ../../images/api_legend/as_complex.png
:alt: view_as_complex 图示
:width: 500
:align: center
参数
:::::::::
- **input** (Tensor) - 输入 Tensor,数据类型为:float32 或 float64。

返回
:::::::::
输出 Tensor,数据类型是 'complex64' 或 'complex128',与 ``input`` 的数值精度一致。

代码示例
:::::::::

COPY-FROM: paddle.view_as_complex
35 changes: 35 additions & 0 deletions docs/api/paddle/view_as_real_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _cn_api_paddle_view_as_real:

view_as_real
-------------------------------

.. py:function:: paddle.view_as_real(input)


获取复数张量 ``input`` 的一个视图,将其视为一个实数张量。

输入 Tensor 的数据类型是 'complex64' 或者 'complex128',输出 Tensor 的数据类型相应为 'float32' 或者 'float64'。

输入 Tensor 的形状是 ``(*,)`` (其中 ``*`` 表示任意形状),输出 Tensor 的形状是 ``(*, 2)``,亦即,输出的形状是在输入形状后附加一个 ``2``,因为一个复数的实部和虚部分别表示为一个实数。

返回的实数张量是输入复数张量的一个视图,这意味着二者共享同一块内存区域。

下图展示了一个 view_as_real 简单的使用情形。一个形状为[2, 3]的复数 Tensor 经过 view_as_real 转换,拆分出一个长度为 2 的维度,形状变为[2, 3, 2]。

.. figure:: ../../images/api_legend/as_real.png
:alt: view_as_real 图示
:width: 500
:align: center

参数
:::::::::
- **input** (Tensor) - 输入 Tensor,数据类型为:'complex64' 或 'complex128'。

返回
:::::::::
输出 Tensor,数据类型是 'float32' 或 'float64',与 ``input`` 共享同一块内存区域。

代码示例
:::::::::

COPY-FROM: paddle.view_as_real