Scatter

Scatter - 11

版本

  • 名称: Scatter (GitHub)

  • : main

  • 起始版本: 11

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的算子已自版本 11 起弃用。

摘要

此算子已弃用。请使用 ScatterElements,它提供相同的功能。

Scatter 接收三个同为等级 r >= 1 的输入 dataupdatesindices,以及一个可选的属性 axis,该属性标识 data 的一个轴(默认情况下,是最外层的轴,即 axis 0)。该操作的输出是通过创建输入 data 的副本,然后用 indices 指定的特定索引位置的 updates 值来更新其值。其输出形状与 data 的形状相同。

对于 updates 中的每个条目,data 中的目标索引通过将 indices 中的相应条目与条目本身的索引结合来获得:维度 = axis 的索引值从 indices 中相应条目的值中获得,维度 != axis 的索引值从条目本身的索引中获得。

例如,在 2-D 张量的情况下,对应于 [i][j] 条目的更新如下所示

  output[indices[i][j]][j] = updates[i][j] if axis = 0,
  output[i][indices[i][j]] = updates[i][j] if axis = 1,

此算子是 GatherElements 的逆运算。它类似于 Torch 的 Scatter 操作。

示例 1

  data = [
      [0.0, 0.0, 0.0],
      [0.0, 0.0, 0.0],
      [0.0, 0.0, 0.0],
  ]
  indices = [
      [1, 0, 2],
      [0, 2, 1],
  ]
  updates = [
      [1.0, 1.1, 1.2],
      [2.0, 2.1, 2.2],
  ]
  output = [
      [2.0, 1.1, 0.0]
      [1.0, 0.0, 2.2]
      [0.0, 2.1, 1.2]
  ]

示例 2

  data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
  indices = [[1, 3]]
  updates = [[1.1, 2.1]]
  axis = 1
  output = [[1.0, 1.1, 3.0, 2.1, 5.0]]

属性

  • axis - INT (默认值为 '0')

    要在哪个轴上进行 scatter。负值表示从后向前计算维度。可接受的范围是 [-r, r-1],其中 r = rank(data)。

输入

  • data (异构) - T

    秩 r >= 1 的张量。

  • 索引 (异构) - Tind

    int32/int64 索引的张量,r >= 1(与输入具有相同的等级)。沿大小为 s 的轴,所有索引值都应在 [-s, s-1] 的范围内。如果任何索引值超出范围,则为错误。

  • updates (异构) - T

    等级为 r >=1 的张量(与 indices 具有相同的等级和形状)

输出

  • 输出 (异构) - T

    等级为 r >= 1 的张量(与输入具有相同的等级)。

类型约束

  • 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) )

    将索引限制为整数类型

Scatter - 9

版本

  • 名称: Scatter (GitHub)

  • : main

  • 起始版本: 9

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

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

摘要

给定等级为 r >= 1 的输入张量 dataupdatesindices,将 updates 提供的写入值写入第一个输入 data 中,沿 dataaxis 维度(默认最外层,即 axis=0),在对应的 indices 位置。对于 updates 中的每个条目,data 中的目标索引由 indices 中对应条目为维度 = axis 指定,维度 != axis 的索引是源中的索引。例如,在 2-D 张量的情况下,如果 axis = 0,则 data[indices[i][j]][j] = updates[i][j];如果 axis = 1,则 data[i][indices[i][j]] = updates[i][j],其中 i 和 j 是从 0 到 updates 的相应大小减 1 的循环计数器。示例 1:data = [ [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], ] indices = [ [1, 0, 2], [0, 2, 1], ] updates = [ [1.0, 1.1, 1.2], [2.0, 2.1, 2.2], ] output = [ [2.0, 1.1, 0.0] [1.0, 0.0, 2.2] [0.0, 2.1, 1.2] ] 示例 2:data = [[1.0, 2.0, 3.0, 4.0, 5.0]] indices = [[1, 3]] updates = [[1.1, 2.1]] axis = 1 output = [[1.0, 1.1, 3.0, 2.1, 5.0]]

属性

  • axis - INT (默认值为 '0')

    要在哪个轴上进行 scatter。负值表示从后向前计算维度。可接受的范围是 [-r, r-1]

输入

  • data (异构) - T

    秩 r >= 1 的张量。

  • 索引 (异构) - Tind

    int32/int64 索引的张量,r >= 1(与输入具有相同的等级)。

  • updates (异构) - T

    等级为 r >=1 的张量(与 indices 具有相同的等级和形状)

输出

  • 输出 (异构) - T

    等级为 r >= 1 的张量(与输入具有相同的等级)。

类型约束

  • 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) )

    将索引限制为整数类型