Skip to content

Add type annotations to forward method in example code - #179

Draft
Lang-Qiu wants to merge 1 commit into
freud14:masterfrom
Lang-Qiu:auto-pr/type_annotations-1780784947
Draft

Add type annotations to forward method in example code#179
Lang-Qiu wants to merge 1 commit into
freud14:masterfrom
Lang-Qiu:auto-pr/type_annotations-1780784947

Conversation

@Lang-Qiu

@Lang-Qiu Lang-Qiu commented Jun 6, 2026

Copy link
Copy Markdown

问题背景

slides/src/code/example_pytorch.py 中的 MnistLogistic 类的 forward 方法缺少参数和返回值类型注解。这降低了代码的可读性和可维护性,并且不符合Python类型提示的最佳实践。

修改内容

  • forward 方法的参数 xb 添加了 torch.Tensor 类型注解。
  • forward 方法的返回值添加了 torch.Tensor 类型注解。

验证方式

  • 这是一个示例代码,因此主要确保代码语法正确,并且类型注解与PyTorch兼容。
  • 可以通过运行Python解释器或使用类型检查工具如mypy来验证类型正确性,但作为示例代码,重点是保持代码清晰和一致性。

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.

2 participants