Slice

Slice - 13

版本

  • 名称: Slice (GitHub)

  • : main

  • 起始版本: 13

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的运算符自 版本 13 起可用。

摘要

沿多个轴生成输入张量的切片。类似于 numpy: https://numpy.com.cn/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding

Slice 使用 startsendsaxessteps 输入来选择其输入 data 张量的子张量。

对于 i[0, ... r-1] 中(其中 r = rank(input)),需要计算有效的 starts[i]ends[i]steps[i],如下所示:

如果省略 axes,则将其设置为 [0, ..., r-1]。如果省略 steps,则将其设置为长度为 len(starts)[1, ..., 1]

有效值初始化为 start[i] = 0ends[i] = dims[i](其中 dimsinput 的维度),以及 steps[i] = 1

通过将 r =rank(input) 添加到 axes 的所有负元素中,使其变为非负数。

dims[axes[i]] 添加到 starts[i]ends[i] 的所有负值中,其中 dimsinput 的维度。然后,对于正向步进,start[axes[i]] 是调整后的 starts[i],它会被限制在 [0, dims[axes[i]]] 范围内;对于负向步进,它会被限制在 [0, dims[axes[i]]-1] 范围内。

调整后的 ends[i] 的限制取决于 steps[i] 的符号,并且必须能够复制 0dims[axes[i]] 个元素。因此,对于正向步进,ends[axes[i]] 会被限制在 [0, dims[axes[i]]] 范围内;对于负向步进,它会被限制在 [-1, dims[axes[i]]-1] 范围内。

最后,steps[axes[i]] = steps[i]

对于尺寸未知的维度进行切片,建议在正向切片时传入 INT_MAX,在反向切片时传入 INT_MIN

示例 1

data = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
]
axes = [0, 1]
starts = [1, 0]
ends = [2, 3]
steps = [1, 2]
result = [
    [5, 7],
]

示例 2

data = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
]
starts = [0, 1]
ends = [-1, 1000]
result = [
    [2, 3, 4],
]

输入

输入数量在 3 到 5 之间。

  • data (异构) - T

    要从中提取切片的数据张量。

  • starts (异构) - Tind

    axes 中对应轴的起始索引的一维张量。

  • ends (异构) - Tind

    axes 中对应轴的结束索引(不包含)的一维张量。

  • axes (可选, 异构) - Tind

    startsends 应用到的轴的一维张量。负值表示从后向前计数维度。可接受的范围是 [-r, r-1],其中 r = rank(data)。如果轴重复,行为未定义。

  • steps (可选, 异构) - Tind

    axes 中对应轴的切片步长的一维张量。负值表示反向切片。“steps”不能为 0。默认为 1。

输出

  • 输出 (异构) - T

    切片后的数据张量。

