| `lambda` expression | For example, `lambda x, y: x + y`.
| `lambda` expression | For example, `lambda x, y: x + y`.
| Reserved keyword type | `True`, `False`, and `None`.
### Statement Types
| Statement | Compared with Python
| Statement | Compared with Python
| :----------- |:--------
| `def` | Same as that in Python.
| `for` | Nested for loops are partially supported. Iteration sequences must be tuples or lists.
| `while` | Nested while loops are partially supported. Grad of net with while is not supported.
| `break` | Same as that in Python.
| `if` | Same as that in Python. The input of the `if` condition must be a constant.
| `def` | Same as that in Python.
| `in` | Only support Dictionary.
| `in` | Only supports judging whether constants exist in Tuple/List/Dictionary whose elements are all constants.
| `not in` | Only support Dictionary.
| Assignment statement | Accessed multiple subscripts of lists and dictionaries cannot be used as l-value.
### System Functions
* len
* partial
* map
* zip
* range
### System Functions/Class
| Functions/Class | Compared with Python
| :----------- |:--------
| `len` | The usage principle is consistent with Python, and the returned result is consistent with Python, returning int.
| `partial` | The usage principle is consistent with Python, and the returned result is inconsistent with Python, returning function.
| `map` | The usage principle is consistent with Python, and the returned result is inconsistent with Python, returning tuple.
| `zip` | The usage principle is consistent with Python, and the returned result is inconsistent with Python, returning tuple.
| `range` | The usage principle is consistent with Python, and the returned result is inconsistent with Python, returning tuple.
| `enumerate` | The usage principle is consistent with Python, and the returned result is inconsistent with Python, returning tuple.
| `super` | The usage principle is consistent with Python, and the returned result is inconsistent with Python, returning the namespace defined by mindspore.
| `isinstance` | The usage principle is consistent with Python, but the second input parameter can only be the type defined by mindspore.
### Function Parameters
* Default parameter value: The data types `int`, `float`, `bool`, `None`, `str`, `tuple`, `list`, and `dict` are supported, whereas `Tensor` is not supported.
...
...
@@ -77,7 +84,7 @@
### Operators
| Operator | Supported Type
| Operator | Supported Type
| :----------- |:--------
| `+` |Scalar, `Tensor`, `tuple` and `string`
| `-` |Scalar and `Tensor`
...
...
@@ -160,19 +167,19 @@ Currently, the following syntax is not supported in network constructors:
### Network Construction Components
| Category | Content
| :----------- |:--------
| `Cell` instance |[mindspore/nn/*](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.nn.html), and custom [Cell](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.nn.html#mindspore.nn.Cell).
| Member function of a `Cell` instance | Member functions of other classes in the construct function of Cell can be called.
| Function | Custom Python functions and system functions listed in the preceding content.
| Dataclass instance | Class decorated with @dataclass.
| Operator generated by constexpr |Uses the value generated by [@constexpr](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.ops.html#mindspore.ops.constexpr) to calculate operators.
| Category | Content
| :----------- |:--------
| `Cell` instance |[mindspore/nn/*](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.nn.html), and custom [Cell](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.nn.html#mindspore.nn.Cell).
| Member function of a `Cell` instance | Member functions of other classes in the construct function of Cell can be called.
| Function | Custom Python functions and system functions listed in the preceding content.
| Dataclass instance | Class decorated with @dataclass.
| Operator generated by constexpr |Uses the value generated by [@constexpr](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.ops.html#mindspore.ops.constexpr) to calculate operators.
### Other Constraints
Input parameters of the construct function on the entire network and parameters of functions modified by the ms_function decorator are generalized during the graph compilation. Therefore, they cannot be transferred to operators as constant input, as shown in the following example:
Input parameters of the construct function on the entire network and parameters of functions modified by the ms_function decorator are generalized during the graph compilation. Therefore, they cannot be transferred to operators as constant input. Therefore, in graph mode, the parameter passed to the entry network can only be Tensor. As shown in the following example: