- MindSpore Python代码注释遵循[Google Python Style Guide](https://google.github.io/styleguide/pyguide.html),由Sphinx工具自动生成API文档,注释样例和支持情况可参考[Example Google Style Python Docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html)和[Support for NumPy and Google style docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html)。
- MindSpore Python code comments comply with [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html). An API document is automatically generated by the Sphinx tool. For comment examples and support details, see [Example Google Style Python Docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html) and [Support for NumPy and Google style docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html).
- MindSpore C++ code needs to be compiled in Markdown files based on the namespace design.
@@ -26,7 +27,7 @@
The comments of classes and methods are in the following format:
```
```rst
Summary.
More elaborate description.
@@ -34,12 +35,12 @@ More elaborate description.
Note:
Description.
Args:
Args:
Arg1 (Type): Description. Default: xxx.
Arg2 (Type): Description.
- Sub-argument1 or Value1 of Arg2: Description.
- Sub-argument2 or Value2 of Arg2: Description.
- Sub-argument1 or Value1 of Arg2: Description.
- Sub-argument2 or Value2 of Arg2: Description.
Returns:
Type, description.
@@ -52,6 +53,7 @@ Examples:
```
The format items are described as follows:
- `Summary`: briefly describes the API function.
- `More elaborate description`: describes the function and usage of an API in detail.
- `Note`: describes precautions for using an API. Do not use `Notes`.
@@ -61,7 +63,8 @@ The format items are described as follows:
- `Examples`: sample code
For comments of operators and cells, add `Inputs` and `Outputs` before `Examples` to describe the input and output types and shapes of the operators after instantiation. The input name can be the same as that in the example. It is recommended that the corresponding mathematical formula be provided in the comment.
```
```rst
Inputs:
- **input_name1** (Type) - Description.
- **input_name2** (Type) - Description.
@@ -71,6 +74,7 @@ Outputs:
```
### Precautions
- Overall Requirements
- The comment items required for a class or method are as follows: `Summary`, `Args`, `Returns`, and `Raises`. If a function does not contain related information (such as `Args`, `Returns`, and `Raises`), do not write None (for example, `Raises: None`), but directly omit the comment item.
- When an API is generated by directory, the comments in the \_\_init\_\_ file header are displayed at the beginning of the web page. When an API is generated by file, the comments at the beginning of the file are displayed at the beginning of the web page. The comments must contain the overall description of the corresponding modules.
@@ -90,96 +94,113 @@ Outputs:
- If the return value type or dimension changes, describe the relationship between the return value and the input.
- If there are multiple return values, write them in different lines. The line difference is not displayed on the web page. The unordered list supports return values in different lines.
- `Examples` Comment
- For the content in `Examples`, add ```>>> ``` at the beginning of each line of code (including empty lines). It should not be added to the output result.
- For the content in `Examples`, add ```>>>``` at the beginning of each line of code, and add ```...``` at the beginning of each line of multiple lines of code (including class or function definitions, artificial line breaks, etc.) or empty lines. No sign is required at the beginning of the output result line.
- Actual code needs to be provided in `Examples`. If you need to refer to other Examples, use Note.
- The comments of the ops operator are written in PyNative mode. If the operator can be executed, the execution result must be provided.
- Import can be omitted in the case of industry consensus, such as np and nn.
- If the import path is long or a user-defined alias is required, add `from xxx import xxx as something` or `import xxx`. If the import path is short, place it in the code.
- `Inputs` and `Outputs` Comment
- If the data type is Tensor, describe the shape in the format of :math:`(N, C, X)`.
- Formula
- Line formula (in the middle of the singly occupied line)
```
.. math::
formula
```
```rst
.. math::
formula
```
- Line-embedded formula (displayed together with other peer text, not in the middle)
```
xxx :math:`formula` xxx
```
```rst
xxx :math:`formula` xxx
```
- If the formula contains an underscored variable and the underscore is followed by multiple letters (for example, xxx_yyy) , select one of the following methods based on the site requirements:
1. Multiple letters are enclosed in braces ({}), for example, xxx_{yyy}. The content following the underscore can be used as the subscript, which is displayed as $xxx_{yyy}$.
2. If a backslash (\\) is added before an underscore (_), for example, xxx\\_yyy, the complete variable name is displayed as xxx_yyy.
- Parent Class Method Display
- By default, the parent class method is not displayed.
- You can add `:inherited-members:` to the module of the RST file in the Sphinx project to specify the parent class method to be displayed. For details, see <https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>.
- By default, the parent class method is not displayed.
- You can add `:inherited-members:` to the module of the RST file in the Sphinx project to specify the parent class method to be displayed. For details, see <https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>.
- Link
- Only the title (such as the name in the following example) is displayed. The detailed address is not displayed.
- Only the title (such as the name in the following example) is displayed. The detailed address is not displayed.
Write a quotation in the following format:
```
`name`_
```
Write a quotation in the following format:
Provide a link in the following format:
```
.. _`name`: https://xxx
```
Note:
- If there is a newline character, indent it. For details, see the following table.
- There must be a space before https.
```rst
`name`_
```
Provide a link in the following format:
```rst
.. _`name`: https://xxx
```
Note:
- If there is a newline character, indent it. For details, see the following table.
- There must be a space before https.
Alternatively, you can use the following simplified format, that is, write only in the place where the reference is made.
```rst
`name <https://xxx>`_
```
- Display the detailed address:
```rst
https://xxx
```
Alternatively, you can use the following simplified format, that is, write only in the place where the reference is made.
```
`name <https://xxx>`_
```
- Display the detailed address:
```
https://xxx
```
- Table (For details, see section <https://sublime-and-sphinx-guide.readthedocs.io/en/latest/tables.html#list-table-directive>.)
```
.. list-table:: Title # Table title
:widths: 25 25 25 # Table column width
:header-rows: 1
* - Heading row 1, column 1 # Table header
- Heading row 1, column 2
- Heading row 1, column 3
* - Row 1, column 1
- #The table is empty.
- Row 1, column 3
* - Row 2, column 1
- Row 2, column 2
- Row 2,
# If a newline is required for the table content, add a blank line in the middle.
column 3
```
Display effect:
```rst
.. list-table:: Title # Table title
:widths: 25 25 25 # Table column width
:header-rows: 1
* - Heading row 1, column 1 # Table header
- Heading row 1, column 2
- Heading row 1, column 3
* - Row 1, column 1
- #The table is empty.
- Row 1, column 3
* - Row 2, column 1
- Row 2, column 2
- Row 2,
# If a newline is required for the table content, add a blank line in the middle.
column 3
```
Display effect:


- By default, the detailed description is displayed in one line. If you need to display it in another line, write it in the form of a list or code-block.
- List mode:
```
- Content1
- Content2
- Content3
```
- List mode:
- Code-Block mode:
```
.. code-block::
```rst
- Content1
- Content2
- Content3
```
Content1
Content2
Content3
```
- Code-Block mode:
```rst
.. code-block::
Content1
Content2
Content3
```
### Python Example
#### Class
```python
class Tensor(Tensor_):
"""
@@ -203,7 +224,7 @@ class Tensor(Tensor_):
>>> assert isinstance(t1, Tensor)
>>> assert t1.shape == (1, 2, 3)
>>> assert t1.dtype == mindspore.float32
>>>
...
>>> # initialize a tensor with a float scalar
>>> t2 = Tensor(0.1)
>>> assert isinstance(t2, Tensor)
@@ -217,6 +238,7 @@ class Tensor(Tensor_):
For details about the display effect, click [here](https://www.mindspore.cn/doc/api_python/en/master/mindspore/mindspore.html#mindspore.Tensor).