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
17198e9e
Unverified
Commit
17198e9e
authored
Sep 27, 2023
by
Hongzhi (Steve), Chen
Committed by
GitHub
Sep 27, 2023
Browse files
[Graphbolt] Rename num_nodes and num_edges. (#6388)
parent
297e120f
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
185 additions
and
144 deletions
+185
-144
python/dgl/graphbolt/impl/csc_sampling_graph.py
python/dgl/graphbolt/impl/csc_sampling_graph.py
+14
-11
tests/python/pytorch/graphbolt/impl/test_csc_sampling_graph.py
.../python/pytorch/graphbolt/impl/test_csc_sampling_graph.py
+156
-120
tests/python/pytorch/graphbolt/impl/test_ondisk_dataset.py
tests/python/pytorch/graphbolt/impl/test_ondisk_dataset.py
+6
-6
tests/python/pytorch/graphbolt/test_feature_fetcher.py
tests/python/pytorch/graphbolt/test_feature_fetcher.py
+9
-7
No files found.
python/dgl/graphbolt/impl/csc_sampling_graph.py
View file @
17198e9e
...
...
@@ -87,7 +87,7 @@ class CSCSamplingGraph:
self
.
_metadata
=
metadata
@
property
def
num_nodes
(
self
)
->
int
:
def
total_
num_nodes
(
self
)
->
int
:
"""Returns the number of nodes in the graph.
Returns
...
...
@@ -98,7 +98,7 @@ class CSCSamplingGraph:
return
self
.
_c_csc_graph
.
num_nodes
()
@
property
def
num_edges
(
self
)
->
int
:
def
total_
num_edges
(
self
)
->
int
:
"""Returns the number of edges in the graph.
Returns
...
...
@@ -116,7 +116,7 @@ class CSCSamplingGraph:
-------
torch.tensor
The indices pointer in the CSC graph. An integer tensor with
shape `(num_nodes+1,)`.
shape `(
total_
num_nodes+1,)`.
"""
return
self
.
_c_csc_graph
.
csc_indptr
()
...
...
@@ -128,7 +128,7 @@ class CSCSamplingGraph:
-------
torch.tensor
The indices in the CSC graph. An integer tensor with shape
`(num_edges,)`.
`(
total_
num_edges,)`.
Notes
-------
...
...
@@ -161,7 +161,7 @@ class CSCSamplingGraph:
Returns
-------
torch.Tensor or None
If present, returns a 1D integer tensor of shape (num_edges,)
If present, returns a 1D integer tensor of shape (
total_
num_edges,)
containing the type of each edge in the graph.
"""
return
self
.
_c_csc_graph
.
type_per_edge
()
...
...
@@ -377,7 +377,7 @@ class CSCSamplingGraph:
probs_or_mask
=
self
.
edge_attributes
[
probs_name
]
assert
probs_or_mask
.
dim
()
==
1
,
"Probs should be 1-D tensor."
assert
(
probs_or_mask
.
size
(
0
)
==
self
.
num_edges
probs_or_mask
.
size
(
0
)
==
self
.
total_
num_edges
),
"Probs should have the same number of elements as the number
\
of edges."
assert
probs_or_mask
.
dtype
in
[
...
...
@@ -566,7 +566,7 @@ class CSCSamplingGraph:
-
self
.
node_type_offset
[
dst_node_type_id
]
)
else
:
max_node_id
=
self
.
num_nodes
max_node_id
=
self
.
total_
num_nodes
return
self
.
_c_csc_graph
.
sample_negative_edges_uniform
(
node_pairs
,
negative_ratio
,
...
...
@@ -606,10 +606,10 @@ def from_csc(
----------
csc_indptr : torch.Tensor
Pointer to the start of each row in the `indices`. An integer tensor
with shape `(num_nodes+1,)`.
with shape `(
total_
num_nodes+1,)`.
indices : torch.Tensor
Column indices of the non-zero elements in the CSC graph. An integer
tensor with shape `(num_edges,)`.
tensor with shape `(
total_
num_edges,)`.
node_type_offset : Optional[torch.tensor], optional
Offset of node types in the graph, by default None.
type_per_edge : Optional[torch.tensor], optional
...
...
@@ -637,7 +637,7 @@ def from_csc(
>>> print(graph)
CSCSamplingGraph(csc_indptr=tensor([0, 2, 5, 7]),
indices=tensor([1, 3, 0, 1, 2, 0, 3]),
num_nodes=3, num_edges=7)
total_
num_nodes=3,
total_
num_edges=7)
"""
if
metadata
and
metadata
.
node_type_to_id
and
node_type_offset
is
not
None
:
assert
len
(
metadata
.
node_type_to_id
)
+
1
==
node_type_offset
.
size
(
...
...
@@ -683,7 +683,10 @@ def _csc_sampling_graph_str(graph: CSCSamplingGraph) -> str:
"""
csc_indptr_str
=
str
(
graph
.
csc_indptr
)
indices_str
=
str
(
graph
.
indices
)
meta_str
=
f
"num_nodes=
{
graph
.
num_nodes
}
, num_edges=
{
graph
.
num_edges
}
"
meta_str
=
(
f
"total_num_nodes=
{
graph
.
total_num_nodes
}
, total_num_edges="
f
"
{
graph
.
total_num_edges
}
"
)
prefix
=
f
"
{
type
(
graph
).
__name__
}
("
def
_add_indent
(
_str
,
indent
):
...
...
tests/python/pytorch/graphbolt/impl/test_csc_sampling_graph.py
View file @
17198e9e
This diff is collapsed.
Click to expand it.
tests/python/pytorch/graphbolt/impl/test_ondisk_dataset.py
View file @
17198e9e
...
...
@@ -961,8 +961,8 @@ def test_OnDiskDataset_Graph_homogeneous():
dataset
=
gb
.
OnDiskDataset
(
test_dir
).
load
()
graph2
=
dataset
.
graph
assert
graph
.
num_nodes
==
graph2
.
num_nodes
assert
graph
.
num_edges
==
graph2
.
num_edges
assert
graph
.
total_
num_nodes
==
graph2
.
total_
num_nodes
assert
graph
.
total_
num_edges
==
graph2
.
total_
num_edges
assert
torch
.
equal
(
graph
.
csc_indptr
,
graph2
.
csc_indptr
)
assert
torch
.
equal
(
graph
.
indices
,
graph2
.
indices
)
...
...
@@ -1004,8 +1004,8 @@ def test_OnDiskDataset_Graph_heterogeneous():
dataset
=
gb
.
OnDiskDataset
(
test_dir
).
load
()
graph2
=
dataset
.
graph
assert
graph
.
num_nodes
==
graph2
.
num_nodes
assert
graph
.
num_edges
==
graph2
.
num_edges
assert
graph
.
total_
num_nodes
==
graph2
.
total_
num_nodes
assert
graph
.
total_
num_edges
==
graph2
.
total_
num_edges
assert
torch
.
equal
(
graph
.
csc_indptr
,
graph2
.
csc_indptr
)
assert
torch
.
equal
(
graph
.
indices
,
graph2
.
indices
)
...
...
@@ -1076,8 +1076,8 @@ def test_OnDiskDataset_preprocess_homogeneous():
csc_sampling_graph
=
gb
.
csc_sampling_graph
.
load_csc_sampling_graph
(
os
.
path
.
join
(
test_dir
,
processed_dataset
[
"graph_topology"
][
"path"
])
)
assert
csc_sampling_graph
.
num_nodes
==
num_nodes
assert
csc_sampling_graph
.
num_edges
==
num_edges
assert
csc_sampling_graph
.
total_
num_nodes
==
num_nodes
assert
csc_sampling_graph
.
total_
num_edges
==
num_edges
num_samples
=
100
fanout
=
1
...
...
tests/python/pytorch/graphbolt/test_feature_fetcher.py
View file @
17198e9e
...
...
@@ -7,8 +7,8 @@ from torchdata.datapipes.iter import Mapper
def
test_FeatureFetcher_invoke
():
# Prepare graph and required datapipes.
graph
=
gb_test_utils
.
rand_csc_graph
(
20
,
0.15
)
a
=
torch
.
randint
(
0
,
10
,
(
graph
.
num_nodes
,))
b
=
torch
.
randint
(
0
,
10
,
(
graph
.
num_edges
,))
a
=
torch
.
randint
(
0
,
10
,
(
graph
.
total_
num_nodes
,))
b
=
torch
.
randint
(
0
,
10
,
(
graph
.
total_
num_edges
,))
features
=
{}
keys
=
[(
"node"
,
None
,
"a"
),
(
"edge"
,
None
,
"b"
)]
...
...
@@ -35,8 +35,8 @@ def test_FeatureFetcher_invoke():
def
test_FeatureFetcher_homo
():
graph
=
gb_test_utils
.
rand_csc_graph
(
20
,
0.15
)
a
=
torch
.
randint
(
0
,
10
,
(
graph
.
num_nodes
,))
b
=
torch
.
randint
(
0
,
10
,
(
graph
.
num_edges
,))
a
=
torch
.
randint
(
0
,
10
,
(
graph
.
total_
num_nodes
,))
b
=
torch
.
randint
(
0
,
10
,
(
graph
.
total_
num_edges
,))
features
=
{}
keys
=
[(
"node"
,
None
,
"a"
),
(
"edge"
,
None
,
"b"
)]
...
...
@@ -56,8 +56,8 @@ def test_FeatureFetcher_homo():
def
test_FeatureFetcher_with_edges_homo
():
graph
=
gb_test_utils
.
rand_csc_graph
(
20
,
0.15
)
a
=
torch
.
randint
(
0
,
10
,
(
graph
.
num_nodes
,))
b
=
torch
.
randint
(
0
,
10
,
(
graph
.
num_edges
,))
a
=
torch
.
randint
(
0
,
10
,
(
graph
.
total_
num_nodes
,))
b
=
torch
.
randint
(
0
,
10
,
(
graph
.
total_
num_edges
,))
def
add_node_and_edge_ids
(
seeds
):
subgraphs
=
[]
...
...
@@ -65,7 +65,9 @@ def test_FeatureFetcher_with_edges_homo():
subgraphs
.
append
(
gb
.
SampledSubgraphImpl
(
node_pairs
=
(
torch
.
tensor
([]),
torch
.
tensor
([])),
original_edge_ids
=
torch
.
randint
(
0
,
graph
.
num_edges
,
(
10
,)),
original_edge_ids
=
torch
.
randint
(
0
,
graph
.
total_num_edges
,
(
10
,)
),
)
)
data
=
gb
.
MiniBatch
(
input_nodes
=
seeds
,
sampled_subgraphs
=
subgraphs
)
...
...
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