diff --git a/docs/source_en/constraints_on_network_construction.md b/docs/source_en/constraints_on_network_construction.md index d61ce5a201a547336d5e7aab7570f91bd17b9a4e..85f41e6af49ecc594befdec0d63a62737d6a1b29 100644 --- a/docs/source_en/constraints_on_network_construction.md +++ b/docs/source_en/constraints_on_network_construction.md @@ -12,7 +12,7 @@ - [System Functions](#system-functions) - [Function Parameters](#function-parameters) - [Operators](#operators) - - [Slicing Operations](#slicing-operations) + - [Index operation](#index-operation) - [Unsupported Syntax](#unsupported-syntax) - [Network Definition Constraints](#network-definition-constraints) - [Instance Types on the Entire Network](#instance-types-on-the-entire-network) @@ -86,32 +86,41 @@ | `%` |Scalar and `Tensor` | `[]` |The operation object type can be `list`, `tuple`, or `Tensor`. Accessed multiple subscripts of lists and dictionaries can be used as r-values instead of l-values. The index type cannot be Tensor. For details about access constraints for the tuple and Tensor types, see the description of slicing operations. -### Slicing Operations - -* `tuple` slicing operation: `tuple_x[start:stop:step]` - - `tuple_x` indicates a tuple on which the slicing operation is performed. - - `start`: index where the slice starts. The value is of the `int` type, and the value range is `[-length(tuple_x), length(tuple_x) - 1]`. Default values can be used. The default settings are as follows: - - When `step > 0`, the default value is `0`. - - When `step < 0`, the default value is `length(tuple_x) - 1`. - - `end`: index where the slice ends. The value is of the `int` type, and the value range is `[-length(tuple_x) - 1, length(tuple_x)]`. Default values can be used. The default settings are as follows: - - When `step > 0`, the default value is `length(tuple_x)`. - - When `step < 0`, the default value is `-1`. - - `step`: slicing step. The value is of the `int` type, and its range is `step! = 0`. The default value `1` can be used. - -* `Tensor` slicing operation: `tensor_x[start0:stop0:step0, start1:stop1:step1, start2:stop2:step2]` - - `tensor_x` indicates a `Tensor` with at least three dimensions. The slicing operation is performed on it. - - `start0`: index where the slice starts in dimension 0. The value is of the `int` type. Default values can be used. The default settings are as follows: - - When `step > 0`, the default value is `0`. - - When `step < 0`, the default value is `-1`. - - `end0`: index where the slice ends in dimension 0. The value is of the `int` type. Default values can be used. The default settings are as follows: - - When `step > 0`, the default value is `length(tuple_x)`. - - When `step < 0`, the default value is `-(1 + length(tuple_x))`. - - `step0`: slicing step in dimension 0. The value is of the `int` type, and its range is `step! = 0`. The default value `1` can be used. - - If the number of dimensions for slicing is less than that for `Tensor`, all elements are used by default if no slice dimension is specified. - - Slice dimension reduction operation: If an integer index is transferred to a dimension, the elements of the corresponding index in the dimension is obtained and the dimension is eliminated. For example, after `tensor_x[2:4:1, 1, 0:5:2]` with shape (4, 3, 6) is sliced, a `Tensor` with shape (2, 3) is generated. The first dimension of the original `Tensor` is eliminated. -* Ellipsis as indexing: Get the all elements of the dimensions which is ignored by ellipsis. For example, tensor_x with shape(3, 4, 5, 6), `tensor_x[1:3:1, ..., 0:5:2]` will result in a shape of (2,4,5,3). -* None as indexing: For a tensor shape with (3,4,5), operation `tensor_x[None]` will result in a tensor with shape (1, 3, 4, 5). -* True as indexing: For a tensor shape with (3,4,5), operation `tensor_x[True]` will result in a tensor with shape (1, 3, 4, 5). +### Index operation + +The index operation includes `tuple` and` Tensor`. The following focuses on the index value assignment and assignment operation of `Tensor`. The value takes` tensor_x [index] `as an example, and the assignment takes` tensor_x [index] = u` as an example for detailed description. Among them, tensor_x is a `Tensor`, which is sliced; index means the index, u means the assigned value, which can be` scalar` or `Tensor (size = 1)`. The index types are as follows: + +- 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`. + +- Ellipsis index: index is `ellipsis` + - Value: `tensor_x [...]`. + - Assignment: `tensor_x [...] = u`. + +- Boolean constant index: index is `True`, index is `False` is not supported temporarily. + - Value: `tensor_x[True]`. + - Assignment: Not supported yet. +- Tensor index: index is `Tensor` + - Value: Not supported yet. + - Assignment: `tensor_x[index] = u`, `index` only supports `Tensor` of type` bool`. +- None constant index: index is `None` + - Value: `tensor_x[None]`, results are consistent with numpy. + - Assignment: Not supported yet. +- tuple index: index is `tuple` + - 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`. + - 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`. + - Not supported in other situations + +In addition, tuple also supports slice value operation, `tuple_x [start: stop: step]`, which has the same effect as Python, and will not be repeated here. + ### Unsupported Syntax Currently, the following syntax is not supported in network constructors: diff --git a/docs/source_zh_cn/constraints_on_network_construction.md b/docs/source_zh_cn/constraints_on_network_construction.md index 42fd829e95400de081fafd01f10a895411f8b4d6..4377e0cb6b1286cbe1a9100f08dd8e4648a59074 100644 --- a/docs/source_zh_cn/constraints_on_network_construction.md +++ b/docs/source_zh_cn/constraints_on_network_construction.md @@ -12,7 +12,7 @@ - [系统函数](#系统函数) - [函数参数](#函数参数) - [操作符](#操作符) - - [切片操作](#切片操作) + - [索引操作](#索引操作) - [不支持的语法](#不支持的语法) - [网络定义约束](#网络定义约束) - [整网实例类型](#整网实例类型) @@ -86,32 +86,39 @@ | `%` |标量、`Tensor` | `[]` |操作对象类型支持`list`、`tuple`、`Tensor`,支持多重下标访问作为右值,但不支持多重下标访问作为左值,且索引类型不支持Tensor;Tuple、Tensor类型访问限制见切片操作中的说明。 -### 切片操作 - -* `tuple`切片操作:`tuple_x[start:stop:step]` - - `tuple_x`为一个元组,是被执行切片操作的目标。 - - `start`:切片的起始位置索引,类型为`int`,取值范围为`[-length(tuple_x), length(tuple_x) - 1]`。可缺省,缺省配置如下: - - 当`step > 0`时,缺省值为`0`。 - - 当`step < 0`时,缺省值为`length(tuple_x) - 1`。 - - `end`:切片的结束位置索引,类型为`int`,取值范围为`[-length(tuple_x) - 1, length(tuple_x)]`。可缺省,缺省配置如下: - - 当`step > 0`时,缺省值为`length(tuple_x)`。 - - 当`step < 0`是,缺省值为`-1`。 - - `step`:切片的步长,类型为`int`,取值范围为`step != 0`。可缺省,缺省值为`1`。 - -* `Tensor`切片操作:`tensor_x[start0:stop0:step0, start1:stop1:step1, start2:stop2:step2]` - - `tensor_x`是一个维度不低于3维的`Tensor`,对其进行切片操作。 - - `start0`:在第0维上进行切片的起始位置索引,类型为`int`,可缺省,缺省配置如下: - - 当`step > 0`时,缺省值为`0`。 - - 当`step < 0`时,缺省值为`-1`。 - - `end0`:在第0维上进行切片的结束位置索引,类型为`int`,可缺省,缺省配置如下: - - 当`step > 0`时,缺省值为`length(tuple_x)`。 - - 当`step < 0`是,缺省值为`-(1 + length(tuple_x))`。 - - `step0`:在第0维上进行切片的步长,类型为`int`,取值范围为`step != 0`。可缺省,缺省值为`1`。 - - 如果进行切片的维数少于`Tensor`的维数,则未指定切片的维度默认取全部元素。 - - 切片降维操作:在某维度上传入整数索引,则取出该维度上对应索引的元素,且消除该维度,如shape为(4, 3, 6)的`tensor_x[2:4:1, 1, 0:5:2]`切片之后,生成一个shape为(2, 3)的`Tensor`,原`Tensor`的第1维被消除。 - - Ellipsis作为索引:与numpy保持一致,未明确指定如何操作的维度,都对应取全部元素,shape为(3, 4, 5, 6)的`tensor_x[1:3:1, ..., 0:5:2]`切片之后,第1维和第2维取全部元素,生成一个shape为(2, 4, 5, 3)的`Tensor`。 - - None作为索引:与numpy保持一致,如shape为(3, 4, 5)的`tensor_x[None]`返回的是一个维度扩展之后,shape为(1, 3, 4, 5)的`Tensor`。 - - True作为索引:与numpy保持一致,如shape为(3, 4, 5)的`tensor_x[True]`返回的是一个维度扩展之后,shape为(1, 3, 4, 5)的`Tensor`。 +### 索引操作 + +索引操作包含`tuple`和`Tensor`的索引操作。下面重点介绍一下`Tensor`的索引取值和赋值操作,取值以`tensor_x[index]`为例,赋值以`tensor_x[index] = u`为例进行详细说明。其中tensor_x是一个`Tensor`,对其进行切片操作;index表示索引,u表示赋予的值,可以是`scalar`或者`Tensor(size=1)`。索引类型如下: + +- 切片索引:index为`slice` + - 取值:`tensor_x[start:stop:step]`,其中Slice(start:stop:step)与Python的语法相同,这里不再赘述。 + - 赋值:`tensor_x[start:stop:step]=u`。 +- Ellipsis索引:index为`ellipsis` + - 取值:`tensor_x[...]`。 + - 赋值:`tensor_x[...]=u`。 +- 布尔常量索引:index为`True`,index为`False`暂不支持。 + - 取值:`tensor_x[True]`。 + - 赋值:暂不支持。 +- Tensor索引:index为`Tensor` + - 取值:暂不支持。 + - 赋值:`tensor_x[index]=u`,`index`仅支持`bool`类型的`Tensor`。 +- None常量索引:index为`None` + - 取值:`tensor_x[None]`,结果与numpy保持一致。 + - 赋值:暂不支持。 +- tuple索引:index为`tuple` + - tuple元素为slice: + - 取值:例如`tensor_x[::, :4, 3:0:-1]`。 + - 赋值:例如`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` + - 其他情况暂不支持 + +另外tuple也支持切片取值操作,`tuple_x[start:stop:step]`,与Python的效果相同,这里不再赘述。 + ### 不支持的语法 目前在网络构造函数里面暂不支持以下语法: