"tests/vscode:/vscode.git/clone" did not exist on "14ccf5986401104121d0ef286a29386904af3bb7"
Commit 50e4214b authored by Matthias Fey's avatar Matthias Fey Committed by GitHub
Browse files

Merge pull request #40 from jhultman/minmax_tuple

min and max should still return arg when index empty
parents 5e69a349 8a8d068c
...@@ -97,5 +97,5 @@ def scatter_max(src, index, dim=-1, out=None, dim_size=None, fill_value=0): ...@@ -97,5 +97,5 @@ def scatter_max(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
""" """
src, out, index, dim = gen(src, index, dim, out, dim_size, fill_value) src, out, index, dim = gen(src, index, dim, out, dim_size, fill_value)
if src.size(dim) == 0: # pragma: no cover if src.size(dim) == 0: # pragma: no cover
return out return out, index.new_full(out.size(), -1)
return ScatterMax.apply(out, src, index, dim) return ScatterMax.apply(out, src, index, dim)
...@@ -44,9 +44,9 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0): ...@@ -44,9 +44,9 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
Minimizes all values from the :attr:`src` tensor into :attr:`out` at the Minimizes all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along a given axis indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their :attr:`dim`.If multiple indices reference the same location, their
**contributions maximize** (`cf.` :meth:`~torch_scatter.scatter_add`). **contributions minimize** (`cf.` :meth:`~torch_scatter.scatter_add`).
The second return tensor contains index location in :attr:`src` of each The second return tensor contains index location in :attr:`src` of each
minimum value (known as argmax). minimum value (known as argmin).
For one-dimensional tensors, the operation computes For one-dimensional tensors, the operation computes
...@@ -83,10 +83,10 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0): ...@@ -83,10 +83,10 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
index = torch.tensor([[ 4, 5, 4, 2, 3], [0, 0, 2, 2, 1]]) index = torch.tensor([[ 4, 5, 4, 2, 3], [0, 0, 2, 2, 1]])
out = src.new_zeros((2, 6)) out = src.new_zeros((2, 6))
out, argmax = scatter_min(src, index, out=out) out, argmin = scatter_min(src, index, out=out)
print(out) print(out)
print(argmax) print(argmin)
.. testoutput:: .. testoutput::
...@@ -97,5 +97,5 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0): ...@@ -97,5 +97,5 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
""" """
src, out, index, dim = gen(src, index, dim, out, dim_size, fill_value) src, out, index, dim = gen(src, index, dim, out, dim_size, fill_value)
if src.size(dim) == 0: # pragma: no cover if src.size(dim) == 0: # pragma: no cover
return out return out, index.new_full(out.size(), -1)
return ScatterMin.apply(out, src, index, dim) return ScatterMin.apply(out, src, index, dim)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment