Scatter Softmax

torch_scatter.composite.scatter_softmax(src, index, dim=-1, eps=1e-12)[source]

Softmax operation over all values in src tensor that share indices specified in the index tensor along a given axis dim.

For one-dimensional tensors, the operation computes

\[\mathrm{out}_i = {\textrm{softmax}(\mathrm{src})}_i = \frac{\exp(\mathrm{src}_i)}{\sum_j \exp(\mathrm{src}_j)}\]

where \(\sum_j\) is over \(j\) such that \(\mathrm{index}_j = i\).

Parameters:
  • src (Tensor) – The source tensor.
  • index (LongTensor) – The indices of elements to scatter.
  • dim (int, optional) – The axis along which to index. (default: -1)
  • eps (float, optional) – Small value to ensure numerical stability. (default: 1e-12)
Return type:

Tensor

torch_scatter.composite.scatter_log_softmax(src, index, dim=-1, eps=1e-12)[source]

Log-softmax operation over all values in src tensor that share indices specified in the index tensor along a given axis dim.

For one-dimensional tensors, the operation computes

\[\mathrm{out}_i = {\textrm{log_softmax}(\mathrm{src})}_i = \log \left( \frac{\exp(\mathrm{src}_i)}{\sum_j \exp(\mathrm{src}_j)} \right)\]

where \(\sum_j\) is over \(j\) such that \(\mathrm{index}_j = i\).

Parameters:
  • src (Tensor) – The source tensor.
  • index (LongTensor) – The indices of elements to scatter.
  • dim (int, optional) – The axis along which to index. (default: -1)
  • eps (float, optional) – Small value to ensure numerical stability. (default: 1e-12)
Return type:

Tensor