Skip to content

[Docathon][Add Inplace CN Doc No.31] #7187

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

Closed
Closed
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
2 changes: 2 additions & 0 deletions docs/api/paddle/Overview_cn.rst
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ tensor 数学操作原位(inplace)版本
" :ref:`paddle.normal_ <cn_api_paddle_normal_>` ", "Inplace 版本的 normal API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.neg_ <cn_api_paddle_neg_>` ", "Inplace 版本的 neg API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.nan_to_num_ <cn_api_paddle_nan_to_num_>` ", "Inplace 版本的 nan_to_num API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.logical_and_ <cn_api_paddle_logical_and_>` ", "Inplace 版本的 logical_and API,对输入 x 采用 Inplace 策略)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

移到上面的 log_normal_ 下吧

" :ref:`paddle.i0_ <cn_api_paddle_i0_>` ", "Inplace 版本的 i0 API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.lcm_ <cn_api_paddle_lcm_>` ", "Inplace 版本的 lcm API,对输入 x 采用 Inplace 策略"




.. _tensor_logic:

tensor 逻辑操作
Expand Down
50 changes: 50 additions & 0 deletions docs/api/paddle/logical_and__cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. _api_paddle_logical_and__cn:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. _api_paddle_logical_and__cn:
.. _cn_api_paddle_logical_and_:


logical_and_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logical_and_
logical\_and\_

需要转义

-------------------------------

.. py:function:: paddle.logical_and_(x: Tensor, y: Tensor, name: str|None = None) → Tensor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. py:function:: paddle.logical_and_(x: Tensor, y: Tensor, name: str|None = None) → Tensor
.. py:function:: paddle.logical_and_(x, y, name = None)


该 API 是 `paddle.logical_and` 的 **Inplace 版本**,输出结果将直接覆盖输入 Tensor ``x`` 的内存,功能与非 Inplace 版本一致。

逐元素对 ``x`` 和 ``y`` 进行逻辑与运算,计算公式为:

.. math::
\text{out}_i = \text{x}_i \ \&\& \ \text{y}_i

.. note::
**Inplace 警告**:此操作会直接修改输入 Tensor ``x`` 的值,若需保留原始数据,请使用非 Inplace 版本 `paddle.logical_and`。

**广播机制**:``x`` 和 ``y`` 的形状需满足广播规则,如您想了解更多,请参考tensor介绍 `<../../guides/beginner/tensor_cn.html#id7>`_。

参数
:::::::::
- **x** (Tensor) - 输入的 Tensor,支持的数据类型为 bool、int8、int16、int32、int64、bfloat16、float16、float32、float64、complex64、complex128。
- **y** (Tensor) - 输入的 Tensor,数据类型需与 ``x`` 一致。
- **name** (str|None, 可选) - 操作的名称,默认值为 None,表示自动命名。

返回
:::::::::
**Tensor**,与输入 ``x`` 共享内存的 Tensor,存储运算后的布尔值结果(直接覆盖 ``x``)。

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

.. code-block:: python

import paddle

# 示例 1:基础用法
x = paddle.to_tensor([True, False, True, False])
y = paddle.to_tensor([True, True, False, False])
paddle.logical_and_(x, y)
print(x) # 输出: [True, False, False, False]

# 示例 2:广播机制
x = paddle.to_tensor([[True], [False]])
y = paddle.to_tensor([True, False])
paddle.logical_and_(x, y) # 广播为 [[True, False], [False, False]]
print(x)
# 输出:
# [[True, False],
Comment on lines +8 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文档内容直接参考其他 inplace API 的写法,如

Inplace 版本的 :ref:`cn_api_paddle_clip` API,对输入 x 采用 Inplace 策略。
更多关于 inplace 操作的介绍请参考 `3.1.3 原位(Inplace)操作和非原位操作的区别`_ 了解详情。
.. _3.1.3 原位(Inplace)操作和非原位操作的区别: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/beginner/tensor_cn.html#id3

# [False, False]]