-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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-2,A-4] Add type annotations for paddle/tensor/attribute.py
and paddle/tensor/einsum.py
#65255
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/tensor/einsum.py
Outdated
@@ -323,15 +336,26 @@ def plan_reduce(plan, op, reduce_dims, keepdim): | |||
plan.add_step(step) | |||
|
|||
|
|||
def plan_scalar_prod(plan, op1, op2): | |||
def plan_scalar_prod(plan: "Plan", op1: int, op2: int) -> 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.
使用 PEP 563 这里就不用引号了
python/paddle/tensor/einsum.py
Outdated
range(start, end)[::-1], range(s.start(), s.end())[::-1] | ||
): | ||
inv_map[ax] = dim | ||
assert r is not None, "Invalid equation: missing ellipsis in output labels." |
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.
这里能确保 r 不是 None 么?那下面的 if r
的 else 分支是干啥的?
python/paddle/tensor/manipulation.py
Outdated
@@ -3361,7 +3361,7 @@ def unique( | |||
return tuple(outs) | |||
|
|||
|
|||
def unsqueeze(x, axis, name=None): | |||
def unsqueeze(x, axis, name=None) -> paddle.Tensor: |
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.
输入也顺手标一下吧~
另外尽可能用
if TYPE_CHECKING:
from paddle import Tensor
然后标注直接用 Tensor
吧~
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.
我觉得不要为了类型标注而修改代码逻辑 ~ 如果不方便标注,实在不行就用 Any ~
如果最后总结的时候,发现有些地方标注不合适 (如 Any ),再推动修改代码 ~
@SigureMo 帮忙确认一下 ~
python/paddle/tensor/einsum.py
Outdated
assert r is not None, "Invalid equation: missing ellipsis in output labels." | ||
start, end = r.start(), r.end() | ||
s = re.search(r'\.+', in_labels) | ||
# fill the broadcast dimension indices from right to left. | ||
if s: | ||
for ax, dim in zip( | ||
range(start, end)[::-1], range(s.start(), s.end())[::-1] | ||
): | ||
inv_map[ax] = dim |
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.
不要改代码逻辑吧?
@@ -460,7 +460,7 @@ def create_parameter( | |||
|
|||
def create_variable_for_type_inference( | |||
self, dtype, stop_gradient=False, shape=None | |||
): | |||
) -> paddle.Tensor: |
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.
这个没啥关系,反正不是公开 API
python/paddle/tensor/einsum.py
Outdated
@@ -323,15 +336,26 @@ def plan_reduce(plan, op, reduce_dims, keepdim): | |||
plan.add_step(step) | |||
|
|||
|
|||
def plan_scalar_prod(plan, op1, op2): | |||
def plan_scalar_prod(plan: "Plan", op1: int, op2: int) -> 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.
from __future__ import annotations
不用引号 ~
paddle/tensor/attribute.py
and paddle/tensor/einsum.py
python/paddle/tensor/attribute.py
Outdated
@@ -13,6 +13,7 @@ | |||
# limitations under the License. | |||
|
|||
# TODO: define functions to get tensor attributes |
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.
TODO 删了吧~
python/paddle/tensor/attribute.py
Outdated
@@ -28,7 +29,7 @@ | |||
__all__ = [] | |||
|
|||
|
|||
def rank(input): | |||
def rank(input: paddle.Tensor) -> paddle.Tensor: |
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.
这个文件也一样直接用 Tensor 吧
paddle/tensor/attribute.py
and paddle/tensor/einsum.py
paddle/tensor/attribute.py
and paddle/tensor/einsum.py
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.
…y` and `paddle/tensor/einsum.py` (PaddlePaddle#65255) --------- Co-authored-by: Nyakku Shigure <[email protected]>
PR Category
User Experience
PR Types
Improvements
Description
添加类型提示
Related links