Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-cluster
Commits
0a038334
Commit
0a038334
authored
Dec 17, 2018
by
rusty1s
Browse files
update doc
parent
21208fce
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
110 additions
and
72 deletions
+110
-72
README.md
README.md
+9
-9
torch_cluster/fps.py
torch_cluster/fps.py
+18
-13
torch_cluster/knn.py
torch_cluster/knn.py
+30
-18
torch_cluster/nearest.py
torch_cluster/nearest.py
+20
-12
torch_cluster/radius.py
torch_cluster/radius.py
+33
-20
No files found.
README.md
View file @
0a038334
...
...
@@ -90,7 +90,7 @@ tensor([0, 5, 3, 0, 1])
## 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
import
torch
...
...
@@ -98,7 +98,7 @@ from torch_cluster import fps
x
=
torch
.
Tensor
([[
-
1
,
-
1
],
[
-
1
,
1
],
[
1
,
-
1
],
[
1
,
1
]])
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])
## kNN-Graph
Computes graph edges to the nearest
*k*
points
in metric space
.
Computes graph edges to the nearest
*k*
points.
```
python
import
torch
...
...
@@ -127,7 +127,7 @@ tensor([[0, 0, 1, 1, 2, 2, 3, 3],
## 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
import
torch
...
...
@@ -146,17 +146,17 @@ tensor([[0, 0, 1, 1, 2, 2, 3, 3],
## 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
import
torch
from
torch_cluster
import
nearest
x
=
torch
.
Tensor
([[
-
1
,
-
1
],
[
-
1
,
1
],
[
1
,
-
1
],
[
1
,
1
]])
batch_x
=
torch
.
T
ensor
([
0
,
0
,
0
,
0
])
query_x
=
torch
.
Tensor
([[
-
1
,
0
],
[
1
,
0
]])
query_
batch
=
torch
.
T
ensor
([
0
,
0
])
cluster
=
nearest
(
x
,
query_x
,
batch_x
,
query_
batch
)
batch_x
=
torch
.
t
ensor
([
0
,
0
,
0
,
0
])
y
=
torch
.
Tensor
([[
-
1
,
0
],
[
1
,
0
]])
batch
_y
=
torch
.
t
ensor
([
0
,
0
])
cluster
=
nearest
(
x
,
y
,
batch_x
,
batch
_y
)
```
```
...
...
torch_cluster/fps.py
View file @
0a038334
...
...
@@ -2,31 +2,36 @@ import torch
if
torch
.
cuda
.
is_available
():
import
fps_cuda
""" """
def
fps
(
x
,
batch
=
None
,
ratio
=
0.5
,
random_start
=
True
):
"""Iteratively samples the most distant point (in metric distance) with
regard to the rest points.
r
""""A sampling algorithm from the `"PointNet++: Deep Hierarchical Feature
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:
x (Tensor): D-dimensional point features.
batch (LongTensor, optional): Vector that maps each point to its
example identifier. If :obj:`None`, all points belong to the same
example. If not :obj:`None`, points in the same example need to
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
x (Tensor): Node feature matrix
:math:`\mathbf{X} \in \mathbb{R}^{N \times F}`.
batch (LongTensor, optional): Batch vector
:math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
node to a specific example. (default: :obj:`None`)
ratio (float, optional): Sampling ratio. (default: :obj:`0.5`)
random_start (bool, optional):
Whether the starting node is
sampled randomly
. (default:
:
obj:`True`)
random_start (bool, optional):
If set to :obj:`False`, use the first
node in :math:`\mathbf{X}` as starting node
. (default: obj:`True`)
:rtype: :class:`LongTensor`
Examples::
.. testsetup::
import torch
from torch_cluster import fps
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> 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
:
...
...
torch_cluster/knn.py
View file @
0a038334
...
...
@@ -6,22 +6,30 @@ if torch.cuda.is_available():
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:
x (Tensor): D-dimensional point features.
y (Tensor): D-dimensional point features.
x (Tensor): Node feature matrix
: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.
batch_x (LongTensor, optional):
Vector that maps each point to its
example identifier. If :obj:`None`, all points belong to the same
example. If not :obj:`None`, points in the same example need to
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
batch_y (LongTensor, optional): See `batch_x`
(default: :obj:`None`)
batch_x (LongTensor, optional):
Batch vector
:math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
node to a specific example. (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`)
:rtype: :class:`LongTensor`
Examples::
.. testsetup::
import torch
from torch_cluster import knn
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch_x = torch.tensor([0, 0, 0, 0])
...
...
@@ -70,22 +78,26 @@ def knn(x, y, k, batch_x=None, batch_y=None):
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:
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.
batch (LongTensor, optional): Vector that maps each point to its
example identifier. If :obj:`None`, all points belong to the same
example. If not :obj:`None`, points in the same example need to
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
batch (LongTensor, optional): Batch vector
:math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
node to a specific example. (default: :obj:`None`)
loop (bool, optional): If :obj:`True`, the graph will contain
self-loops. (default: :obj:`False`)
: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]])
>>> batch = torch.tensor([0, 0, 0, 0])
...
...
torch_cluster/nearest.py
View file @
0a038334
...
...
@@ -6,24 +6,32 @@ if torch.cuda.is_available():
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:
x (Tensor): D-dimensional point features.
y (Tensor): D-dimensional point features.
batch_x (LongTensor, optional): Vector that maps each point to its
example identifier. If :obj:`None`, all points belong to the same
example. If not :obj:`None`, points in the same example need to
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
batch_y (LongTensor, optional): See `batch_x` (default: :obj:`None`)
x (Tensor): Node feature matrix
:math:`\mathbf{X} \in \mathbb{R}^{N
\t
imes F}`.
y (Tensor): Node feature matrix
:math:`\mathbf{X} \in \mathbb{R}^{M
\t
imes F}`.
batch_x (LongTensor, optional): Batch vector
:math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
node to a specific example. (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]])
>>> batch_x = torch.
T
ensor([0, 0, 0, 0])
>>> batch_x = torch.
t
ensor([0, 0, 0, 0])
>>> y = torch.Tensor([[-1, 0], [1, 0]])
>>> batch_x = torch.
T
ensor([0, 0])
>>> batch_x = torch.
t
ensor([0, 0])
>>> cluster = nearest(x, y, batch_x, batch_y)
"""
...
...
torch_cluster/radius.py
View file @
0a038334
...
...
@@ -6,24 +6,33 @@ if torch.cuda.is_available():
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:
x (Tensor): D-dimensional point features.
y (Tensor): D-dimensional point features.
x (Tensor): Node feature matrix
: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.
batch_x (LongTensor, optional):
Vector that maps each point to its
example identifier. If :obj:`None`, all points belong to the same
example. If not :obj:`None`, points in the same example need to
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
batch_y (LongTensor, optional): See `batch_x`
(default: :obj:`None`)
batch_x (LongTensor, optional):
Batch vector
:math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
node to a specific example. (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`)
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`
Examples::
.. testsetup::
import torch
from torch_cluster import radius
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> 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):
def
radius_graph
(
x
,
r
,
batch
=
None
,
loop
=
False
,
max_num_neighbors
=
32
):
"""
Finds for each element in `x` all points in `x` withi
n distance
`r`
.
r
"""
Computes graph edges to all points within a give
n distance.
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.
batch (LongTensor, optional): Vector that maps each point to its
example identifier. If :obj:`None`, all points belong to the same
example. If not :obj:`None`, points in the same example need to
have contiguous memory layout and :obj:`batch` needs to be
ascending. (default: :obj:`None`)
batch (LongTensor, optional): Batch vector
:math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`, which assigns each
node to a specific example. (default: :obj:`None`)
loop (bool, optional): If :obj:`True`, the graph will contain
self-loops. (default: :obj:`False`)
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`
Examples::
.. testsetup::
import torch
from torch_cluster import radius_graph
.. testcode::
>>> x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
>>> batch = torch.tensor([0, 0, 0, 0])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment