Scatter Min

torch_scatter.scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=None)[source]

https://raw.githubusercontent.com/rusty1s/pytorch_scatter/master/docs/source/_figures/min.svg?sanitize=true

Minimizes all values from the src tensor into out at the indices specified in the index tensor along a given axis dim.If multiple indices reference the same location, their contributions minimize (cf. scatter_add()). The second return tensor contains index location in src of each minimum value (known as argmin).

For one-dimensional tensors, the operation computes

\[\mathrm{out}_i = \min(\mathrm{out}_i, \min_j(\mathrm{src}_j))\]

where \(\min_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)
  • out (Tensor, optional) – The destination tensor. (default: None)
  • dim_size (int, optional) – If out is not given, automatically create output with size dim_size at dimension dim. If dim_size is not given, a minimal sized output tensor is returned. (default: None)
  • fill_value (int, optional) – If out is not given, automatically fill output tensor with fill_value. (default: None)
  • fill_value – If out is not given, automatically fill output tensor with fill_value. If set to None, the output tensor is filled with the greatest possible value of src.dtype. (default: None)
Return type:

(Tensor, LongTensor)

from torch_scatter import scatter_min

src = torch.Tensor([[-2, 0, -1, -4, -3], [0, -2, -1, -3, -4]])
index = torch.tensor([[ 4, 5,  4,  2,  3], [0,  0,  2,  2,  1]])
out = src.new_zeros((2, 6))

out, argmin = scatter_min(src, index, out=out)

print(out)
print(argmin)
tensor([[ 0.,  0., -4., -3., -2.,  0.],
        [-2., -4., -3.,  0.,  0.,  0.]])
tensor([[-1, -1,  3,  4,  0,  1],
        [ 1,  4,  3, -1, -1, -1]])