-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
add as_complex and as_real op #37784
Conversation
Thanks for your contribution! |
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
|
||
const framework::DDim out_dims(in_dims.Get(), input_rank - 1); | ||
ctx->SetOutputDim("Out", out_dims); | ||
ctx->ShareLoD("X", /*->*/ "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.
实数和对应的复数的lod是一样的吗?
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.
实数和复数的 lod 是一样的。
对于 LoDTensor 来说,view_as_complex 和 view_as_real 直接操作 LoD Tensor 的 underlying Tensor.
比如说一个 underlying 形状为 (L, *base_shape)
的 复数 LoDTensor 来说,经过 view_as_real 会得到一个 LoD Tensor, 其 underlying Tensor 形状为 (L, *base_shape, 2)
。
而 LoD 信息表示的是递归折叠的端点信息。只要一个操作是局限在 base_shape
内部的操作,那么是不会改变 LoD 信息的,而复数和实数的互相 view,对于复数来说是 element 级别的操作,所以不会改变 LoD 信息。
对于 view_as_complex 来说,因为对输入 Tensor 形状有要求。假定为 (L, *base_shape)
, 那么每两个相邻的元素为一个单元视作复数,这个操作也不会跨越 base_shape, 所以不会改变 LoD 信息。
return np.stack([x.real, x.imag], -1) | ||
|
||
|
||
class TestViewAsComplexOp(OpTest): |
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.
请参考test_view_op_reuse_allocation.py
单测,测试下这两个API的view机制是否真的生效(改变输入输出中的某一个tensor值,另一个也会随之改变),同时也测下inplace version等信息。
可以直接在test_view_op_reuse_allocation.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.
okay
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.
加上了测试内存复用机制的单测 case.
…input's allocation
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
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
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
a856076
a856076
to
0bff2f4
Compare
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
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
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.
LG API
9dcbf5c
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 For API Docs
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
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
PR types
New features
PR changes
OPs
Describe
as_complex
andas_real
API, and corresponding operators.examples