jax.lax.scatter_apply#

jax.lax.scatter_apply(operand, scatter_indices, func, dimension_numbers, *, update_shape=(), indices_are_sorted=False, unique_indices=False, mode=None)[源代码]#

Scatter-apply 操作符。

封装了 XLA 的 Scatter 操作符,其中 operand 中的值被替换为 func(operand),重复的索引会导致多次应用 func

scatter 的语义很复杂,其 API 将来可能会更改。对于大多数用例,您应该首选 JAX 数组上的 jax.numpy.ndarray.at 属性,它使用熟悉的 NumPy 索引语法。

请注意,在当前的实现中,scatter_apply 与自动微分不兼容。

参数:
  • operand (Array) – 要应用 scatter 的数组

  • scatter_indices (Array) – 一个数组,它给出 operand 中每个 updates 中的更新应应用到的索引。

  • func (Callable[[Array], Array]) – 将在每个索引处应用的单参数函数。

  • dimension_numbers (ScatterDimensionNumbers) – 一个 lax.ScatterDimensionNumbers 对象,它描述 operandstart_indicesupdates 和输出的维度如何关联。

  • update_shape (Shape) – 给定索引处更新的形状。

  • indices_are_sorted (bool) – 是否已知 scatter_indices 已排序。如果为 true,则可能会提高某些后端上的性能。

  • unique_indices (bool) – operand 中要更新的元素是否保证彼此不重叠。如果为 true,则可能会提高某些后端上的性能。JAX 不会检查此承诺:如果 unique_indicesTrue 时更新的元素重叠,则行为未定义。

  • mode (str | GatherScatterMode | None | None) – 如何处理超出范围的索引:当设置为 ‘clip’ 时,索引会被钳制,以便切片在范围内;当设置为 ‘fill’ 或 ‘drop’ 时,超出范围的更新将被丢弃。当设置为 ‘promise_in_bounds’ 时,超出范围的索引的行为是实现定义的。

返回:

一个包含在给定索引处将 func 应用于 operand 的结果的数组。

返回类型:

Array