CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
【Paddle Tensor No.21】:新增 bitwise_invert
,复用已有接口 Tenosr.__invert__
-part
#69197
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提交成功,感谢你对开源项目的贡献! |
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,可以根据review建议稍作修改
python/paddle/tensor/__init__.py
Outdated
@@ -850,4 +850,5 @@ | |||
('__or__', 'bitwise_or'), | |||
('__xor__', 'bitwise_xor'), | |||
('__invert__', 'bitwise_not'), | |||
('bitwise_invert', 'bitwise_not'), |
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.
bitwise_invert
不是一个魔术方法,根据其语义,不应该放在这里,它是与bitwise_right_shift
同类的位运算,因此应该参考bitwise_right_shift的做法,即需要修改这三个文件
,添加的bitwise_invert直接调用bitwise_not即可,并补充docstring。另外需要提交一个文档PR到:https://github.com/PaddlePaddle/docs/blob/develop/docs/api/paddle/Tensor_cn.rst,这样英文和中文文档都能看到这个API
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/logic.py
Outdated
|
||
>>> import paddle | ||
>>> x = paddle.to_tensor([-5, -1, 1]) | ||
>>> res = paddle.bitwise_invert(x) |
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.
这个样例应该是调用x.bitwise_invert
>>> res = paddle.bitwise_invert(x) | |
>>> res = x.bitwise_invert() |
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.
这两个实际运行起来中间会有什么细微差别吗。
我记得torch那边也是,一个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.
一个是Tensor类的方法,一个是paddle模块下的函数,Python的接口不同调用方式不同,底层都是调用同一个kernel
@@ -204,6 +204,7 @@ class AbstractTensor: | |||
# unary arithmetic operations | |||
def __invert__(self) -> Tensor: ... | |||
def __neg__(self) -> Tensor: ... | |||
def bitwise_invert(self) -> 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.
这个有源码,应该可以自动生成,不用手动添加~
@@ -244,6 +244,7 @@ | |||
allclose, | |||
bitwise_and, | |||
bitwise_and_, | |||
bitwise_invert, |
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.
bitwise_not
有 inplace 版本 bitwise_not_
,bitwise_invert
应该没什么不同,也应该有 bitwise_invert_
可在 test/legacy_test/test_inplace.py
添加相关单测
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.
这里只能测到静态图,通过 Tensor method 路径调用的,可以在 test/legacy_test/test_bitwise_op.py
补充下动态图直接跑的测试 case,不需要继承 OpTest
,直接继承 unittest.TestCase
写一个简单的 case 验证下即可
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.
这个我不是很确定行不行.
5ae2f93
def test_bitwise_invert_in_place(self): | ||
x_copy = self.x.clone() | ||
x_copy.bitwise_invert_() | ||
np.testing.assert_array_equal(x_copy.numpy(), self.expected_out) |
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.
@MrXnneHang 考虑报名一下启航计划嘛 |
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
描述里可以链接上相关 issue、PR,比如本 PR 要链接任务 issue #69082、中文文档 PaddlePaddle/docs#6932 中文文档那边相应链接过来 这样相互之间引用关系会很清晰~ |
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
bitwise_invert
,复用已有接口 Tenosr.__invert__
-part
PR Category
User Experience
PR Types
New features
Description
Paddle Tensor 规范化:新增 Tensor.bitwise_invert,复用已有接口
Tenosr.__invert__
.https://data-apis.org/array-api/latest/API_specification/generated/array_api.bitwise_invert.html