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

Conversation

QuarryFlow
Copy link
Contributor

@QuarryFlow QuarryFlow commented Mar 30, 2025

描述
paddle.logical_and_ 添加中文文档

增加
logical_and__cn.rst文件

修改
在Overview_cn.rst中新增新添加的API相关信息(在“tensor 数学操作原位(inplace)版本”标题下)

issue
Issue #7090

英文文档

logic_and_en: https://www.paddlepaddle.org.cn/documentation/docs/en/develop/api/paddle/logical_and__en.html

@sunzhongkai588 感谢审阅

Copy link

paddle-bot bot commented Mar 30, 2025

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7187.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

@CLAassistant
Copy link

CLAassistant commented Mar 30, 2025

CLA assistant check
All committers have signed the CLA.

@QuarryFlow QuarryFlow changed the title Add Chinese doc for paddle.logical_and_ [Docathon][Add Inplace CN Doc No.31] Mar 30, 2025
Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

可以参考一下别的 PR 是怎么改的 #7108

Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

参考一下别的 PR 是怎么改的 #7108

@QuarryFlow
Copy link
Contributor Author

QuarryFlow commented Apr 2, 2025

参考一下别的 PR 是怎么改的 #7108

好的,已修改,请再次审阅,谢谢

@@ -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_:

@@ -0,0 +1,50 @@
.. _api_paddle_logical_and__cn:

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\_

需要转义

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)

Comment on lines +8 to +49
该 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],
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

@@ -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_ 下吧

@Echo-Nie
Copy link
Contributor

@luotao1 The PR can be closed due to the following PR is merged:

@luotao1 luotao1 closed this Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants