Commit 0a038334 authored by rusty1s's avatar rusty1s
Browse files

update doc

parent 21208fce
...@@ -90,7 +90,7 @@ tensor([0, 5, 3, 0, 1]) ...@@ -90,7 +90,7 @@ tensor([0, 5, 3, 0, 1])
## FarthestPointSampling ## FarthestPointSampling
A sampling algorithm, which iteratively samples the most distant point (in metric distance) with regard to the rest points. A sampling algorithm, which iteratively samples the most distant point with regard to the rest points.
```python ```python
import torch import torch
...@@ -98,7 +98,7 @@ from torch_cluster import fps ...@@ -98,7 +98,7 @@ from torch_cluster import fps
x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
batch = torch.tensor([0, 0, 0, 0]) batch = torch.tensor([0, 0, 0, 0])
sample = fps(x, batch, ratio=0.5, random_start=False) index = fps(x, batch, ratio=0.5, random_start=False)
``` ```
``` ```
...@@ -108,7 +108,7 @@ tensor([0, 3]) ...@@ -108,7 +108,7 @@ tensor([0, 3])
## kNN-Graph ## kNN-Graph
Computes graph edges to the nearest *k* points in metric space. Computes graph edges to the nearest *k* points.
```python ```python
import torch import torch
...@@ -127,7 +127,7 @@ tensor([[0, 0, 1, 1, 2, 2, 3, 3], ...@@ -127,7 +127,7 @@ tensor([[0, 0, 1, 1, 2, 2, 3, 3],
## Radius-Graph ## Radius-Graph
Computes graph edges to all points within a given distance in metric space. Computes graph edges to all points within a given distance.
```python ```python
import torch import torch
...@@ -146,17 +146,17 @@ tensor([[0, 0, 1, 1, 2, 2, 3, 3], ...@@ -146,17 +146,17 @@ tensor([[0, 0, 1, 1, 2, 2, 3, 3],
## Nearest ## Nearest
Clusters points which are nearest to a given query point in metric space. Clusters points in *x* together which are nearest to a given query point in *y*.
```python ```python
import torch import torch
from torch_cluster import nearest from torch_cluster import nearest
x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
batch_x = torch.Tensor([0, 0, 0, 0]) batch_x = torch.tensor([0, 0, 0, 0])
query_x = torch.Tensor([[-1, 0], [1, 0]]) y = torch.Tensor([[-1, 0], [1, 0]])
query_batch = torch.Tensor([0, 0]) batch_y = torch.tensor([0, 0])
cluster = nearest(x, query_x, batch_x, query_batch) cluster = nearest(x, y, batch_x, batch_y)
``` ```
``` ```
......
...@@ -2,31 +2,36 @@ import torch ...@@ -2,31 +2,36 @@ import torch
if torch.cuda.is_available(): if torch.cuda.is_available():
import fps_cuda import fps_cuda
""" """
def fps(x, batch=None, ratio=0.5, random_start=True): def fps(x, batch=None, ratio=0.5, random_start=True):
"""Iteratively samples the most distant point (in metric distance) with r""""A sampling algorithm from the `"PointNet++: Deep Hierarchical Feature
regard to the rest points. Learning on Point Sets in a Metric Space"
<https://arxiv.org/abs/1706.02413>`_ paper, which iteratively samples the
most distant point with regard to the rest points.
Args: Args:
x (Tensor): D-dimensional point features. x (Tensor): Node feature matrix
batch (LongTensor, optional): Vector that maps each point to its :math:`\mathbf{X} \in \mathbb{R}^{N \times F}`.
example identifier. If :obj:`None`, all points belong to the same batch (LongTensor, optional): Batch vector
example. If not :obj:`None`, points in the same example need to :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
have contiguous memory layout and :obj:`batch` needs to be node to a specific example. (default: :obj:`None`)
ascending. (default: :obj:`None`)
ratio (float, optional): Sampling ratio. (default: :obj:`0.5`) ratio (float, optional): Sampling ratio. (default: :obj:`0.5`)
random_start (bool, optional): Whether the starting node is random_start (bool, optional): If set to :obj:`False`, use the first
sampled randomly. (default: :obj:`True`) node in :math:`\mathbf{X}` as starting node. (default: obj:`True`)
:rtype: :class:`LongTensor` :rtype: :class:`LongTensor`
Examples:: .. testsetup::
import torch
from torch_cluster import fps
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) >>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch = torch.tensor([0, 0, 0, 0]) >>> batch = torch.tensor([0, 0, 0, 0])
>>> sample = fps(x, batch, ratio=0.5) >>> index = fps(x, batch, ratio=0.5)
""" """
if batch is None: if batch is None:
......
...@@ -6,22 +6,30 @@ if torch.cuda.is_available(): ...@@ -6,22 +6,30 @@ if torch.cuda.is_available():
def knn(x, y, k, batch_x=None, batch_y=None): def knn(x, y, k, batch_x=None, batch_y=None):
"""Finds for each element in `y` the `k` nearest points in `x`. r"""Finds for each element in :obj:`y` the :obj:`k` nearest points in
:obj:`x`.
Args: Args:
x (Tensor): D-dimensional point features. x (Tensor): Node feature matrix
y (Tensor): D-dimensional point features. :math:`\mathbf{X} \in \mathbb{R}^{N \times F}`.
y (Tensor): Node feature matrix
:math:`\mathbf{X} \in \mathbb{R}^{M \times F}`.
k (int): The number of neighbors. k (int): The number of neighbors.
batch_x (LongTensor, optional): Vector that maps each point to its batch_x (LongTensor, optional): Batch vector
example identifier. If :obj:`None`, all points belong to the same :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
example. If not :obj:`None`, points in the same example need to node to a specific example. (default: :obj:`None`)
have contiguous memory layout and :obj:`batch` needs to be batch_y (LongTensor, optional): Batch vector
ascending. (default: :obj:`None`) :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^M`, which assigns each
batch_y (LongTensor, optional): See `batch_x` (default: :obj:`None`) node to a specific example. (default: :obj:`None`)
:rtype: :class:`LongTensor` :rtype: :class:`LongTensor`
Examples:: .. testsetup::
import torch
from torch_cluster import knn
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) >>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch_x = torch.tensor([0, 0, 0, 0]) >>> batch_x = torch.tensor([0, 0, 0, 0])
...@@ -70,22 +78,26 @@ def knn(x, y, k, batch_x=None, batch_y=None): ...@@ -70,22 +78,26 @@ def knn(x, y, k, batch_x=None, batch_y=None):
def knn_graph(x, k, batch=None, loop=False): def knn_graph(x, k, batch=None, loop=False):
"""Finds for each element in `x` the `k` nearest points. r"""Computes graph edges to the nearest :obj:`k` points.
Args: Args:
x (Tensor): D-dimensional point features. x (Tensor): Node feature matrix
:math:`\mathbf{X} \in \mathbb{R}^{N \times F}`.
k (int): The number of neighbors. k (int): The number of neighbors.
batch (LongTensor, optional): Vector that maps each point to its batch (LongTensor, optional): Batch vector
example identifier. If :obj:`None`, all points belong to the same :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
example. If not :obj:`None`, points in the same example need to node to a specific example. (default: :obj:`None`)
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
loop (bool, optional): If :obj:`True`, the graph will contain loop (bool, optional): If :obj:`True`, the graph will contain
self-loops. (default: :obj:`False`) self-loops. (default: :obj:`False`)
:rtype: :class:`LongTensor` :rtype: :class:`LongTensor`
Examples:: .. testsetup::
import torch
from torch_cluster import knn_graph
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) >>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch = torch.tensor([0, 0, 0, 0]) >>> batch = torch.tensor([0, 0, 0, 0])
......
...@@ -6,24 +6,32 @@ if torch.cuda.is_available(): ...@@ -6,24 +6,32 @@ if torch.cuda.is_available():
def nearest(x, y, batch_x=None, batch_y=None): def nearest(x, y, batch_x=None, batch_y=None):
"""Finds for each element in `x` its nearest point in `y`. """Clusters points in :obj:`x` together which are nearest to a given query
point in :obj:`y`.
Args: Args:
x (Tensor): D-dimensional point features. x (Tensor): Node feature matrix
y (Tensor): D-dimensional point features. :math:`\mathbf{X} \in \mathbb{R}^{N \times F}`.
batch_x (LongTensor, optional): Vector that maps each point to its y (Tensor): Node feature matrix
example identifier. If :obj:`None`, all points belong to the same :math:`\mathbf{X} \in \mathbb{R}^{M \times F}`.
example. If not :obj:`None`, points in the same example need to batch_x (LongTensor, optional): Batch vector
have contiguous memory layout and :obj:`batch` needs to be :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
ascending. (default: :obj:`None`) node to a specific example. (default: :obj:`None`)
batch_y (LongTensor, optional): See `batch_x` (default: :obj:`None`) batch_y (LongTensor, optional): Batch vector
:math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^M`, which assigns each
node to a specific example. (default: :obj:`None`)
Examples:: .. testsetup::
import torch
from torch_cluster import nearest
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) >>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch_x = torch.Tensor([0, 0, 0, 0]) >>> batch_x = torch.tensor([0, 0, 0, 0])
>>> y = torch.Tensor([[-1, 0], [1, 0]]) >>> y = torch.Tensor([[-1, 0], [1, 0]])
>>> batch_x = torch.Tensor([0, 0]) >>> batch_x = torch.tensor([0, 0])
>>> cluster = nearest(x, y, batch_x, batch_y) >>> cluster = nearest(x, y, batch_x, batch_y)
""" """
......
...@@ -6,24 +6,33 @@ if torch.cuda.is_available(): ...@@ -6,24 +6,33 @@ if torch.cuda.is_available():
def radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32): def radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32):
"""Finds for each element in `y` all points in `x` within distance `r`. r"""Finds for each element in :obj:`y` all points in :obj:`x` within
distance :obj:`r`.
Args: Args:
x (Tensor): D-dimensional point features. x (Tensor): Node feature matrix
y (Tensor): D-dimensional point features. :math:`\mathbf{X} \in \mathbb{R}^{N \times F}`.
y (Tensor): Node feature matrix
:math:`\mathbf{X} \in \mathbb{R}^{M \times F}`.
r (float): The radius. r (float): The radius.
batch_x (LongTensor, optional): Vector that maps each point to its batch_x (LongTensor, optional): Batch vector
example identifier. If :obj:`None`, all points belong to the same :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
example. If not :obj:`None`, points in the same example need to node to a specific example. (default: :obj:`None`)
have contiguous memory layout and :obj:`batch` needs to be batch_y (LongTensor, optional): Batch vector
ascending. (default: :obj:`None`) :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^M`, which assigns each
batch_y (LongTensor, optional): See `batch_x` (default: :obj:`None`) node to a specific example. (default: :obj:`None`)
max_num_neighbors (int, optional): The maximum number of neighbors to max_num_neighbors (int, optional): The maximum number of neighbors to
return for each element in `y`. (default: :obj:`32`) return for each element in :obj:`y`. (default: :obj:`32`)
:rtype: :class:`LongTensor` :rtype: :class:`LongTensor`
Examples:: .. testsetup::
import torch
from torch_cluster import radius
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) >>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch_x = torch.tensor([0, 0, 0, 0]) >>> batch_x = torch.tensor([0, 0, 0, 0])
...@@ -63,24 +72,28 @@ def radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32): ...@@ -63,24 +72,28 @@ def radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32):
def radius_graph(x, r, batch=None, loop=False, max_num_neighbors=32): def radius_graph(x, r, batch=None, loop=False, max_num_neighbors=32):
"""Finds for each element in `x` all points in `x` within distance `r`. r"""Computes graph edges to all points within a given distance.
Args: Args:
x (Tensor): D-dimensional point features. x (Tensor): Node feature matrix
:math:`\mathbf{X} \in \mathbb{R}^{N \times F}`.
r (float): The radius. r (float): The radius.
batch (LongTensor, optional): Vector that maps each point to its batch (LongTensor, optional): Batch vector
example identifier. If :obj:`None`, all points belong to the same :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
example. If not :obj:`None`, points in the same example need to node to a specific example. (default: :obj:`None`)
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
loop (bool, optional): If :obj:`True`, the graph will contain loop (bool, optional): If :obj:`True`, the graph will contain
self-loops. (default: :obj:`False`) self-loops. (default: :obj:`False`)
max_num_neighbors (int, optional): The maximum number of neighbors to max_num_neighbors (int, optional): The maximum number of neighbors to
return for each element in `y`. (default: :obj:`32`) return for each element in :obj:`y`. (default: :obj:`32`)
:rtype: :class:`LongTensor` :rtype: :class:`LongTensor`
Examples:: .. testsetup::
import torch
from torch_cluster import radius_graph
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) >>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch = torch.tensor([0, 0, 0, 0]) >>> batch = torch.tensor([0, 0, 0, 0])
......
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