-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Doc] Re-organize the code for dgl.geometry, and expose it in the doc (…
…dmlc#2982) * reorg and expose dgl.geometry * fix lint * fix test * fix
- Loading branch information
Showing
14 changed files
with
122 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.. _api-geometry: | ||
|
||
dgl.geometry | ||
================================= | ||
|
||
.. automodule:: dgl.geometry | ||
|
||
.. _api-geometry-farthest-point-sampler: | ||
|
||
Farthest Point Sampler | ||
----------- | ||
|
||
Farthest point sampling is a greedy algorithm that samples from a point cloud | ||
data iteratively. It starts from a random single sample of point. In each iteration, | ||
it samples from the rest points that is the farthest from the set of sampled points. | ||
|
||
.. autoclass:: farthest_point_sampler | ||
|
||
.. _api-geometry-neighbor-matching: | ||
|
||
Neighbor Matching | ||
----------------------------- | ||
|
||
Neighbor matching is an important module in the Graclus clustering algorithm. | ||
|
||
.. autoclass:: neighbor_matching |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
"""Package for geometry common components.""" | ||
import importlib | ||
import sys | ||
from ..backend import backend_name | ||
"""The ``dgl.geometry`` package contains geometry operations: | ||
* Farthest point sampling for point cloud sampling | ||
def _load_backend(mod_name): | ||
mod = importlib.import_module('.%s' % mod_name, __name__) | ||
thismod = sys.modules[__name__] | ||
for api, obj in mod.__dict__.items(): | ||
setattr(thismod, api, obj) | ||
* Neighbor matching module for graclus pooling | ||
_load_backend(backend_name) | ||
.. note:: | ||
This package is experimental and the interfaces may be subject | ||
to changes in future releases. | ||
""" | ||
from .fps import * | ||
from .edge_coarsening import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Farthest Point Sampler for pytorch Geometry package""" | ||
#pylint: disable=no-member, invalid-name | ||
|
||
from .. import backend as F | ||
|
||
from ..base import DGLError | ||
from .capi import _farthest_point_sampler | ||
|
||
__all__ = ['farthest_point_sampler'] | ||
|
||
def farthest_point_sampler(pos, npoints, start_idx=None): | ||
"""Farthest Point Sampler without the need to compute all pairs of distance. | ||
In each batch, the algorithm starts with the sample index specified by ``start_idx``. | ||
Then for each point, we maintain the minimum to-sample distance. | ||
Finally, we pick the point with the maximum such distance. | ||
This process will be repeated for ``sample_points`` - 1 times. | ||
Parameters | ||
---------- | ||
pos : tensor | ||
The positional tensor of shape (B, N, C) | ||
npoints : int | ||
The number of points to sample in each batch. | ||
start_idx : int, optional | ||
If given, appoint the index of the starting point, | ||
otherwise randomly select a point as the start point. | ||
(default: None) | ||
Returns | ||
------- | ||
tensor of shape (B, npoints) | ||
The sampled indices in each batch. | ||
Examples | ||
-------- | ||
The following exmaple uses PyTorch backend. | ||
>>> import torch | ||
>>> from dgl.geometry import farthest_point_sampler | ||
>>> x = torch.rand((2, 10, 3)) | ||
>>> point_idx = farthest_point_sampler(x, 2) | ||
>>> print(point_idx) | ||
tensor([[5, 6], | ||
[7, 8]]) | ||
""" | ||
ctx = F.context(pos) | ||
B, N, C = pos.shape | ||
pos = pos.reshape(-1, C) | ||
dist = F.zeros((B * N), dtype=pos.dtype, ctx=ctx) | ||
if start_idx is None: | ||
start_idx = F.randint(shape=(B, ), dtype=F.int64, ctx=ctx, low=0, high=N-1) | ||
else: | ||
if start_idx >= N or start_idx < 0: | ||
raise DGLError("Invalid start_idx, expected 0 <= start_idx < {}, got {}".format( | ||
N, start_idx)) | ||
start_idx = F.full_1d((B, ), start_idx, dtype=F.int64, ctx=ctx) | ||
result = F.zeros((npoints * B), dtype=F.int64, ctx=ctx) | ||
_farthest_point_sampler(pos, B, npoints, dist, start_idx, result) | ||
return result.reshape(B, npoints) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.