From 6b38d8f74c7b99ed3c0df58c9454c91da2b274ca Mon Sep 17 00:00:00 2001 From: Payne Date: Tue, 27 Oct 2020 17:41:29 +0800 Subject: [PATCH] update the Tensor augment assignment. --- docs/note/source_en/constraints_on_network_construction.md | 5 +++++ .../note/source_zh_cn/constraints_on_network_construction.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/docs/note/source_en/constraints_on_network_construction.md b/docs/note/source_en/constraints_on_network_construction.md index 4f5e9f8c1d..b9c294ff0b 100644 --- a/docs/note/source_en/constraints_on_network_construction.md +++ b/docs/note/source_en/constraints_on_network_construction.md @@ -71,6 +71,7 @@ | `is` | Only support `True`, `False`, and `None`. | `is not` | Only support `True`, `False`, and `None`. | Assignment statement | Accessed multiple subscripts of lists and dictionaries cannot be used as l-value. +| Augment assignment statement| `+=``-=`, `*=`, `/=`, `%=`, `//=`. ### System Functions/Classes @@ -112,10 +113,12 @@ The index operation includes `tuple` and `Tensor`. The following focuses on the - Slice index: index is `slice` - Value: `tensor_x[start: stop: step]`, where Slice (start: stop: step) has the same syntax as Python, and will not be repeated here. - Assignment: `tensor_x[start: stop: step] = u`. + - Augment assignment: `tensor_x[start: stop: step] += u`. - Ellipsis index: index is `ellipsis` - Value: `tensor_x [...]`. - Assignment: `tensor_x [...] = u`. + - Augment assignment: `tensor_x [...] += u`. - Boolean constant index: index is `True`, index is `False` is not supported temporarily. - Value: `tensor_x[True]`. @@ -147,12 +150,14 @@ The index operation includes `tuple` and `Tensor`. The following focuses on the - The tuple element is a slice: - Value: for example `tensor_x[::,: 4, 3: 0: -1]`. - Assignment: for example `tensor_x[::,: 4, 3: 0: -1] = u`. + - Augment assignment: for example `tensor_x[::,: 4, 3: 0: -1] += u`. - The tuple element is Number: - Value: for example `tensor_x[2,1]`. - Assignment: for example `tensor_x[1,4] = u`. - The tuple element is a mixture of slice and ellipsis: - Value: for example `tensor_x[..., ::, 1:]`. - Assignment: for example `tensor_x[..., ::, 1:] = u`. + - Augment assignment: for example `tensor_x[..., ::, 1:] += u`. - Not supported in other situations The index value operation of tuple and list type, we need to focus on the index value operation of tuple or list whose element type is `nn.Cell`. This operation is currently only supported by the GPU backend in Graph mode, and its syntax format is like `layers[index](*inputs)`, the example code is as follows: diff --git a/docs/note/source_zh_cn/constraints_on_network_construction.md b/docs/note/source_zh_cn/constraints_on_network_construction.md index 599f7a35ce..292b5bef9e 100644 --- a/docs/note/source_zh_cn/constraints_on_network_construction.md +++ b/docs/note/source_zh_cn/constraints_on_network_construction.md @@ -71,6 +71,7 @@ | `is` | 仅支持`True`、`False`、`None`。 | `is not` | 仅支持`True`、`False`、`None`。 | 赋值语句 | List和Dictionary的多重下标访问不支持作为左值。 +| 增强赋值语句 | `+=`、`-=`、`*=`、`/=`、`%=`、`//=`。 ### 系统函数/系统类 @@ -112,10 +113,12 @@ - 切片索引:index为`slice` - 取值:`tensor_x[start:stop:step]`,其中Slice(start:stop:step)与Python的语法相同,这里不再赘述。 - 赋值:`tensor_x[start:stop:step]=u`。 + - 增强赋值:`tensor_x[start:stop:step]+=u`。 - Ellipsis索引:index为`ellipsis` - 取值:`tensor_x[...]`。 - 赋值:`tensor_x[...]=u`。 + - 增强赋值:`tensor_x[...]+=u`。 - 布尔常量索引:index为`True`,index为`False`暂不支持。 - 取值:`tensor_x[True]`。 @@ -146,12 +149,14 @@ - tuple元素为slice: - 取值:例如`tensor_x[::, :4, 3:0:-1]`。 - 赋值:例如`tensor_x[::, :4, 3:0:-1]=u`。 + - 增强赋值:例如`tensor_x[::, :4, 3:0:-1]+=u`。 - tuple元素为Number: - 取值:例如`tensor_x[2,1]`。 - 赋值:例如`tensor_x[1,4]=u`。 - tuple元素为slice和ellipsis混合情况: - 取值:例如`tensor_x[..., ::, 1:]` - 赋值:例如`tensor_x[..., ::, 1:]=u` + - 增强赋值:例如`tensor_x[..., ::, 1:]+=u` - 其他情况暂不支持 tuple和list类型的索引取值操作,需要重点介绍一下元素类型为`nn.Cell`的tuple或list的索引取值操作,该操作目前在Graph模式下仅GPU后端支持运行,其语法格式形如`layers[index](*inputs)`,具体示例代码如下: -- Gitee