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 new API "eigvals" in linalg #35720

Merged
merged 15 commits into from
Sep 17, 2021

Conversation

From00
Copy link
Contributor

@From00 From00 commented Sep 14, 2021

PR types

New features

PR changes

APIs

Describe

Add a new API: linalg.eigvals

The corresponding PR for CN docs:PaddlePaddle/docs#3875

NOTE

  1. The gradient kernel of this operator does not yet develop.
  2. This PR does not implement the CUDA kernel. If the API is called by a GPU tensor, Paddle will report an error.
  3. This PR implements the linalg.eigvals API with the Eigen library, which will be replaced by the Lapack library in the future.

image
image

@paddle-bot-old
Copy link

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

.. code-block:: python

import paddle

Copy link
Contributor

Choose a reason for hiding this comment

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

Add paddle.seed(x) to fix output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 35 to 50
def np_eigvals_grad(a, out_grad):
l, v = np.linalg.eig(a)
print("l:")
print(l)
print("v:")
print(v)
vh = v.conj().T
print("vh:")
print(vh)
print("out_grad:")
print(out_grad)
a_grad = np.linalg.solve(vh, np.diagflat(out_grad, 0) * vh)
print("a_grad")
print(a_grad)

return a_grad.astype(a.dtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems no usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been commented out.

template <typename T>
using EigenVectorStd = Eigen::Matrix<StdCType<T>, Eigen::Dynamic, 1>;

static void SpiltBatchSquareMatrix(const Tensor *input,
Copy link
Contributor

Choose a reason for hiding this comment

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

Better use const& for input

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@From00 From00 changed the title Add new API linalg.eigvals Add new API eigvals in linalg Sep 15, 2021
@From00 From00 changed the title Add new API eigvals in linalg Add new API "eigvals" in linalg Sep 15, 2021
zhiqiu
zhiqiu previously approved these changes Sep 17, 2021
Copy link
Contributor

@zhiqiu zhiqiu 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

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LG API

Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM for set_tests_properties(test_eigvals_op PROPERTIES TIMEOUT 400)

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
TODO:
1、补充中文文档&中英文API文档预览图
2、示例代码中不需要set_device这一行

@zhiqiu zhiqiu merged commit d411a03 into PaddlePaddle:develop Sep 17, 2021
AnnaTrainingG pushed a commit to AnnaTrainingG/Paddle that referenced this pull request Sep 29, 2021
* Add linalg.eigvals API

* pre-commit check

* Adjust code style

* Fix conflict

* Improve code style

* Modify the test code to ignore testing CUDA kernel

* Sort ouput data before checking in test code

* Set timeout value for UT

* Improve API example code to pass CI

* Fix bug for None fetch_list in Windows

* Delete grad Op
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.

5 participants