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
dgl
Commits
2a715f2f
Unverified
Commit
2a715f2f
authored
Sep 14, 2023
by
Rhett Ying
Committed by
GitHub
Sep 14, 2023
Browse files
[GraphBolt] skip empty mask (#6331)
parent
4ea2bd45
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
python/dgl/graphbolt/impl/csc_sampling_graph.py
python/dgl/graphbolt/impl/csc_sampling_graph.py
+2
-0
tests/python/pytorch/graphbolt/impl/test_csc_sampling_graph.py
.../python/pytorch/graphbolt/impl/test_csc_sampling_graph.py
+30
-3
No files found.
python/dgl/graphbolt/impl/csc_sampling_graph.py
View file @
2a715f2f
...
...
@@ -242,6 +242,8 @@ class CSCSamplingGraph:
src_ntype_id
=
self
.
metadata
.
node_type_to_id
[
src_ntype
]
dst_ntype_id
=
self
.
metadata
.
node_type_to_id
[
dst_ntype
]
mask
=
type_per_edge
==
etype_id
if
mask
.
count_nonzero
()
==
0
:
continue
hetero_row
=
row
[
mask
]
-
self
.
node_type_offset
[
src_ntype_id
]
hetero_column
=
(
column
[
mask
]
-
self
.
node_type_offset
[
dst_ntype_id
]
...
...
tests/python/pytorch/graphbolt/impl/test_csc_sampling_graph.py
View file @
2a715f2f
...
...
@@ -547,7 +547,7 @@ def test_sample_neighbors_hetero(labor):
metadata
=
metadata
,
)
#
Generate subgraph via sample neighbor
s.
#
Sample on both node type
s.
nodes
=
{
"n1"
:
torch
.
LongTensor
([
0
]),
"n2"
:
torch
.
LongTensor
([
0
])}
fanouts
=
torch
.
tensor
([
-
1
,
-
1
])
sampler
=
graph
.
sample_layer_neighbors
if
labor
else
graph
.
sample_neighbors
...
...
@@ -572,6 +572,27 @@ def test_sample_neighbors_hetero(labor):
assert
subgraph
.
reverse_row_node_ids
is
None
assert
subgraph
.
reverse_edge_ids
is
None
# Sample on single node type.
nodes
=
{
"n1"
:
torch
.
LongTensor
([
0
])}
fanouts
=
torch
.
tensor
([
-
1
,
-
1
])
sampler
=
graph
.
sample_layer_neighbors
if
labor
else
graph
.
sample_neighbors
subgraph
=
sampler
(
nodes
,
fanouts
)
# Verify in subgraph.
expected_node_pairs
=
{
"n2:e2:n1"
:
(
torch
.
LongTensor
([
0
,
2
]),
torch
.
LongTensor
([
0
,
0
]),
),
}
assert
len
(
subgraph
.
node_pairs
)
==
1
for
etype
,
pairs
in
expected_node_pairs
.
items
():
assert
torch
.
equal
(
subgraph
.
node_pairs
[
etype
][
0
],
pairs
[
0
])
assert
torch
.
equal
(
subgraph
.
node_pairs
[
etype
][
1
],
pairs
[
1
])
assert
subgraph
.
reverse_column_node_ids
is
None
assert
subgraph
.
reverse_row_node_ids
is
None
assert
subgraph
.
reverse_edge_ids
is
None
@
unittest
.
skipIf
(
F
.
_default_context_str
==
"gpu"
,
...
...
@@ -634,8 +655,14 @@ def test_sample_neighbors_fanouts(
subgraph
=
sampler
(
nodes
,
fanouts
)
# Verify in subgraph.
assert
subgraph
.
node_pairs
[
"n1:e1:n2"
][
0
].
numel
()
==
expected_sampled_num1
assert
subgraph
.
node_pairs
[
"n2:e2:n1"
][
0
].
numel
()
==
expected_sampled_num2
assert
(
expected_sampled_num1
==
0
or
subgraph
.
node_pairs
[
"n1:e1:n2"
][
0
].
numel
()
==
expected_sampled_num1
)
assert
(
expected_sampled_num2
==
0
or
subgraph
.
node_pairs
[
"n2:e2:n1"
][
0
].
numel
()
==
expected_sampled_num2
)
@
unittest
.
skipIf
(
...
...
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