提交 5ea0eadc 编写于 作者: B buxue

support enumerate super isinstance.

上级 1d16b8c3
......@@ -40,34 +40,41 @@
### Expression Types
| Operation | Description
| :----------- |:--------
| Unary operator |`+`,`-`, and`not`. The operator `+` supports only scalars.
| Binary operator |`+`, `-`, `*`, `/`, `%`, `**` and `//`
| `if` expression | For example, `a = x if x < y else y`.
| Comparison expression | `>`, `>=`, `<`, `<=`, `==`, and `! =`.
| Operation | Description
| :----------- |:--------
| Unary operator |`+`,`-`, and`not`. The operator `+` supports only scalars.
| Binary operator |`+`, `-`, `*`, `/`, `%`, `**` and `//`.
| `if` expression | For example, `a = x if x < y else y`.
| Comparison expression | `>`, `>=`, `<`, `<=`, `==`, and `! =`.
| Logical expression | `and` and `or`.
| `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.
| Primitive operator |[mindspore/ops/operations/*](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.ops.operations.html).
| Composite operator |[mindspore/ops/composite/*](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.ops.composite.html).
| 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.
| Primitive operator |[mindspore/ops/operations/*](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.ops.operations.html).
| Composite operator |[mindspore/ops/composite/*](https://www.mindspore.cn/api/en/master/api/python/mindspore/mindspore.ops.composite.html).
| 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:
* The following is an example of incorrect input:
```python
class ExpandDimsTest(Cell):
......
......@@ -41,33 +41,40 @@
### 表达式类型
| 操作名 | 具体操作
| :----------- |:--------
| 一元操作符 |`+``-``not`,其中`+`操作符只支持标量。
| 数学表达式 |`+``-``*``/``%``**``//`
| :----------- |:--------
| 一元操作符 |`+``-``not`,其中`+`操作符只支持标量。
| 数学表达式 |`+``-``*``/``%``**``//`
| `if`表达式 |例如`a = x if x < y else y`
| 比较表达式 | `>``>=``<``<=``==``!=`
| 逻辑表达式 | `and``or`
| 比较表达式 | `>``>=``<``<=``==``!=`
| 逻辑表达式 | `and``or`
| `lambda`表达式 | 例如`lambda x, y: x + y`
| 保留关键字类型 | `True``False``None`
| 保留关键字类型 | `True``False``None`
### 语句类型
| 语句 | 与Python对比
| 语句 | 与Python对比
| :----------- |:--------
| `def` | 相同。
| `for` | 迭代序列必须是Tuple/List,部分嵌套场景支持。
| `while` | 部分嵌套场景支持,对带有while循环的网络求反向不支持。
| `break` | 相同。
| `if` | 与Python使用原则一致,但if条件的输入只支持常量。
| `in` | 仅支持Dictionary
| `in` | 仅支持判断常量是否存在于元素都是常量的Tuple/List/Dictionary里。
| `not in` | 仅支持Dictionary
| `def` | 相同。
| 赋值语句 | List和Dictionary的多重下标访问不支持作为左值。
| 赋值语句 | List和Dictionary的多重下标访问不支持作为左值。
### 系统函数
* len
* partial
* map
* zip
* range
### 系统函数/系统类
| 函数/类 | 与Python对比
| :----------- |:--------
| `len` | 使用原则与Python一致,返回结果与Python一致,返回int。
| `partial` | 使用原则与Python一致,返回结果与Python不一致,返回函数。
| `map` | 使用原则与Python一致,返回结果与Python不一致,返回tuple。
| `zip` | 使用原则与Python一致,返回结果与Python不一致,返回tuple。
| `range` | 使用原则与Python一致,返回结果与Python不一致,返回tuple。
| `enumerate` | 使用原则与Python一致,返回结果与Python不一致,返回tuple。
| `super` | 使用原则与Python一致,返回结果与Python不一致,返回mindspore自定义的命名空间。
| `isinstance` | 使用原则与Python一致,但第二个入参只能是mindspore定义的类型。
### 函数参数
* 参数默认值:目前不支持默认值设为`Tensor`类型数据,支持`int``float``bool``None``str``tuple``list``dict`类型数据。
......@@ -77,7 +84,7 @@
### 操作符
| 运算符 | 支持类型
| 运算符 | 支持类型
| :----------- |:--------
| `+` |标量、`Tensor``tuple``string`
| `-` |标量、`Tensor`
......@@ -155,19 +162,19 @@
### 网络构造组件
| 类别 | 内容
| :----------- |:--------
| `Cell`实例 |[mindspore/nn/*](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.nn.html)、自定义[Cell](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.nn.html#mindspore.nn.Cell)
| `Cell`实例的成员函数 | Cell的construct中可以调用其他类成员函数。
| 函数 | 自定义Python函数、前文中列举的系统函数。
| dataclass实例 | 使用@dataclass装饰的类。
| Primitive算子 |[mindspore/ops/operations/*](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.ops.operations.html)
| Composite算子 |[mindspore/ops/composite/*](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.ops.composite.html)
| constexpr生成算子 |使用[@constexpr](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.ops.html#mindspore.ops.constexpr)生成的值计算算子。
| 类别 | 内容
| :----------- |:--------
| `Cell`实例 |[mindspore/nn/*](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.nn.html)、自定义[Cell](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.nn.html#mindspore.nn.Cell)
| `Cell`实例的成员函数 | Cell的construct中可以调用其他类成员函数。
| 函数 | 自定义Python函数、前文中列举的系统函数。
| dataclass实例 | 使用@dataclass装饰的类。
| Primitive算子 |[mindspore/ops/operations/*](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.ops.operations.html)
| Composite算子 |[mindspore/ops/composite/*](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.ops.composite.html)
| constexpr生成算子 |使用[@constexpr](https://www.mindspore.cn/api/zh-CN/master/api/python/mindspore/mindspore.ops.html#mindspore.ops.constexpr)生成的值计算算子。
### 其他约束
整网construct函数输入的参数以及使用ms_function装饰器修饰的函数的参数在图编译过程中会进行泛化,不能作为常量输入传给算子使用,如下例所示:
整网construct函数输入的参数以及使用ms_function装饰器修饰的函数的参数在图编译过程中会进行泛化,不能作为常量输入传给算子使用。所以,在图模式下,限制入口网络的参数只能是Tensor,如下例所示:
* 错误的写法如下:
```python
class ExpandDimsTest(Cell):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册