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

[Typing][B-02,B-04] Add type annotations for python/paddle/distribution/{bernoulli, binomial}.py #65727

Merged
merged 3 commits into from
Jul 13, 2024

Conversation

Asthestarsfalll
Copy link
Contributor

PR Category

User Experience

PR Types

Improvements

Description

Add type annotations for python/paddle/distribution/{bernoulli, binomial}.py:

Copy link

paddle-bot bot commented Jul 4, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Jul 4, 2024
@@ -67,7 +74,13 @@ class Binomial(distribution.Distribution):
[2.94053698, 3.00781751, 2.51124287])
"""

def __init__(self, total_count, probs):
dtype: DTypeLike
Copy link
Member

@SigureMo SigureMo Jul 4, 2024

Choose a reason for hiding this comment

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

这个应该是通过 get_default_dtype 得到的,应该是某一个类型而不是 Union

根据实现,应该是 _DTypeLiteral

可以顺手标注下 set_default_dtypeget_default_dtype 两个 API~(新增了 B-43


def __init__(
self, total_count: int | Tensor, probs: float | Tensor
) -> None:
self.dtype = paddle.get_default_dtype()
self.total_count, self.probs = self._to_tensor(total_count, probs)
Copy link
Member

Choose a reason for hiding this comment

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

下面的 _to_tensor 可以顺手标一下,文档里都给出类型了

另外我目测了下,返回值应该是 list[Tensor]?虽然确实是两个元素就是了,文档里写的可能并不准确

def __init__(self, probs, name=None):
name: str
probs: Tensor
logits: Tensor
Copy link
Member

Choose a reason for hiding this comment

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

看看 dtype 是不是也可以写下?

Copy link

paddle-ci-bot bot commented Jul 12, 2024

Sorry to inform you that 0739a08's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@SigureMo SigureMo merged commit de8725b into PaddlePaddle:develop Jul 13, 2024
30 of 32 checks passed
lixcli pushed a commit to lixcli/Paddle that referenced this pull request Jul 22, 2024
…ion/{bernoulli, binomial}.py` (PaddlePaddle#65727)


---------

Co-authored-by: SigureMo <sigure.qaq@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants