Skip to content
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

Merged
merged 17 commits into from
Dec 17, 2020

Conversation

MingMingShangTian
Copy link
Contributor

@MingMingShangTian MingMingShangTian commented Dec 9, 2020

PR types

New features

PR changes

OPs

Describe

add conjugate op for complex types

image

@paddle-bot-old
Copy link

paddle-bot-old bot commented Dec 9, 2020

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

# [(4-4j), (5-5j), (6-6j)]])

"""
check_type(input, 'input', (Variable, tuple, list), 'conj')
Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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)
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/fluid/tests/unittests/test_complex_conj.py Outdated Show resolved Hide resolved
namespace paddle {
namespace operators {

using framework::OpKernelType;
Copy link
Contributor

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?

OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "conj");

auto in_dims = ctx->GetInputDim("X");
auto outs_names = ctx->Outputs("Out");
Copy link
Contributor

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?

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)));
Copy link
Contributor

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?

This function computes the conjugate of the Tensor elementwisely.

Args:
input (list): A list of Variables which hold input Tensors with the same
Copy link
Contributor

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?

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. \
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable -> Tensor

paddle/fluid/operators/mean_op.cc Outdated Show resolved Hide resolved
python/paddle/fluid/tests/unittests/op_test.py Outdated Show resolved Hide resolved
python/paddle/tensor/math.py Outdated Show resolved Hide resolved
chenwhql
chenwhql previously approved these changes Dec 16, 2020
Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

lanxianghit
lanxianghit previously approved these changes Dec 16, 2020
This function computes the conjugate of the Tensor elementwisely.

Args:
x (Tensor): The input thensor which hold the complex numbers.
Copy link
Contributor

Choose a reason for hiding this comment

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

thensor -> tensor

Copy link
Contributor

@TCChenlong TCChenlong left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@lanxianghit lanxianghit left a comment

Choose a reason for hiding this comment

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

LGTM

@chenwhql chenwhql merged commit 71063b8 into PaddlePaddle:develop Dec 17, 2020
@MingMingShangTian MingMingShangTian deleted the complex_conj branch December 18, 2020 02:33
chenwhql pushed a commit to chenwhql/Paddle that referenced this pull request Dec 18, 2020
* 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
lanxianghit pushed a commit that referenced this pull request Dec 18, 2020
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants