CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
【Paddle Tensor No.13】: 新增paddle.positive
和Tensor.__pos__
#69256
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/tensor/logic.py
Outdated
# In static mode, return a clone of the tensor | ||
return x.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里return x.clone()的原因是?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,是我最初对静态图计算的理解有点问题。
There was a problem hiding this 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__
吧
python/paddle/tensor/logic.py
Outdated
|
||
# 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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ValueError("The `+` operator, on a bool tensor is not supported.") | |
raise TypeError("The `+` operator, on a bool tensor is not supported.") |
用 TypeError
吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
python/paddle/tensor/logic.py
Outdated
|
||
Args: | ||
x (Tensor): The input tensor. It must be a tensor with one of the following data types: | ||
float16, float32, float64, int32, or int64. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没有 kernel,应该没有任何 dtype 限制?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我单测只加了这些,不过从代码看确实只有Bool不行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我用raise TypeError是否可以。或者有更好的方法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我用raise TypeError是否可以。或者有更好的方法
可以的,这里就用TypeError好了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
paddle.positive
和Tensor.__pos__
新增的接口 |
好的 |
@@ -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: |
There was a problem hiding this comment.
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
函数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以,我再提一个PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Category
User Experience
PR Types
New features
Description
新增
paddle.positive
,Tensor.__pos__
,用于对Tensor进行正号操作。