类型约束

  • T 在 ( tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入和输出类型限制为所有张量类型。

  • Tind 在 ( tensor(int32), tensor(int64) )

    将索引限制为整数类型

Slice - 11

版本

  • 名称: Slice (GitHub)

  • : main

  • 起始版本: 11

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的运算符自 版本 11 起可用。

摘要

沿多个轴生成输入张量的切片。类似于 numpy: https://numpy.com.cn/doc/stable/reference/routines.indexing.html Slices 使用 startsendsaxessteps 输入来指定轴列表中每个轴的开始和结束维度以及步长,它使用此信息来切片输入 data 张量。如果为任何开始或结束索引传递负值,则表示该维度末尾之前的元素数量。如果传递给 start 或 end 的值大于 n(此维度中的元素数量),则表示 n。对于尺寸未知的维度进行切片,建议在正向切片时传入 INT_MAX,在反向切片时传入 INT_MIN。如果为步长传递负值,则表示反向切片。但步长值不能为 0。如果省略 axes,则将其设置为 [0, ..., ndim-1]。如果省略 steps,则将其设置为长度为 len(starts)[1, ..., 1]。示例 1:data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] axes = [0, 1] starts = [1, 0] ends = [2, 3] steps = [1, 2] result = [ [5, 7], ] 示例 2:data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] starts = [0, 1] ends = [-1, 1000] result = [ [2, 3, 4], ]

输入

输入数量在 3 到 5 之间。

  • data (异构) - T

    要从中提取切片的数据张量。

  • starts (异构) - Tind

    axes 中对应轴的起始索引的一维张量。

  • ends (异构) - Tind

    axes 中对应轴的结束索引(不包含)的一维张量。

  • axes (可选, 异构) - Tind

    startsends 应用到的轴的一维张量。负值表示从后向前计数维度。可接受的范围是 [-r, r-1],其中 r = rank(data)。

  • steps (可选, 异构) - Tind

    axes 中对应轴的切片步长的一维张量。负值表示反向切片。“steps”不能为 0。默认为 1。

输出

  • 输出 (异构) - T

    切片后的数据张量。

类型约束

  • T 在 ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入和输出类型限制为所有张量类型。

  • Tind 在 ( tensor(int32), tensor(int64) )

    将索引限制为整数类型

Slice - 10

版本

  • 名称: Slice (GitHub)

  • : main

  • since_version: 10

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的操作符已在 版本 10 中提供。

摘要

沿多个轴生成输入张量的切片。类似于 numpy: https://numpy.com.cn/doc/stable/reference/routines.indexing.html Slices 使用 startsendsaxessteps 输入来指定轴列表中每个轴的开始和结束维度以及步长,它使用此信息来切片输入 data 张量。如果为任何开始或结束索引传递负值,则表示该维度末尾之前的元素数量。如果传递给 start 或 end 的值大于 n(此维度中的元素数量),则表示 n。对于尺寸未知的维度进行切片,建议传入 INT_MAX。如果为步长传递负值,则表示反向切片。如果省略 axes,则将其设置为 [0, ..., ndim-1]。如果省略 steps,则将其设置为长度为 len(starts)[1, ..., 1]。示例 1:data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] axes = [0, 1] starts = [1, 0] ends = [2, 3] steps = [1, 2] result = [ [5, 7], ] 示例 2:data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] starts = [0, 1] ends = [-1, 1000] result = [ [2, 3, 4], ]

输入

输入数量在 3 到 5 之间。

  • data (异构) - T

    要从中提取切片的数据张量。

  • starts (异构) - Tind

    axes 中对应轴的起始索引的一维张量。

  • ends (异构) - Tind

    axes 中对应轴的结束索引(不包含)的一维张量。

  • axes (可选, 异构) - Tind

    startsends 应用到的轴的一维张量。

  • steps (可选, 异构) - Tind

    axes 中对应轴的切片步长的一维张量。默认为 1。

输出

  • 输出 (异构) - T

    切片后的数据张量。

类型约束

  • T 在 ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入和输出类型限制为所有张量类型。

  • Tind 在 ( tensor(int32), tensor(int64) )

    将索引限制为整数类型

Slice - 1

版本

  • 名称: Slice (GitHub)

  • : main

  • 起始版本: 1

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的运算符自 版本 1 起可用。

总结

沿多个轴生成输入张量的切片。类似于 numpy: https://numpy.com.cn/doc/stable/reference/routines.indexing.html Slices 使用 axesstartsends 属性来指定轴列表中每个轴的开始和结束维度,它使用此信息来切片输入 data 张量。如果为任何开始或结束索引传递负值,则表示该维度末尾之前的元素数量。如果传递给 start 或 end 的值大于 n(此维度中的元素数量),则表示 n。对于尺寸未知的维度进行切片,建议传入 INT_MAX。如果省略 axes,则将其设置为 [0, ..., ndim-1]。示例 1:data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] axes = [0, 1] starts = [1, 0] ends = [2, 3] result = [ [5, 6, 7], ] 示例 2:data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] starts = [0, 1] ends = [-1, 1000] result = [ [2, 3, 4], ]

属性

  • axes - INTS :

    startsends 应用到的轴。此属性是可选的。如果不存在,则假定为 [0, 1, ..., len(starts) - 1]。

  • ends - INTS (必需)

    axes 中对应轴的结束索引(不包含)

  • starts - INTS (必需)

    axes 中对应轴的起始索引

输入

  • data (异构) - T

    要从中提取切片的数据张量。

输出

  • 输出 (异构) - T

    切片后的数据张量。

类型约束

  • T 在 ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) )

    将输入和输出类型限制为所有张量类型。