Unverified Commit 7ba9cbc6 authored by Quan (Andy) Gan's avatar Quan (Andy) Gan Committed by GitHub
Browse files

[Docs] Fix docstrings and documentations (#1420)

* fix docs of to_block

* fix

* oops

* more fixes
parent e3793a5c
...@@ -246,7 +246,7 @@ Dataset Classes ...@@ -246,7 +246,7 @@ Dataset Classes
If your dataset is stored in a ``.csv`` file, you may find it helpful to use If your dataset is stored in a ``.csv`` file, you may find it helpful to use
.. autoclass:: dgl.data.chem.CSVDataset .. autoclass:: dgl.data.chem.MoleculeCSVDataset
:members: __getitem__, __len__ :members: __getitem__, __len__
Currently four datasets are supported: Currently four datasets are supported:
......
...@@ -15,6 +15,7 @@ API Reference ...@@ -15,6 +15,7 @@ API Reference
propagate propagate
udf udf
sampler sampler
sampling
data data
transform transform
graph_store graph_store
......
.. _api-sampling:
dgl.sampling
=================================
.. automodule:: dgl.sampling
Sampling algorithms on graphs.
Random walk sampling functions
------------------------------
.. autosummary::
:toctree: ../../generated/
random_walk
pack_traces
Neighbor sampling functions
---------------------------
.. autosummary::
:toctree: ../../generated/
sample_neighbors
select_topk
Builtin sampler classes for more complicated sampling algorithms
----------------------------------------------------------------
.. autoclass:: RandomWalkNeighborSampler
.. autoclass:: PinSAGESampler
...@@ -178,6 +178,7 @@ class PinSAGESampler(RandomWalkNeighborSampler): ...@@ -178,6 +178,7 @@ class PinSAGESampler(RandomWalkNeighborSampler):
Examples Examples
-------- --------
Generate a random bidirectional bipartite graph with 3000 "A" nodes and 5000 "B" nodes. Generate a random bidirectional bipartite graph with 3000 "A" nodes and 5000 "B" nodes.
>>> g = scipy.sparse.random(3000, 5000, 0.003) >>> g = scipy.sparse.random(3000, 5000, 0.003)
>>> G = dgl.heterograph({ >>> G = dgl.heterograph({
... ('A', 'AB', 'B'): g, ... ('A', 'AB', 'B'): g,
...@@ -185,10 +186,12 @@ class PinSAGESampler(RandomWalkNeighborSampler): ...@@ -185,10 +186,12 @@ class PinSAGESampler(RandomWalkNeighborSampler):
Then we create a PinSAGE neighbor sampler that samples a graph of node type "A". Each Then we create a PinSAGE neighbor sampler that samples a graph of node type "A". Each
node would have (a maximum of) 10 neighbors. node would have (a maximum of) 10 neighbors.
>>> sampler = dgl.sampling.PinSAGESampler(G, 'A', 'B', 3, 0.5, 200, 10) >>> sampler = dgl.sampling.PinSAGESampler(G, 'A', 'B', 3, 0.5, 200, 10)
This is how we select the neighbors for node #0, #1 and #2 of type "A" according to This is how we select the neighbors for node #0, #1 and #2 of type "A" according to
PinSAGE algorithm: PinSAGE algorithm:
>>> seeds = torch.LongTensor([0, 1, 2]) >>> seeds = torch.LongTensor([0, 1, 2])
>>> frontier = sampler(seeds) >>> frontier = sampler(seeds)
>>> frontier.all_edges(form='uv') >>> frontier.all_edges(form='uv')
......
...@@ -884,21 +884,21 @@ def to_block(g, dst_nodes=None, include_dst_in_src=True): ...@@ -884,21 +884,21 @@ def to_block(g, dst_nodes=None, include_dst_in_src=True):
>>> g = dgl.bipartite([(0, 1), (1, 2), (2, 3)], utype='A', vtype='B') >>> g = dgl.bipartite([(0, 1), (1, 2), (2, 3)], utype='A', vtype='B')
If you don't specify any node of type A on the right hand side, the node type ``A`` If you don't specify any node of type A on the right hand side, the node type ``A``
in the block would have zero nodes. in the block would have zero nodes on the DST side.
>>> block = dgl.to_block(g, {'B': torch.LongTensor([3, 2])}) >>> block = dgl.to_block(g, {'B': torch.LongTensor([3, 2])})
>>> block.number_of_nodes('A') >>> block.number_of_dst_nodes('A')
0 0
>>> block.number_of_nodes('B') >>> block.number_of_dst_nodes('B')
2 2
>>> block.nodes['B'].data[dgl.NID] >>> block.dstnodes['B'].data[dgl.NID]
tensor([3, 2]) tensor([3, 2])
The left hand side would contain all the nodes on the right hand side: The left hand side would contain all the nodes on the right hand side:
>>> block.nodes['B'].data[dgl.NID] >>> block.srcnodes['B'].data[dgl.NID]
tensor([3, 2]) tensor([3, 2])
As well as all the nodes that have connections to the nodes on the right hand side: As well as all the nodes that have connections to the nodes on the right hand side:
>>> block.nodes['A'].data[dgl.NID] >>> block.srcnodes['A'].data[dgl.NID]
tensor([2, 1]) tensor([2, 1])
""" """
if dst_nodes is None: if dst_nodes is None:
......
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