Skip to content

Conversation

MrXnneHang
Copy link
Contributor

@MrXnneHang MrXnneHang commented Nov 8, 2024

PR Category

User Experience

PR Types

New features

Description

新增paddle.positive, Tensor.__pos__,用于对Tensor进行正号操作。

Copy link

paddle-bot bot commented Nov 8, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Nov 8, 2024
Comment on lines 1501 to 1502
# In static mode, return a clone of the tensor
return x.clone()
Copy link
Contributor

Choose a reason for hiding this comment

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

这里return x.clone()的原因是?

Copy link
Contributor

Choose a reason for hiding this comment

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

竞品torch也是直接返回输入即可,不需要进行clone(),
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,是我最初对静态图计算的理解有点问题。

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

python/paddle/tensor/tensor.prototype.pyi __neg__ 附近也补一个 __pos__


# Check if the input tensor is of bool type and raise an error
if x.dtype == paddle.bool:
raise ValueError("The `+` operator, on a bool tensor is not supported.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise ValueError("The `+` operator, on a bool tensor is not supported.")
raise TypeError("The `+` operator, on a bool tensor is not supported.")

TypeError 吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok


Args:
x (Tensor): The input tensor. It must be a tensor with one of the following data types:
float16, float32, float64, int32, or int64.
Copy link
Member

Choose a reason for hiding this comment

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

这里没有 kernel,应该没有任何 dtype 限制?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我单测只加了这些,不过从代码看确实只有Bool不行。

Copy link
Contributor

Choose a reason for hiding this comment

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

Member

这里需要对bool进行限制,这是一个逻辑值,没有正负运算的概念,参考:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我用raise TypeError是否可以。或者有更好的方法

Copy link
Contributor

Choose a reason for hiding this comment

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

我用raise TypeError是否可以。或者有更好的方法

可以的,这里就用TypeError好了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@HydrogenSulfate HydrogenSulfate merged commit 6c14ff0 into PaddlePaddle:develop Nov 12, 2024
28 checks passed
@HydrogenSulfate HydrogenSulfate changed the title 【Paddle Tensor No.13】: 新增paddle.positive,新增Tensor.__pos__ 【Paddle Tensor No.13】: 新增paddle.positiveTensor.__pos__ Nov 12, 2024
@HydrogenSulfate
Copy link
Contributor

新增的接口paddle.positive麻烦在中文API文档(https://github.com/PaddlePaddle/docs)中也同步添加一下对应的文档信息,感谢~

@MrXnneHang
Copy link
Contributor Author

好的

@@ -1463,6 +1463,38 @@ def bitwise_invert_(x: Tensor, name: str | None = None) -> Tensor:
return bitwise_not_(x, name=name)


def positive(x: Tensor) -> Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

这个函数能否移动到python/paddle/tensor/math.py里?我觉得放在logic.py里不太合适,因为logic.py里面都是与布尔逻辑判断相关的,而math.py有一个和positive对应的paddle.neg函数

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以,我再提一个PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants