-
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
[Typing][A-3] Add type annotations for paddle/tensor/creation.py
#65082
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/tensor/creation.py
Outdated
""" | ||
This function creates a new tensor variable with value in the global block(block 0). | ||
|
||
Args: | ||
shape (list[int]|tuple[int]): Shape of the variable | ||
shape (ShapeLike): Shape of the variable |
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.
这里 ShapeLike
不暴露给用户吧
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.
done
python/paddle/tensor/creation.py
Outdated
@@ -2921,14 +3034,16 @@ def polar(abs, angle, name=None): | |||
|
|||
|
|||
@dygraph_only | |||
def cauchy_(x, loc=0, scale=1, name=None): | |||
def cauchy_( | |||
x: paddle.Tensor, loc=0, scale=1, name: str | None = None |
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.
是不是漏了俩 :doge:
python/paddle/tensor/creation.py
Outdated
@@ -2955,14 +3070,16 @@ def cauchy_(x, loc=0, scale=1, name=None): | |||
|
|||
|
|||
@dygraph_only | |||
def geometric_(x, probs, name=None): | |||
def geometric_( | |||
x: paddle.Tensor, probs, name: str | None = None |
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.
probs 也漏了?
Co-authored-by: Nyakku Shigure <[email protected]>
Co-authored-by: Nyakku Shigure <[email protected]>
Co-authored-by: Nyakku Shigure <[email protected]>
python/paddle/tensor/creation.py
Outdated
@@ -1079,7 +1134,9 @@ def ones_like(x, dtype=None, name=None): | |||
return full_like(x=x, fill_value=1, dtype=dtype, name=name) | |||
|
|||
|
|||
def zeros(shape, dtype=None, name=None): | |||
def zeros( | |||
shape: ShapeLike, dtype: DTypeLike | None = None, name: str | None = None |
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.
2024-06-13 00:06:49 paddle.zeros:1
2024-06-13 00:06:49 <string>:8:28: error: Argument "shape" to "zeros" has incompatible type "List[Tensor]"; expected "Union[Tuple[int, ...], List[int], Tensor]" [arg-type]
看样子是动态 shape 挂了,这里可以不改,直接这样就好,我们改一下 ShapeLike
-DynamicShapeLike: TypeAlias = Union[
+_DynamicShapeLike: TypeAlias = Union[
- Tuple[Union[int, "Tensor", None], ...],
- List[Union[int, "Tensor", None]],
+ Sequence[Union[int, "Tensor", None]],
"Tensor",
]
-ShapeLike: TypeAlias = Union[
+_StaticShapeLike: TypeAlias = Union[
- Tuple[int, ...],
- List[int],
+ Sequence[int],
"Tensor",
]
+ShapeLike: TypeAlias = Union[_DynamicShapeLike, _StaticShapeLike]
非 dynamic 的情况基本是没有意义的
python/paddle/tensor/creation.py
Outdated
@@ -1136,7 +1137,9 @@ def ones_like( | |||
|
|||
|
|||
def zeros( | |||
shape: ShapeLike, dtype: DTypeLike | None = None, name: str | None = None | |||
shape: DynamicShapeLike, |
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.
这咋和说的不一样 😂
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.
Static Check 结果需要看一下, |
python/paddle/tensor/creation.py
Outdated
>>> array = np.array([[1, 1], | ||
... [3, 4], | ||
... [1, 3]]).astype(np.int64) | ||
>>> array: npt.NDArray[Any] = np.array([[1, 1], [3, 4], [1, 3]]).astype( |
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.
这里还是加 # type: ignore
吧 ~ 不然一个简单的例子搞这么复杂,不太友好 ~
@SigureMo 看看行不?后面可以一块儿清理 ~
PaddlePaddle/docs#6680 用来处理渲染的问题 ~
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.
嗯嗯,可以~
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 reverts commit aec0894.
@megemini 有一个奇怪的问题,使用
确认只有多进程才会有这个问题,感觉有点奇怪,目前只有这个 API 遇到了,可以低优看看 |
我这里确实没遇到 type checking 的时候抛段错误 ~ 我先记一下吧,关联 #65190 (comment) |
啊……还是冲突了,可以解决一下,应该恢复相关文件的修改就可以了~ |
啊 我来搞一下吧 |
…addlePaddle#65082) --------- Co-authored-by: Nyakku Shigure <[email protected]>
PR Category
User Experience
PR Types
Improvements
Description
@megemini
Related links