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

Support new API linalg.cond in paddle #35140

Merged
merged 18 commits into from
Sep 16, 2021
Merged

Support new API linalg.cond in paddle #35140

merged 18 commits into from
Sep 16, 2021

Conversation

haohongxiang
Copy link
Contributor

@haohongxiang haohongxiang commented Aug 25, 2021

PR types

New features

PR changes

APIs

Describe

Support new API 'paddle.linalg.cond' in static/dynamic mode, which can be also called by 'paddle.cond'.

Its doc PR in Chinese is available at PR-3849

docs_cn:
image

Example :

import paddle
import numpy as np

np_input = [[1., 0, -1], [0, 1, 0], [1, 0, 1]]
x = paddle.to_tensor(np_input)

out = paddle.linalg.cond(x)
# out.numpy() [1.41421342]

out_fro = paddle.linalg.cond(x, p='fro')
# out_fro.numpy() [3.16227770]

out_nuc = paddle.linalg.cond(x, p='nuc')
# out_nuc.numpy() [9.24263859]

out_1 = paddle.linalg.cond(x, p=1)
# out_1.numpy() [2.]

out_minus_2 = paddle.linalg.cond(x, p=-2)
# out_minus_2.numpy() [0.70710683]

out_inf = paddle.linalg.cond(x, p=np.inf)
# out_inf.numpy() [2.]

@paddle-bot-old
Copy link

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

ForFishes
ForFishes previously approved these changes Sep 8, 2021
Copy link
Member

@ForFishes ForFishes left a comment

Choose a reason for hiding this comment

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

LGTM

from .tensor.linalg import matrix_power # noqa: F401
from .tensor import inverse as inv # noqa: F401
from .tensor.linalg import svd

__all__ = [
'cholesky', #noqa
'norm',
'cond',
Copy link
Contributor

Choose a reason for hiding this comment

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

这里应该和 paddle/init.py 里的 96&496行冲突了,不能同时在两个 all

Copy link
Contributor

Choose a reason for hiding this comment

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

1个API可以有多个别名,但是开放的推荐位置是设计时就唯一确定,比如这个API开放的推荐位置是 paddle.linalg.cond,则其只能加入到相应位置(这里为python/paddle/linalg.py中)的 all 列表中,不能加入到其它的__all__ 列表。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,已在python/paddle/init.py中的__all__列表中将'cond'删去了。

import paddle
import numpy as np
np_input = [[1., 0, -1], [0, 1, 0], [1, 0, 1]]
x = paddle.to_tensor(np_input)
Copy link
Contributor

Choose a reason for hiding this comment

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

567 -> 569 直接改为 x = paddle.to_tensor([[1., 0, -1], [0, 1, 0], [1, 0, 1]]) 即可

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

@@ -492,6 +493,7 @@
'expand_as',
'stack',
'sqrt',
'cond',
Copy link
Contributor

Choose a reason for hiding this comment

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

这里不推荐加入到__all__列表,推荐加入到 python/paddle/linalg.py中的__all__列表,原因在下面解释

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

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 for docs

Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

lgtm

@ForFishes ForFishes merged commit 2df74aa into PaddlePaddle:develop Sep 16, 2021
AnnaTrainingG pushed a commit to AnnaTrainingG/Paddle that referenced this pull request Sep 29, 2021
* Support new API linalg.cond in paddle

* check code style

* check code style

* modify codes

* add docs_eng of linalg.cond

* add svd_norm for linalg.cond

* modify docs_en of cond

* add support for empty input in dynamic mode

* modify set_time of unittest

* update

* modify unittest of cond

* update

* remove cond in paddle.__all__

* pull latest codes

* merge latest codes

* update
@haohongxiang haohongxiang deleted the mydev branch October 25, 2021 08:19
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