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

add exclude self option for EdgeDataLoader (#3122)


Co-authored-by: default avatarMinjie Wang <wmjlyjemaine@gmail.com>
parent b576e617
...@@ -77,6 +77,9 @@ def _find_exclude_eids(g, exclude_mode, eids, **kwargs): ...@@ -77,6 +77,9 @@ def _find_exclude_eids(g, exclude_mode, eids, **kwargs):
None (default) None (default)
Does not exclude any edge. Does not exclude any edge.
'self'
Exclude the given edges themselves but nothing else.
'reverse_id' 'reverse_id'
Exclude all edges specified in ``eids``, as well as their reverse edges Exclude all edges specified in ``eids``, as well as their reverse edges
of the same edge type. of the same edge type.
...@@ -105,6 +108,8 @@ def _find_exclude_eids(g, exclude_mode, eids, **kwargs): ...@@ -105,6 +108,8 @@ def _find_exclude_eids(g, exclude_mode, eids, **kwargs):
""" """
if exclude_mode is None: if exclude_mode is None:
return None return None
elif exclude_mode == 'self':
return eids
elif exclude_mode == 'reverse_id': elif exclude_mode == 'reverse_id':
return _find_exclude_eids_with_reverse_id(g, eids, kwargs['reverse_eid_map']) return _find_exclude_eids_with_reverse_id(g, eids, kwargs['reverse_eid_map'])
elif exclude_mode == 'reverse_types': elif exclude_mode == 'reverse_types':
...@@ -493,6 +498,8 @@ class EdgeCollator(Collator): ...@@ -493,6 +498,8 @@ class EdgeCollator(Collator):
* None, which excludes nothing. * None, which excludes nothing.
* ``'self'``, which excludes the sampled edges themselves but nothing else.
* ``'reverse_id'``, which excludes the reverse edges of the sampled edges. The said * ``'reverse_id'``, which excludes the reverse edges of the sampled edges. The said
reverse edges have the same edge type as the sampled edges. Only works reverse edges have the same edge type as the sampled edges. Only works
on edge types whose source node type is the same as its destination node type. on edge types whose source node type is the same as its destination node type.
......
...@@ -607,6 +607,7 @@ class EdgeDataLoader: ...@@ -607,6 +607,7 @@ class EdgeDataLoader:
minibatch. Possible values are minibatch. Possible values are
* None, * None,
* ``self``,
* ``reverse_id``, * ``reverse_id``,
* ``reverse_types`` * ``reverse_types``
......
...@@ -121,6 +121,12 @@ def test_neighbor_sampler_dataloader(): ...@@ -121,6 +121,12 @@ def test_neighbor_sampler_dataloader():
nids.append({'follow': seeds}) nids.append({'follow': seeds})
modes.append('edge') modes.append('edge')
collators.append(dgl.dataloading.EdgeCollator(
g, seeds, sampler, exclude='self'))
graphs.append(g)
nids.append({'follow': seeds})
modes.append('edge')
collators.append(dgl.dataloading.EdgeCollator( collators.append(dgl.dataloading.EdgeCollator(
g, seeds, sampler, exclude='reverse_id', reverse_eids=reverse_eids)) g, seeds, sampler, exclude='reverse_id', reverse_eids=reverse_eids))
graphs.append(g) graphs.append(g)
...@@ -133,6 +139,12 @@ def test_neighbor_sampler_dataloader(): ...@@ -133,6 +139,12 @@ def test_neighbor_sampler_dataloader():
nids.append({'follow': seeds}) nids.append({'follow': seeds})
modes.append('link') modes.append('link')
collators.append(dgl.dataloading.EdgeCollator(
g, seeds, sampler, exclude='self', negative_sampler=dgl.dataloading.negative_sampler.Uniform(2)))
graphs.append(g)
nids.append({'follow': seeds})
modes.append('link')
collators.append(dgl.dataloading.EdgeCollator( collators.append(dgl.dataloading.EdgeCollator(
g, seeds, sampler, exclude='reverse_id', reverse_eids=reverse_eids, g, seeds, sampler, exclude='reverse_id', reverse_eids=reverse_eids,
negative_sampler=dgl.dataloading.negative_sampler.Uniform(2))) negative_sampler=dgl.dataloading.negative_sampler.Uniform(2)))
......
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