-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 conj op for complex types #29527
add conj op for complex types #29527
Conversation
Thanks for your contribution! |
python/paddle/tensor/math.py
Outdated
# [(4-4j), (5-5j), (6-6j)]]) | ||
|
||
""" | ||
check_type(input, 'input', (Variable, tuple, list), 'conj') |
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.
这里注意下写法要分动静态图,现在这样写动态图性能会受影响,https://github.com/PaddlePaddle/Paddle/wiki/paddle_api_development_manual.md
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.
这里应该只支持Variable,包括后面的检查,需要再修改下
elif tensor_to_check_dtype == np.complex64: | ||
return tensor._get_complex64_element(i) | ||
elif tensor_to_check_dtype == np.complex128: | ||
return tensor._get_complex128_element(i) | ||
else: | ||
return tensor._get_double_element(i) |
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.
建议把else单独抛出异常,double的判断还放到上面,类似:
elif tensor_to_check_dtype == np.float64:
tensor._set_double_element(i, e)
elif tensor_to_check_dtype == np.complex64:
tensor._set_complex64_element(i, e)
elif tensor_to_check_dtype == np.complex128:
tensor._set_complex128_element(i, e)
else:
raise TypeError("Unsupported test data type %s." %
tensor_to_check_dtype)
elif tensor_to_check_dtype == np.complex64: | ||
tensor._set_complex64_element(i, e) | ||
elif tensor_to_check_dtype == np.complex128: | ||
tensor._set_complex128_element(i, e) |
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.
同上
paddle/fluid/operators/conj_op.cc
Outdated
namespace paddle { | ||
namespace operators { | ||
|
||
using framework::OpKernelType; |
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.
remove these two using
declaration?
paddle/fluid/operators/conj_op.cc
Outdated
OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "conj"); | ||
|
||
auto in_dims = ctx->GetInputDim("X"); | ||
auto outs_names = ctx->Outputs("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.
this out_names
is useless?
paddle/fluid/operators/conj_op.h
Outdated
void Compute(const framework::ExecutionContext& context) const override { | ||
const Tensor* x = context.Input<Tensor>("X"); | ||
Tensor* out = context.Output<Tensor>("Out"); | ||
out->mutable_data<T>(context.GetPlace(), size_t(x->numel() * sizeof(T))); |
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.
here only need one mutable_data?
python/paddle/tensor/math.py
Outdated
This function computes the conjugate of the Tensor elementwisely. | ||
|
||
Args: | ||
input (list): A list of Variables which hold input Tensors with the same |
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.
here is input (Tensor)
? why list?
python/paddle/tensor/math.py
Outdated
user to set this property. For more information, please refer to :ref:`api_guide_Name` | ||
|
||
Returns: | ||
out (Variable): The conjugate of inputs. The shape and data type is the same with input. \ |
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.
Variable
-> 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.
LGTM
python/paddle/tensor/math.py
Outdated
This function computes the conjugate of the Tensor elementwisely. | ||
|
||
Args: | ||
x (Tensor): The input thensor which hold the complex numbers. |
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.
thensor -> tensor
b5ee789
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
* add conj op for complex types * add conj for complex types * add more test case * add conj_op test * modify conj api and impl * add complex type for fill_constant_op xpu * add setConstant for complex type * remove complex conj test file * user define grad for test_conj_op * add test case for static mode of conj api * modify conj doc * change input args name to x * remove useless codes * conj support real types * add conj test case for real number
* Add complex dtype op (add) test example (#29603) * add op test case for complex * polish code details * add xpu set constant support * fix argument rror * remove useless pyc file * [Complex] Add real & imag op and api for complex tensor (#29672) * add complex real op & api & unittest * add imag op & api & unittest * refactor op impl * revert simplify writing due to complile failed * polish details * polish grad op code * add conj op for complex types (#29527) * add conj op for complex types * add conj for complex types * add more test case * add conj_op test * modify conj api and impl * add complex type for fill_constant_op xpu * add setConstant for complex type * remove complex conj test file * user define grad for test_conj_op * add test case for static mode of conj api * modify conj doc * change input args name to x * remove useless codes * conj support real types * add conj test case for real number Co-authored-by: chentianyu03 <[email protected]>
PR types
New features
PR changes
OPs
Describe
add conjugate op for complex types