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
3132da28
Unverified
Commit
3132da28
authored
Nov 15, 2022
by
peizhou001
Committed by
GitHub
Nov 15, 2022
Browse files
Deprecate (#4864)
rename DGLHeteroGraph to DGLGraph
parent
ee9887d6
Changes
45
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
126 additions
and
147 deletions
+126
-147
python/dgl/convert.py
python/dgl/convert.py
+9
-9
python/dgl/data/graph_serialize.py
python/dgl/data/graph_serialize.py
+6
-6
python/dgl/data/heterograph_serialize.py
python/dgl/data/heterograph_serialize.py
+6
-6
python/dgl/dataloading/dataloader.py
python/dgl/dataloading/dataloader.py
+11
-11
python/dgl/distributed/dist_graph.py
python/dgl/distributed/dist_graph.py
+2
-2
python/dgl/distributed/graph_services.py
python/dgl/distributed/graph_services.py
+1
-1
python/dgl/distributed/server_state.py
python/dgl/distributed/server_state.py
+1
-1
python/dgl/heterograph.py
python/dgl/heterograph.py
+11
-11
python/dgl/nn/mxnet/hetero.py
python/dgl/nn/mxnet/hetero.py
+2
-2
python/dgl/nn/pytorch/hetero.py
python/dgl/nn/pytorch/hetero.py
+2
-2
python/dgl/nn/tensorflow/hetero.py
python/dgl/nn/tensorflow/hetero.py
+2
-2
python/dgl/ops/sddmm.py
python/dgl/ops/sddmm.py
+3
-3
python/dgl/ops/spmm.py
python/dgl/ops/spmm.py
+2
-2
python/dgl/partition.py
python/dgl/partition.py
+4
-4
python/dgl/propagate.py
python/dgl/propagate.py
+10
-10
python/dgl/sampling/negative.py
python/dgl/sampling/negative.py
+2
-2
python/dgl/sampling/neighbor.py
python/dgl/sampling/neighbor.py
+9
-9
python/dgl/subgraph.py
python/dgl/subgraph.py
+11
-11
python/dgl/transforms/functional.py
python/dgl/transforms/functional.py
+16
-37
python/dgl/traversal.py
python/dgl/traversal.py
+16
-16
No files found.
python/dgl/convert.py
View file @
3132da28
...
@@ -7,7 +7,7 @@ import networkx as nx
...
@@ -7,7 +7,7 @@ import networkx as nx
from
.
import
backend
as
F
from
.
import
backend
as
F
from
.
import
heterograph_index
from
.
import
heterograph_index
from
.heterograph
import
DGL
Hetero
Graph
,
combine_frames
,
DGLBlock
from
.heterograph
import
DGLGraph
,
combine_frames
,
DGLBlock
from
.
import
graph_index
from
.
import
graph_index
from
.
import
utils
from
.
import
utils
from
.base
import
NTYPE
,
ETYPE
,
NID
,
EID
,
DGLError
,
dgl_warning
from
.base
import
NTYPE
,
ETYPE
,
NID
,
EID
,
DGLError
,
dgl_warning
...
@@ -224,7 +224,7 @@ def hetero_from_shared_memory(name):
...
@@ -224,7 +224,7 @@ def hetero_from_shared_memory(name):
HeteroGraph (in shared memory)
HeteroGraph (in shared memory)
"""
"""
g
,
ntypes
,
etypes
=
heterograph_index
.
create_heterograph_from_shared_memory
(
name
)
g
,
ntypes
,
etypes
=
heterograph_index
.
create_heterograph_from_shared_memory
(
name
)
return
DGL
Hetero
Graph
(
g
,
ntypes
,
etypes
)
return
DGLGraph
(
g
,
ntypes
,
etypes
)
def
heterograph
(
data_dict
,
def
heterograph
(
data_dict
,
num_nodes_dict
=
None
,
num_nodes_dict
=
None
,
...
@@ -378,7 +378,7 @@ def heterograph(data_dict,
...
@@ -378,7 +378,7 @@ def heterograph(data_dict,
# create graph index
# create graph index
hgidx
=
heterograph_index
.
create_heterograph_from_relations
(
hgidx
=
heterograph_index
.
create_heterograph_from_relations
(
metagraph
,
[
rgrh
.
_graph
for
rgrh
in
rel_graphs
],
num_nodes_per_type
)
metagraph
,
[
rgrh
.
_graph
for
rgrh
in
rel_graphs
],
num_nodes_per_type
)
retg
=
DGL
Hetero
Graph
(
hgidx
,
ntypes
,
etypes
)
retg
=
DGLGraph
(
hgidx
,
ntypes
,
etypes
)
return
retg
.
to
(
device
)
return
retg
.
to
(
device
)
...
@@ -612,7 +612,7 @@ def block_to_graph(block):
...
@@ -612,7 +612,7 @@ def block_to_graph(block):
"""
"""
new_types
=
[
ntype
+
'_src'
for
ntype
in
block
.
srctypes
]
+
\
new_types
=
[
ntype
+
'_src'
for
ntype
in
block
.
srctypes
]
+
\
[
ntype
+
'_dst'
for
ntype
in
block
.
dsttypes
]
[
ntype
+
'_dst'
for
ntype
in
block
.
dsttypes
]
retg
=
DGL
Hetero
Graph
(
block
.
_graph
,
new_types
,
block
.
etypes
)
retg
=
DGLGraph
(
block
.
_graph
,
new_types
,
block
.
etypes
)
for
srctype
in
block
.
srctypes
:
for
srctype
in
block
.
srctypes
:
retg
.
nodes
[
srctype
+
'_src'
].
data
.
update
(
block
.
srcnodes
[
srctype
].
data
)
retg
.
nodes
[
srctype
+
'_src'
].
data
.
update
(
block
.
srcnodes
[
srctype
].
data
)
...
@@ -1620,7 +1620,7 @@ def to_networkx(g, node_attrs=None, edge_attrs=None):
...
@@ -1620,7 +1620,7 @@ def to_networkx(g, node_attrs=None, edge_attrs=None):
attr
.
update
({
key
:
F
.
squeeze
(
feat_dict
[
key
],
0
)
for
key
in
edge_attrs
})
attr
.
update
({
key
:
F
.
squeeze
(
feat_dict
[
key
],
0
)
for
key
in
edge_attrs
})
return
nx_graph
return
nx_graph
DGL
Hetero
Graph
.
to_networkx
=
to_networkx
DGLGraph
.
to_networkx
=
to_networkx
def
to_cugraph
(
g
):
def
to_cugraph
(
g
):
"""Convert a DGL graph to a :class:`cugraph.Graph` and return.
"""Convert a DGL graph to a :class:`cugraph.Graph` and return.
...
@@ -1677,7 +1677,7 @@ def to_cugraph(g):
...
@@ -1677,7 +1677,7 @@ def to_cugraph(g):
destination
=
'destination'
)
destination
=
'destination'
)
return
g_cugraph
return
g_cugraph
DGL
Hetero
Graph
.
to_cugraph
=
to_cugraph
DGLGraph
.
to_cugraph
=
to_cugraph
def
from_cugraph
(
cugraph_graph
):
def
from_cugraph
(
cugraph_graph
):
"""Create a graph from a :class:`cugraph.Graph` object.
"""Create a graph from a :class:`cugraph.Graph` object.
...
@@ -1766,7 +1766,7 @@ def create_from_edges(sparse_fmt, arrays,
...
@@ -1766,7 +1766,7 @@ def create_from_edges(sparse_fmt, arrays,
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
"""
"""
if
utype
==
vtype
:
if
utype
==
vtype
:
num_ntypes
=
1
num_ntypes
=
1
...
@@ -1784,6 +1784,6 @@ def create_from_edges(sparse_fmt, arrays,
...
@@ -1784,6 +1784,6 @@ def create_from_edges(sparse_fmt, arrays,
num_ntypes
,
urange
,
vrange
,
indptr
,
indices
,
eids
,
[
'coo'
,
'csr'
,
'csc'
],
num_ntypes
,
urange
,
vrange
,
indptr
,
indices
,
eids
,
[
'coo'
,
'csr'
,
'csc'
],
sparse_fmt
==
'csc'
)
sparse_fmt
==
'csc'
)
if
utype
==
vtype
:
if
utype
==
vtype
:
return
DGL
Hetero
Graph
(
hgidx
,
[
utype
],
[
etype
])
return
DGLGraph
(
hgidx
,
[
utype
],
[
etype
])
else
:
else
:
return
DGL
Hetero
Graph
(
hgidx
,
[
utype
,
vtype
],
[
etype
])
return
DGLGraph
(
hgidx
,
[
utype
,
vtype
],
[
etype
])
python/dgl/data/graph_serialize.py
View file @
3132da28
...
@@ -7,7 +7,7 @@ from .. import backend as F
...
@@ -7,7 +7,7 @@ from .. import backend as F
from
.._ffi.function
import
_init_api
from
.._ffi.function
import
_init_api
from
.._ffi.object
import
ObjectBase
,
register_object
from
.._ffi.object
import
ObjectBase
,
register_object
from
..base
import
DGLError
,
dgl_warning
from
..base
import
DGLError
,
dgl_warning
from
..heterograph
import
DGL
Hetero
Graph
from
..heterograph
import
DGLGraph
from
.heterograph_serialize
import
save_heterographs
from
.heterograph_serialize
import
save_heterographs
_init_api
(
"dgl.data.graph_serialize"
)
_init_api
(
"dgl.data.graph_serialize"
)
...
@@ -69,10 +69,10 @@ class GraphData(ObjectBase):
...
@@ -69,10 +69,10 @@ class GraphData(ObjectBase):
return
_CAPI_MakeGraphData
(
ghandle
,
node_tensors
,
edge_tensors
)
return
_CAPI_MakeGraphData
(
ghandle
,
node_tensors
,
edge_tensors
)
def
get_graph
(
self
):
def
get_graph
(
self
):
"""Get DGL
Hetero
Graph from GraphData"""
"""Get DGLGraph from GraphData"""
ghandle
=
_CAPI_GDataGraphHandle
(
self
)
ghandle
=
_CAPI_GDataGraphHandle
(
self
)
hgi
=
_CAPI_DGLAsHeteroGraph
(
ghandle
)
hgi
=
_CAPI_DGLAsHeteroGraph
(
ghandle
)
g
=
DGL
Hetero
Graph
(
hgi
,
[
"_U"
],
[
"_E"
])
g
=
DGLGraph
(
hgi
,
[
"_U"
],
[
"_E"
])
node_tensors_items
=
_CAPI_GDataNodeTensors
(
self
).
items
()
node_tensors_items
=
_CAPI_GDataNodeTensors
(
self
).
items
()
edge_tensors_items
=
_CAPI_GDataEdgeTensors
(
self
).
items
()
edge_tensors_items
=
_CAPI_GDataEdgeTensors
(
self
).
items
()
for
k
,
v
in
node_tensors_items
:
for
k
,
v
in
node_tensors_items
:
...
@@ -142,8 +142,8 @@ def save_graphs(filename, g_list, labels=None, formats=None):
...
@@ -142,8 +142,8 @@ def save_graphs(filename, g_list, labels=None, formats=None):
g_sample
=
g_list
[
0
]
if
isinstance
(
g_list
,
list
)
else
g_list
g_sample
=
g_list
[
0
]
if
isinstance
(
g_list
,
list
)
else
g_list
if
(
if
(
type
(
g_sample
)
==
DGL
Hetero
Graph
type
(
g_sample
)
==
DGLGraph
):
# Doesn't support DGL
Hetero
Graph's derived class
):
# Doesn't support DGLGraph's derived class
save_heterographs
(
filename
,
g_list
,
labels
,
formats
)
save_heterographs
(
filename
,
g_list
,
labels
,
formats
)
else
:
else
:
raise
DGLError
(
raise
DGLError
(
...
@@ -203,7 +203,7 @@ def load_graphs(filename, idx_list=None):
...
@@ -203,7 +203,7 @@ def load_graphs(filename, idx_list=None):
def
load_graph_v2
(
filename
,
idx_list
=
None
):
def
load_graph_v2
(
filename
,
idx_list
=
None
):
"""Internal functions for loading DGL
Hetero
Graphs."""
"""Internal functions for loading DGLGraphs."""
if
idx_list
is
None
:
if
idx_list
is
None
:
idx_list
=
[]
idx_list
=
[]
assert
isinstance
(
idx_list
,
list
)
assert
isinstance
(
idx_list
,
list
)
...
...
python/dgl/data/heterograph_serialize.py
View file @
3132da28
...
@@ -6,7 +6,7 @@ from .._ffi.function import _init_api
...
@@ -6,7 +6,7 @@ from .._ffi.function import _init_api
from
.._ffi.object
import
ObjectBase
,
register_object
from
.._ffi.object
import
ObjectBase
,
register_object
from
..container
import
convert_to_strmap
from
..container
import
convert_to_strmap
from
..frame
import
Frame
from
..frame
import
Frame
from
..heterograph
import
DGL
Hetero
Graph
from
..heterograph
import
DGLGraph
_init_api
(
"dgl.data.heterograph_serialize"
)
_init_api
(
"dgl.data.heterograph_serialize"
)
...
@@ -23,11 +23,11 @@ def save_heterographs(filename, g_list, labels, formats):
...
@@ -23,11 +23,11 @@ def save_heterographs(filename, g_list, labels, formats):
"""Save heterographs into file"""
"""Save heterographs into file"""
if
labels
is
None
:
if
labels
is
None
:
labels
=
{}
labels
=
{}
if
isinstance
(
g_list
,
DGL
Hetero
Graph
):
if
isinstance
(
g_list
,
DGLGraph
):
g_list
=
[
g_list
]
g_list
=
[
g_list
]
assert
all
(
assert
all
(
[
type
(
g
)
==
DGL
Hetero
Graph
for
g
in
g_list
]
[
type
(
g
)
==
DGLGraph
for
g
in
g_list
]
),
"Invalid DGL
Hetero
Graph in g_list argument"
),
"Invalid DGLGraph in g_list argument"
gdata_list
=
[
HeteroGraphData
.
create
(
g
)
for
g
in
g_list
]
gdata_list
=
[
HeteroGraphData
.
create
(
g
)
for
g
in
g_list
]
if
formats
is
None
:
if
formats
is
None
:
formats
=
[]
formats
=
[]
...
@@ -39,7 +39,7 @@ def save_heterographs(filename, g_list, labels, formats):
...
@@ -39,7 +39,7 @@ def save_heterographs(filename, g_list, labels, formats):
@
register_object
(
"heterograph_serialize.HeteroGraphData"
)
@
register_object
(
"heterograph_serialize.HeteroGraphData"
)
class
HeteroGraphData
(
ObjectBase
):
class
HeteroGraphData
(
ObjectBase
):
"""Object to hold the data to be stored for DGL
Hetero
Graph"""
"""Object to hold the data to be stored for DGLGraph"""
@
staticmethod
@
staticmethod
def
create
(
g
):
def
create
(
g
):
...
@@ -75,4 +75,4 @@ class HeteroGraphData(ObjectBase):
...
@@ -75,4 +75,4 @@ class HeteroGraphData(ObjectBase):
}
}
eframes
.
append
(
Frame
(
edict
,
num_rows
=
gidx
.
number_of_edges
(
etid
)))
eframes
.
append
(
Frame
(
edict
,
num_rows
=
gidx
.
number_of_edges
(
etid
)))
return
DGL
Hetero
Graph
(
gidx
,
ntype_names
,
etype_names
,
nframes
,
eframes
)
return
DGLGraph
(
gidx
,
ntype_names
,
etype_names
,
nframes
,
eframes
)
python/dgl/dataloading/dataloader.py
View file @
3132da28
...
@@ -19,7 +19,7 @@ from torch.utils.data.distributed import DistributedSampler
...
@@ -19,7 +19,7 @@ from torch.utils.data.distributed import DistributedSampler
from
..base
import
NID
,
EID
,
dgl_warning
,
DGLError
from
..base
import
NID
,
EID
,
dgl_warning
,
DGLError
from
..batch
import
batch
as
batch_graphs
from
..batch
import
batch
as
batch_graphs
from
..heterograph
import
DGL
Hetero
Graph
from
..heterograph
import
DGLGraph
from
..utils
import
(
from
..utils
import
(
recursive_apply
,
ExceptionWrapper
,
recursive_apply_pair
,
set_num_threads
,
get_num_threads
,
recursive_apply
,
ExceptionWrapper
,
recursive_apply_pair
,
set_num_threads
,
get_num_threads
,
get_numa_nodes_cores
,
context_of
,
dtype_of
)
get_numa_nodes_cores
,
context_of
,
dtype_of
)
...
@@ -283,7 +283,7 @@ def _prefetch_for_subgraph(subg, dataloader):
...
@@ -283,7 +283,7 @@ def _prefetch_for_subgraph(subg, dataloader):
def
_prefetch_for
(
item
,
dataloader
):
def
_prefetch_for
(
item
,
dataloader
):
if
isinstance
(
item
,
DGL
Hetero
Graph
):
if
isinstance
(
item
,
DGLGraph
):
return
_prefetch_for_subgraph
(
item
,
dataloader
)
return
_prefetch_for_subgraph
(
item
,
dataloader
)
elif
isinstance
(
item
,
LazyFeature
):
elif
isinstance
(
item
,
LazyFeature
):
return
dataloader
.
other_storages
[
item
.
name
].
fetch
(
return
dataloader
.
other_storages
[
item
.
name
].
fetch
(
...
@@ -343,7 +343,7 @@ def _prefetch(batch, dataloader, stream):
...
@@ -343,7 +343,7 @@ def _prefetch(batch, dataloader, stream):
def
_assign_for
(
item
,
feat
):
def
_assign_for
(
item
,
feat
):
if
isinstance
(
item
,
DGL
Hetero
Graph
):
if
isinstance
(
item
,
DGLGraph
):
subg
=
item
subg
=
item
for
(
tid
,
key
),
value
in
feat
.
node_feats
.
items
():
for
(
tid
,
key
),
value
in
feat
.
node_feats
.
items
():
assert
isinstance
(
subg
.
_node_frames
[
tid
][
key
],
LazyFeature
)
assert
isinstance
(
subg
.
_node_frames
[
tid
][
key
],
LazyFeature
)
...
@@ -387,17 +387,17 @@ def _prefetcher_entry(
...
@@ -387,17 +387,17 @@ def _prefetcher_entry(
queue
,
(
None
,
None
,
None
,
ExceptionWrapper
(
where
=
'in prefetcher'
)),
done_event
)
queue
,
(
None
,
None
,
None
,
ExceptionWrapper
(
where
=
'in prefetcher'
)),
done_event
)
# DGL
Hetero
Graphs have the semantics of lazy feature slicing with subgraphs. Such behavior depends
# DGLGraphs have the semantics of lazy feature slicing with subgraphs. Such behavior depends
# on that DGL
Hetero
Graph's ndata and edata are maintained by Frames. So to maintain compatibility
# on that DGLGraph's ndata and edata are maintained by Frames. So to maintain compatibility
# with older code, DGL
Hetero
Graphs and other graph storages are handled separately: (1)
# with older code, DGLGraphs and other graph storages are handled separately: (1)
# DGL
Hetero
Graphs will preserve the lazy feature slicing for subgraphs. (2) Other graph storages
# DGLGraphs will preserve the lazy feature slicing for subgraphs. (2) Other graph storages
# will not have lazy feature slicing; all feature slicing will be eager.
# will not have lazy feature slicing; all feature slicing will be eager.
def
remove_parent_storage_columns
(
item
,
g
):
def
remove_parent_storage_columns
(
item
,
g
):
"""Removes the storage objects in the given graphs' Frames if it is a sub-frame of the
"""Removes the storage objects in the given graphs' Frames if it is a sub-frame of the
given parent graph, so that the storages are not serialized during IPC from PyTorch
given parent graph, so that the storages are not serialized during IPC from PyTorch
DataLoader workers.
DataLoader workers.
"""
"""
if
not
isinstance
(
item
,
DGL
Hetero
Graph
)
or
not
isinstance
(
g
,
DGL
Hetero
Graph
):
if
not
isinstance
(
item
,
DGLGraph
)
or
not
isinstance
(
g
,
DGLGraph
):
return
item
return
item
for
subframe
,
frame
in
zip
(
for
subframe
,
frame
in
zip
(
...
@@ -419,7 +419,7 @@ def restore_parent_storage_columns(item, g):
...
@@ -419,7 +419,7 @@ def restore_parent_storage_columns(item, g):
"""Restores the storage objects in the given graphs' Frames if it is a sub-frame of the
"""Restores the storage objects in the given graphs' Frames if it is a sub-frame of the
given parent graph (i.e. when the storage object is None).
given parent graph (i.e. when the storage object is None).
"""
"""
if
not
isinstance
(
item
,
DGL
Hetero
Graph
)
or
not
isinstance
(
g
,
DGL
Hetero
Graph
):
if
not
isinstance
(
item
,
DGLGraph
)
or
not
isinstance
(
g
,
DGLGraph
):
return
item
return
item
for
subframe
,
frame
in
zip
(
for
subframe
,
frame
in
zip
(
...
@@ -774,7 +774,7 @@ class DataLoader(torch.utils.data.DataLoader):
...
@@ -774,7 +774,7 @@ class DataLoader(torch.utils.data.DataLoader):
self
.
device
=
_get_device
(
device
)
self
.
device
=
_get_device
(
device
)
# Sanity check - we only check for DGLGraphs.
# Sanity check - we only check for DGLGraphs.
if
isinstance
(
self
.
graph
,
DGL
Hetero
Graph
):
if
isinstance
(
self
.
graph
,
DGLGraph
):
# Check graph and indices device as well as num_workers
# Check graph and indices device as well as num_workers
if
use_uva
:
if
use_uva
:
if
self
.
graph
.
device
.
type
!=
'cpu'
:
if
self
.
graph
.
device
.
type
!=
'cpu'
:
...
@@ -1098,7 +1098,7 @@ class GraphCollator(object):
...
@@ -1098,7 +1098,7 @@ class GraphCollator(object):
"""
"""
elem
=
items
[
0
]
elem
=
items
[
0
]
elem_type
=
type
(
elem
)
elem_type
=
type
(
elem
)
if
isinstance
(
elem
,
DGL
Hetero
Graph
):
if
isinstance
(
elem
,
DGLGraph
):
batched_graphs
=
batch_graphs
(
items
)
batched_graphs
=
batch_graphs
(
items
)
return
batched_graphs
return
batched_graphs
elif
F
.
is_tensor
(
elem
):
elif
F
.
is_tensor
(
elem
):
...
...
python/dgl/distributed/dist_graph.py
View file @
3132da28
...
@@ -7,7 +7,7 @@ import os
...
@@ -7,7 +7,7 @@ import os
import
gc
import
gc
import
numpy
as
np
import
numpy
as
np
from
..heterograph
import
DGL
Hetero
Graph
from
..heterograph
import
DGLGraph
from
..convert
import
heterograph
as
dgl_heterograph
from
..convert
import
heterograph
as
dgl_heterograph
from
..convert
import
graph
as
dgl_graph
from
..convert
import
graph
as
dgl_graph
from
..transforms
import
compact_graphs
from
..transforms
import
compact_graphs
...
@@ -129,7 +129,7 @@ def _get_graph_from_shared_mem(graph_name):
...
@@ -129,7 +129,7 @@ def _get_graph_from_shared_mem(graph_name):
g
,
ntypes
,
etypes
=
heterograph_index
.
create_heterograph_from_shared_memory
(
graph_name
)
g
,
ntypes
,
etypes
=
heterograph_index
.
create_heterograph_from_shared_memory
(
graph_name
)
if
g
is
None
:
if
g
is
None
:
return
None
return
None
g
=
DGL
Hetero
Graph
(
g
,
ntypes
,
etypes
)
g
=
DGLGraph
(
g
,
ntypes
,
etypes
)
g
.
ndata
[
'inner_node'
]
=
_get_shared_mem_ndata
(
g
,
graph_name
,
'inner_node'
)
g
.
ndata
[
'inner_node'
]
=
_get_shared_mem_ndata
(
g
,
graph_name
,
'inner_node'
)
g
.
ndata
[
NID
]
=
_get_shared_mem_ndata
(
g
,
graph_name
,
NID
)
g
.
ndata
[
NID
]
=
_get_shared_mem_ndata
(
g
,
graph_name
,
NID
)
...
...
python/dgl/distributed/graph_services.py
View file @
3132da28
...
@@ -484,7 +484,7 @@ def _distributed_access(g, nodes, issue_remote_req, local_access):
...
@@ -484,7 +484,7 @@ def _distributed_access(g, nodes, issue_remote_req, local_access):
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
The subgraph that contains the neighborhoods of all input nodes.
The subgraph that contains the neighborhoods of all input nodes.
"""
"""
req_list
=
[]
req_list
=
[]
...
...
python/dgl/distributed/server_state.py
View file @
3132da28
...
@@ -30,7 +30,7 @@ class ServerState:
...
@@ -30,7 +30,7 @@ class ServerState:
----------
----------
kv_store : KVServer
kv_store : KVServer
reference for KVServer
reference for KVServer
graph : DGL
Hetero
Graph
graph : DGLGraph
Graph structure of one partition
Graph structure of one partition
total_num_nodes : int
total_num_nodes : int
Total number of nodes
Total number of nodes
...
...
python/dgl/heterograph.py
View file @
3132da28
...
@@ -20,9 +20,9 @@ from . import backend as F
...
@@ -20,9 +20,9 @@ from . import backend as F
from
.frame
import
Frame
from
.frame
import
Frame
from
.view
import
HeteroNodeView
,
HeteroNodeDataView
,
HeteroEdgeView
,
HeteroEdgeDataView
from
.view
import
HeteroNodeView
,
HeteroNodeDataView
,
HeteroEdgeView
,
HeteroEdgeDataView
__all__
=
[
'DGL
Hetero
Graph'
,
'combine_names'
]
__all__
=
[
'DGLGraph'
,
'combine_names'
]
class
DGL
Hetero
Graph
(
object
):
class
DGLGraph
(
object
):
"""Class for storing graph structure and node/edge feature data.
"""Class for storing graph structure and node/edge feature data.
There are a few ways to create a DGLGraph:
There are a few ways to create a DGLGraph:
...
@@ -66,7 +66,7 @@ class DGLHeteroGraph(object):
...
@@ -66,7 +66,7 @@ class DGLHeteroGraph(object):
Otherwise, ``edge_frames[i]`` stores the edge features
Otherwise, ``edge_frames[i]`` stores the edge features
of edge type i. (default: None)
of edge type i. (default: None)
"""
"""
if
isinstance
(
gidx
,
DGL
Hetero
Graph
):
if
isinstance
(
gidx
,
DGLGraph
):
raise
DGLError
(
'The input is already a DGLGraph. No need to create it again.'
)
raise
DGLError
(
'The input is already a DGLGraph. No need to create it again.'
)
if
not
isinstance
(
gidx
,
heterograph_index
.
HeteroGraphIndex
):
if
not
isinstance
(
gidx
,
heterograph_index
.
HeteroGraphIndex
):
dgl_warning
(
'Recommend creating graphs by `dgl.graph(data)`'
dgl_warning
(
'Recommend creating graphs by `dgl.graph(data)`'
...
@@ -5476,7 +5476,7 @@ class DGLHeteroGraph(object):
...
@@ -5476,7 +5476,7 @@ class DGLHeteroGraph(object):
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
Graph on CPU.
Graph on CPU.
See Also
See Also
...
@@ -5614,7 +5614,7 @@ class DGLHeteroGraph(object):
...
@@ -5614,7 +5614,7 @@ class DGLHeteroGraph(object):
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
The graph object that is a clone of current graph.
The graph object that is a clone of current graph.
"""
"""
# XXX(minjie): Do a shallow copy first to clone some internal metagraph information.
# XXX(minjie): Do a shallow copy first to clone some internal metagraph information.
...
@@ -5919,7 +5919,7 @@ class DGLHeteroGraph(object):
...
@@ -5919,7 +5919,7 @@ class DGLHeteroGraph(object):
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
Graph in the new ID type.
Graph in the new ID type.
"""
"""
if
idtype
is
None
:
if
idtype
is
None
:
...
@@ -5936,7 +5936,7 @@ class DGLHeteroGraph(object):
...
@@ -5936,7 +5936,7 @@ class DGLHeteroGraph(object):
def
shared_memory
(
self
,
name
,
formats
=
(
'coo'
,
'csr'
,
'csc'
)):
def
shared_memory
(
self
,
name
,
formats
=
(
'coo'
,
'csr'
,
'csc'
)):
"""Return a copy of this graph in shared memory, without node data or edge data.
"""Return a copy of this graph in shared memory, without node data or edge data.
It moves the graph index to shared memory and returns a DGL
Heterog
raph object which
It moves the graph index to shared memory and returns a DGL
G
raph object which
has the same graph structure, node types and edge types but does not contain node data
has the same graph structure, node types and edge types but does not contain node data
or edge data.
or edge data.
...
@@ -5949,7 +5949,7 @@ class DGLHeteroGraph(object):
...
@@ -5949,7 +5949,7 @@ class DGLHeteroGraph(object):
Returns
Returns
-------
-------
Hetero
Graph
DGL
Graph
The graph in shared memory
The graph in shared memory
"""
"""
assert
len
(
name
)
>
0
,
"The name of shared memory cannot be empty"
assert
len
(
name
)
>
0
,
"The name of shared memory cannot be empty"
...
@@ -5959,7 +5959,7 @@ class DGLHeteroGraph(object):
...
@@ -5959,7 +5959,7 @@ class DGLHeteroGraph(object):
for
fmt
in
formats
:
for
fmt
in
formats
:
assert
fmt
in
(
"coo"
,
"csr"
,
"csc"
),
'{} is not coo, csr or csc'
.
format
(
fmt
)
assert
fmt
in
(
"coo"
,
"csr"
,
"csc"
),
'{} is not coo, csr or csc'
.
format
(
fmt
)
gidx
=
self
.
_graph
.
shared_memory
(
name
,
self
.
ntypes
,
self
.
etypes
,
formats
)
gidx
=
self
.
_graph
.
shared_memory
(
name
,
self
.
ntypes
,
self
.
etypes
,
formats
)
return
DGL
Hetero
Graph
(
gidx
,
self
.
ntypes
,
self
.
etypes
)
return
DGLGraph
(
gidx
,
self
.
ntypes
,
self
.
etypes
)
def
long
(
self
):
def
long
(
self
):
...
@@ -6374,7 +6374,7 @@ def combine_names(names, ids=None):
...
@@ -6374,7 +6374,7 @@ def combine_names(names, ids=None):
selected
=
sorted
([
names
[
i
]
for
i
in
ids
])
selected
=
sorted
([
names
[
i
]
for
i
in
ids
])
return
'+'
.
join
(
selected
)
return
'+'
.
join
(
selected
)
class
DGLBlock
(
DGL
Hetero
Graph
):
class
DGLBlock
(
DGLGraph
):
"""Subclass that signifies the graph is a block created from
"""Subclass that signifies the graph is a block created from
:func:`dgl.to_block`.
:func:`dgl.to_block`.
"""
"""
...
@@ -6465,7 +6465,7 @@ def _create_compute_graph(graph, u, v, eid, recv_nodes=None):
...
@@ -6465,7 +6465,7 @@ def _create_compute_graph(graph, u, v, eid, recv_nodes=None):
eframe
=
graph
.
_edge_frames
[
0
].
subframe
(
eid
)
eframe
=
graph
.
_edge_frames
[
0
].
subframe
(
eid
)
eframe
[
EID
]
=
eid
eframe
[
EID
]
=
eid
return
DGL
Hetero
Graph
(
hgidx
,
([
srctype
],
[
dsttype
]),
[
etype
],
return
DGLGraph
(
hgidx
,
([
srctype
],
[
dsttype
]),
[
etype
],
node_frames
=
[
srcframe
,
dstframe
],
node_frames
=
[
srcframe
,
dstframe
],
edge_frames
=
[
eframe
]),
unique_src
,
unique_dst
,
eid
edge_frames
=
[
eframe
]),
unique_src
,
unique_dst
,
eid
...
...
python/dgl/nn/mxnet/hetero.py
View file @
3132da28
...
@@ -93,7 +93,7 @@ class HeteroGraphConv(nn.Block):
...
@@ -93,7 +93,7 @@ class HeteroGraphConv(nn.Block):
----------
----------
mods : dict[str, nn.Module]
mods : dict[str, nn.Module]
Modules associated with every edge types. The forward function of each
Modules associated with every edge types. The forward function of each
module must have a `DGL
Hetero
Graph` object as the first argument, and
module must have a `DGLGraph` object as the first argument, and
its second argument is either a tensor object representing the node
its second argument is either a tensor object representing the node
features or a pair of tensor object representing the source and destination
features or a pair of tensor object representing the source and destination
node features.
node features.
...
@@ -146,7 +146,7 @@ class HeteroGraphConv(nn.Block):
...
@@ -146,7 +146,7 @@ class HeteroGraphConv(nn.Block):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
Graph data.
Graph data.
inputs : dict[str, Tensor] or pair of dict[str, Tensor]
inputs : dict[str, Tensor] or pair of dict[str, Tensor]
Input node features.
Input node features.
...
...
python/dgl/nn/pytorch/hetero.py
View file @
3132da28
...
@@ -97,7 +97,7 @@ class HeteroGraphConv(nn.Module):
...
@@ -97,7 +97,7 @@ class HeteroGraphConv(nn.Module):
----------
----------
mods : dict[str, nn.Module]
mods : dict[str, nn.Module]
Modules associated with every edge types. The forward function of each
Modules associated with every edge types. The forward function of each
module must have a `DGL
Hetero
Graph` object as the first argument, and
module must have a `DGLGraph` object as the first argument, and
its second argument is either a tensor object representing the node
its second argument is either a tensor object representing the node
features or a pair of tensor object representing the source and destination
features or a pair of tensor object representing the source and destination
node features.
node features.
...
@@ -163,7 +163,7 @@ class HeteroGraphConv(nn.Module):
...
@@ -163,7 +163,7 @@ class HeteroGraphConv(nn.Module):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
Graph data.
Graph data.
inputs : dict[str, Tensor] or pair of dict[str, Tensor]
inputs : dict[str, Tensor] or pair of dict[str, Tensor]
Input node features.
Input node features.
...
...
python/dgl/nn/tensorflow/hetero.py
View file @
3132da28
...
@@ -100,7 +100,7 @@ class HeteroGraphConv(layers.Layer):
...
@@ -100,7 +100,7 @@ class HeteroGraphConv(layers.Layer):
----------
----------
mods : dict[str, nn.Module]
mods : dict[str, nn.Module]
Modules associated with every edge types. The forward function of each
Modules associated with every edge types. The forward function of each
module must have a `DGL
Hetero
Graph` object as the first argument, and
module must have a `DGLGraph` object as the first argument, and
its second argument is either a tensor object representing the node
its second argument is either a tensor object representing the node
features or a pair of tensor object representing the source and destination
features or a pair of tensor object representing the source and destination
node features.
node features.
...
@@ -150,7 +150,7 @@ class HeteroGraphConv(layers.Layer):
...
@@ -150,7 +150,7 @@ class HeteroGraphConv(layers.Layer):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
Graph data.
Graph data.
inputs : dict[str, Tensor] or pair of dict[str, Tensor]
inputs : dict[str, Tensor] or pair of dict[str, Tensor]
Input node features.
Input node features.
...
...
python/dgl/ops/sddmm.py
View file @
3132da28
...
@@ -106,7 +106,7 @@ def _gen_sddmm_func(lhs_target, rhs_target, binary_op):
...
@@ -106,7 +106,7 @@ def _gen_sddmm_func(lhs_target, rhs_target, binary_op):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
The input graph
The input graph
x : tensor
x : tensor
The {lhs} features.
The {lhs} features.
...
@@ -157,7 +157,7 @@ def copy_u(g, x):
...
@@ -157,7 +157,7 @@ def copy_u(g, x):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
The input graph.
The input graph.
x : tensor
x : tensor
The source node features.
The source node features.
...
@@ -179,7 +179,7 @@ def copy_v(g, x):
...
@@ -179,7 +179,7 @@ def copy_v(g, x):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
The input graph.
The input graph.
x : tensor
x : tensor
The destination node features.
The destination node features.
...
...
python/dgl/ops/spmm.py
View file @
3132da28
...
@@ -143,7 +143,7 @@ def _gen_spmm_func(binary_op, reduce_op):
...
@@ -143,7 +143,7 @@ def _gen_spmm_func(binary_op, reduce_op):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
The input graph
The input graph
x : tensor
x : tensor
The source node features.
The source node features.
...
@@ -191,7 +191,7 @@ def _gen_copy_reduce_func(binary_op, reduce_op):
...
@@ -191,7 +191,7 @@ def _gen_copy_reduce_func(binary_op, reduce_op):
Parameters
Parameters
----------
----------
g : DGL
Hetero
Graph
g : DGLGraph
The input graph
The input graph
x : tensor
x : tensor
The {} features.
The {} features.
...
...
python/dgl/partition.py
View file @
3132da28
...
@@ -9,7 +9,7 @@ from . import backend as F
...
@@ -9,7 +9,7 @@ from . import backend as F
from
.
import
utils
from
.
import
utils
from
._ffi.function
import
_init_api
from
._ffi.function
import
_init_api
from
.base
import
EID
,
ETYPE
,
NID
,
NTYPE
from
.base
import
EID
,
ETYPE
,
NID
,
NTYPE
from
.heterograph
import
DGL
Hetero
Graph
from
.heterograph
import
DGLGraph
from
.ndarray
import
NDArray
from
.ndarray
import
NDArray
from
.subgraph
import
edge_subgraph
from
.subgraph
import
edge_subgraph
...
@@ -49,7 +49,7 @@ def reorder_nodes(g, new_node_ids):
...
@@ -49,7 +49,7 @@ def reorder_nodes(g, new_node_ids):
new_gidx
=
_CAPI_DGLReorderGraph_Hetero
(
new_gidx
=
_CAPI_DGLReorderGraph_Hetero
(
g
.
_graph
,
new_node_ids
.
todgltensor
()
g
.
_graph
,
new_node_ids
.
todgltensor
()
)
)
new_g
=
DGL
Hetero
Graph
(
gidx
=
new_gidx
,
ntypes
=
[
"_N"
],
etypes
=
[
"_E"
])
new_g
=
DGLGraph
(
gidx
=
new_gidx
,
ntypes
=
[
"_N"
],
etypes
=
[
"_E"
])
new_g
.
ndata
[
"orig_id"
]
=
idx
new_g
.
ndata
[
"orig_id"
]
=
idx
return
new_g
return
new_g
...
@@ -211,7 +211,7 @@ def partition_graph_with_halo(g, node_part, extra_cached_hops, reshuffle=False):
...
@@ -211,7 +211,7 @@ def partition_graph_with_halo(g, node_part, extra_cached_hops, reshuffle=False):
# This creaets a subgraph from subgraphs returned from the CAPI above.
# This creaets a subgraph from subgraphs returned from the CAPI above.
def
create_subgraph
(
subg
,
induced_nodes
,
induced_edges
,
inner_node
):
def
create_subgraph
(
subg
,
induced_nodes
,
induced_edges
,
inner_node
):
subg1
=
DGL
Hetero
Graph
(
gidx
=
subg
.
graph
,
ntypes
=
[
"_N"
],
etypes
=
[
"_E"
])
subg1
=
DGLGraph
(
gidx
=
subg
.
graph
,
ntypes
=
[
"_N"
],
etypes
=
[
"_E"
])
# If IDs are shuffled, we should shuffled edges. This will help us collect edge data
# If IDs are shuffled, we should shuffled edges. This will help us collect edge data
# from the distributed graph after training.
# from the distributed graph after training.
if
reshuffle
:
if
reshuffle
:
...
@@ -325,7 +325,7 @@ def metis_partition_assignment(
...
@@ -325,7 +325,7 @@ def metis_partition_assignment(
# The METIS runs on the symmetric graph to generate the node assignment to partitions.
# The METIS runs on the symmetric graph to generate the node assignment to partitions.
start
=
time
.
time
()
start
=
time
.
time
()
sym_gidx
=
_CAPI_DGLMakeSymmetric_Hetero
(
g
.
_graph
)
sym_gidx
=
_CAPI_DGLMakeSymmetric_Hetero
(
g
.
_graph
)
sym_g
=
DGL
Hetero
Graph
(
gidx
=
sym_gidx
)
sym_g
=
DGLGraph
(
gidx
=
sym_gidx
)
print
(
print
(
"Convert a graph into a bidirected graph: {:.3f} seconds, peak memory: {:.3f} GB"
.
format
(
"Convert a graph into a bidirected graph: {:.3f} seconds, peak memory: {:.3f} GB"
.
format
(
time
.
time
()
-
start
,
get_peak_mem
()
time
.
time
()
-
start
,
get_peak_mem
()
...
...
python/dgl/propagate.py
View file @
3132da28
...
@@ -3,7 +3,7 @@ from __future__ import absolute_import
...
@@ -3,7 +3,7 @@ from __future__ import absolute_import
from
.
import
backend
as
F
from
.
import
backend
as
F
from
.
import
traversal
as
trv
from
.
import
traversal
as
trv
from
.heterograph
import
DGL
Hetero
Graph
from
.heterograph
import
DGLGraph
__all__
=
[
__all__
=
[
"prop_nodes"
,
"prop_nodes"
,
...
@@ -84,7 +84,7 @@ def prop_nodes_bfs(
...
@@ -84,7 +84,7 @@ def prop_nodes_bfs(
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
source : list, tensor of nodes
source : list, tensor of nodes
Source nodes.
Source nodes.
...
@@ -102,8 +102,8 @@ def prop_nodes_bfs(
...
@@ -102,8 +102,8 @@ def prop_nodes_bfs(
dgl.traversal.bfs_nodes_generator
dgl.traversal.bfs_nodes_generator
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"prop_nodes_bfs only support homogeneous graph"
),
"prop_nodes_bfs only support homogeneous graph"
...
@@ -122,7 +122,7 @@ def prop_nodes_topo(
...
@@ -122,7 +122,7 @@ def prop_nodes_topo(
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
message_func : callable
message_func : callable
The message function.
The message function.
...
@@ -138,8 +138,8 @@ def prop_nodes_topo(
...
@@ -138,8 +138,8 @@ def prop_nodes_topo(
dgl.traversal.topological_nodes_generator
dgl.traversal.topological_nodes_generator
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"prop_nodes_topo only support homogeneous graph"
),
"prop_nodes_topo only support homogeneous graph"
...
@@ -165,7 +165,7 @@ def prop_edges_dfs(
...
@@ -165,7 +165,7 @@ def prop_edges_dfs(
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
source : list, tensor of nodes
source : list, tensor of nodes
Source nodes.
Source nodes.
...
@@ -187,8 +187,8 @@ def prop_edges_dfs(
...
@@ -187,8 +187,8 @@ def prop_edges_dfs(
dgl.traversal.dfs_labeled_edges_generator
dgl.traversal.dfs_labeled_edges_generator
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"prop_edges_dfs only support homogeneous graph"
),
"prop_edges_dfs only support homogeneous graph"
...
...
python/dgl/sampling/negative.py
View file @
3132da28
...
@@ -5,7 +5,7 @@ from numpy.polynomial import polynomial
...
@@ -5,7 +5,7 @@ from numpy.polynomial import polynomial
from
..
import
backend
as
F
from
..
import
backend
as
F
from
..
import
utils
from
..
import
utils
from
.._ffi.function
import
_init_api
from
.._ffi.function
import
_init_api
from
..heterograph
import
DGL
Hetero
Graph
from
..heterograph
import
DGLGraph
__all__
=
[
"global_uniform_negative_sampling"
]
__all__
=
[
"global_uniform_negative_sampling"
]
...
@@ -120,7 +120,7 @@ def global_uniform_negative_sampling(
...
@@ -120,7 +120,7 @@ def global_uniform_negative_sampling(
return
F
.
from_dgl_nd
(
src
),
F
.
from_dgl_nd
(
dst
)
return
F
.
from_dgl_nd
(
src
),
F
.
from_dgl_nd
(
dst
)
DGL
Hetero
Graph
.
global_uniform_negative_sampling
=
utils
.
alias_func
(
DGLGraph
.
global_uniform_negative_sampling
=
utils
.
alias_func
(
global_uniform_negative_sampling
global_uniform_negative_sampling
)
)
...
...
python/dgl/sampling/neighbor.py
View file @
3132da28
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
from
.._ffi.function
import
_init_api
from
.._ffi.function
import
_init_api
from
..
import
backend
as
F
from
..
import
backend
as
F
from
..base
import
DGLError
,
EID
from
..base
import
DGLError
,
EID
from
..heterograph
import
DGL
Hetero
Graph
from
..heterograph
import
DGLGraph
from
..
import
ndarray
as
nd
from
..
import
ndarray
as
nd
from
..
import
utils
from
..
import
utils
from
.utils
import
EidExcluder
from
.utils
import
EidExcluder
...
@@ -157,7 +157,7 @@ def sample_etype_neighbors(
...
@@ -157,7 +157,7 @@ def sample_etype_neighbors(
g
.
_graph
,
nodes
,
etype_offset
,
fanout
,
edge_dir
,
prob_array
,
g
.
_graph
,
nodes
,
etype_offset
,
fanout
,
edge_dir
,
prob_array
,
replace
,
etype_sorted
)
replace
,
etype_sorted
)
induced_edges
=
subgidx
.
induced_edges
induced_edges
=
subgidx
.
induced_edges
ret
=
DGL
Hetero
Graph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
ret
=
DGLGraph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
# handle features
# handle features
# (TODO) (BarclayII) DGL distributed fails with bus error, freezes, or other
# (TODO) (BarclayII) DGL distributed fails with bus error, freezes, or other
...
@@ -178,7 +178,7 @@ def sample_etype_neighbors(
...
@@ -178,7 +178,7 @@ def sample_etype_neighbors(
return
ret
if
output_device
is
None
else
ret
.
to
(
output_device
)
return
ret
if
output_device
is
None
else
ret
.
to
(
output_device
)
DGL
Hetero
Graph
.
sample_etype_neighbors
=
utils
.
alias_func
(
sample_etype_neighbors
)
DGLGraph
.
sample_etype_neighbors
=
utils
.
alias_func
(
sample_etype_neighbors
)
def
sample_neighbors
(
g
,
nodes
,
fanout
,
edge_dir
=
'in'
,
prob
=
None
,
def
sample_neighbors
(
g
,
nodes
,
fanout
,
edge_dir
=
'in'
,
prob
=
None
,
replace
=
False
,
copy_ndata
=
True
,
copy_edata
=
True
,
replace
=
False
,
copy_ndata
=
True
,
copy_edata
=
True
,
...
@@ -388,7 +388,7 @@ def _sample_neighbors(g, nodes, fanout, edge_dir='in', prob=None,
...
@@ -388,7 +388,7 @@ def _sample_neighbors(g, nodes, fanout, edge_dir='in', prob=None,
g
.
_graph
,
nodes_all_types
,
fanout_array
,
edge_dir
,
prob_arrays
,
g
.
_graph
,
nodes_all_types
,
fanout_array
,
edge_dir
,
prob_arrays
,
excluded_edges_all_t
,
replace
)
excluded_edges_all_t
,
replace
)
induced_edges
=
subgidx
.
induced_edges
induced_edges
=
subgidx
.
induced_edges
ret
=
DGL
Hetero
Graph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
ret
=
DGLGraph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
# handle features
# handle features
# (TODO) (BarclayII) DGL distributed fails with bus error, freezes, or other
# (TODO) (BarclayII) DGL distributed fails with bus error, freezes, or other
...
@@ -409,7 +409,7 @@ def _sample_neighbors(g, nodes, fanout, edge_dir='in', prob=None,
...
@@ -409,7 +409,7 @@ def _sample_neighbors(g, nodes, fanout, edge_dir='in', prob=None,
return
ret
return
ret
DGL
Hetero
Graph
.
sample_neighbors
=
utils
.
alias_func
(
sample_neighbors
)
DGLGraph
.
sample_neighbors
=
utils
.
alias_func
(
sample_neighbors
)
def
sample_neighbors_biased
(
g
,
nodes
,
fanout
,
bias
,
edge_dir
=
'in'
,
def
sample_neighbors_biased
(
g
,
nodes
,
fanout
,
bias
,
edge_dir
=
'in'
,
tag_offset_name
=
'_TAG_OFFSET'
,
replace
=
False
,
tag_offset_name
=
'_TAG_OFFSET'
,
replace
=
False
,
...
@@ -568,7 +568,7 @@ def sample_neighbors_biased(g, nodes, fanout, bias, edge_dir='in',
...
@@ -568,7 +568,7 @@ def sample_neighbors_biased(g, nodes, fanout, bias, edge_dir='in',
subgidx
=
_CAPI_DGLSampleNeighborsBiased
(
g
.
_graph
,
nodes_array
,
fanout
,
bias_array
,
subgidx
=
_CAPI_DGLSampleNeighborsBiased
(
g
.
_graph
,
nodes_array
,
fanout
,
bias_array
,
tag_offset_array
,
edge_dir
,
replace
)
tag_offset_array
,
edge_dir
,
replace
)
induced_edges
=
subgidx
.
induced_edges
induced_edges
=
subgidx
.
induced_edges
ret
=
DGL
Hetero
Graph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
ret
=
DGLGraph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
if
copy_ndata
:
if
copy_ndata
:
node_frames
=
utils
.
extract_node_subframes
(
g
,
device
)
node_frames
=
utils
.
extract_node_subframes
(
g
,
device
)
...
@@ -581,7 +581,7 @@ def sample_neighbors_biased(g, nodes, fanout, bias, edge_dir='in',
...
@@ -581,7 +581,7 @@ def sample_neighbors_biased(g, nodes, fanout, bias, edge_dir='in',
ret
.
edata
[
EID
]
=
induced_edges
[
0
]
ret
.
edata
[
EID
]
=
induced_edges
[
0
]
return
ret
if
output_device
is
None
else
ret
.
to
(
output_device
)
return
ret
if
output_device
is
None
else
ret
.
to
(
output_device
)
DGL
Hetero
Graph
.
sample_neighbors_biased
=
utils
.
alias_func
(
sample_neighbors_biased
)
DGLGraph
.
sample_neighbors_biased
=
utils
.
alias_func
(
sample_neighbors_biased
)
def
select_topk
(
g
,
k
,
weight
,
nodes
=
None
,
edge_dir
=
'in'
,
ascending
=
False
,
def
select_topk
(
g
,
k
,
weight
,
nodes
=
None
,
edge_dir
=
'in'
,
ascending
=
False
,
copy_ndata
=
True
,
copy_edata
=
True
,
output_device
=
None
):
copy_ndata
=
True
,
copy_edata
=
True
,
output_device
=
None
):
...
@@ -705,7 +705,7 @@ def select_topk(g, k, weight, nodes=None, edge_dir='in', ascending=False,
...
@@ -705,7 +705,7 @@ def select_topk(g, k, weight, nodes=None, edge_dir='in', ascending=False,
subgidx
=
_CAPI_DGLSampleNeighborsTopk
(
subgidx
=
_CAPI_DGLSampleNeighborsTopk
(
g
.
_graph
,
nodes_all_types
,
k_array
,
edge_dir
,
weight_arrays
,
bool
(
ascending
))
g
.
_graph
,
nodes_all_types
,
k_array
,
edge_dir
,
weight_arrays
,
bool
(
ascending
))
induced_edges
=
subgidx
.
induced_edges
induced_edges
=
subgidx
.
induced_edges
ret
=
DGL
Hetero
Graph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
ret
=
DGLGraph
(
subgidx
.
graph
,
g
.
ntypes
,
g
.
etypes
)
# handle features
# handle features
if
copy_ndata
:
if
copy_ndata
:
...
@@ -717,6 +717,6 @@ def select_topk(g, k, weight, nodes=None, edge_dir='in', ascending=False,
...
@@ -717,6 +717,6 @@ def select_topk(g, k, weight, nodes=None, edge_dir='in', ascending=False,
utils
.
set_new_frames
(
ret
,
edge_frames
=
edge_frames
)
utils
.
set_new_frames
(
ret
,
edge_frames
=
edge_frames
)
return
ret
if
output_device
is
None
else
ret
.
to
(
output_device
)
return
ret
if
output_device
is
None
else
ret
.
to
(
output_device
)
DGL
Hetero
Graph
.
select_topk
=
utils
.
alias_func
(
select_topk
)
DGLGraph
.
select_topk
=
utils
.
alias_func
(
select_topk
)
_init_api
(
'dgl.sampling.neighbor'
,
__name__
)
_init_api
(
'dgl.sampling.neighbor'
,
__name__
)
python/dgl/subgraph.py
View file @
3132da28
...
@@ -9,7 +9,7 @@ from . import backend as F
...
@@ -9,7 +9,7 @@ from . import backend as F
from
.
import
graph_index
,
heterograph_index
,
utils
from
.
import
graph_index
,
heterograph_index
,
utils
from
._ffi.function
import
_init_api
from
._ffi.function
import
_init_api
from
.base
import
DGLError
,
dgl_warning
from
.base
import
DGLError
,
dgl_warning
from
.heterograph
import
DGL
Hetero
Graph
from
.heterograph
import
DGLGraph
from
.utils
import
context_of
,
recursive_apply
from
.utils
import
context_of
,
recursive_apply
__all__
=
[
__all__
=
[
...
@@ -173,7 +173,7 @@ def node_subgraph(
...
@@ -173,7 +173,7 @@ def node_subgraph(
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
DGL
Hetero
Graph
.
subgraph
=
utils
.
alias_func
(
node_subgraph
)
DGLGraph
.
subgraph
=
utils
.
alias_func
(
node_subgraph
)
def
edge_subgraph
(
def
edge_subgraph
(
...
@@ -346,7 +346,7 @@ def edge_subgraph(
...
@@ -346,7 +346,7 @@ def edge_subgraph(
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
DGL
Hetero
Graph
.
edge_subgraph
=
utils
.
alias_func
(
edge_subgraph
)
DGLGraph
.
edge_subgraph
=
utils
.
alias_func
(
edge_subgraph
)
def
in_subgraph
(
def
in_subgraph
(
...
@@ -484,7 +484,7 @@ def in_subgraph(
...
@@ -484,7 +484,7 @@ def in_subgraph(
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
DGL
Hetero
Graph
.
in_subgraph
=
utils
.
alias_func
(
in_subgraph
)
DGLGraph
.
in_subgraph
=
utils
.
alias_func
(
in_subgraph
)
def
out_subgraph
(
def
out_subgraph
(
...
@@ -622,7 +622,7 @@ def out_subgraph(
...
@@ -622,7 +622,7 @@ def out_subgraph(
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
return
subg
if
output_device
is
None
else
subg
.
to
(
output_device
)
DGL
Hetero
Graph
.
out_subgraph
=
utils
.
alias_func
(
out_subgraph
)
DGLGraph
.
out_subgraph
=
utils
.
alias_func
(
out_subgraph
)
def
khop_in_subgraph
(
def
khop_in_subgraph
(
...
@@ -807,7 +807,7 @@ def khop_in_subgraph(
...
@@ -807,7 +807,7 @@ def khop_in_subgraph(
return
sub_g
return
sub_g
DGL
Hetero
Graph
.
khop_in_subgraph
=
utils
.
alias_func
(
khop_in_subgraph
)
DGLGraph
.
khop_in_subgraph
=
utils
.
alias_func
(
khop_in_subgraph
)
def
khop_out_subgraph
(
def
khop_out_subgraph
(
...
@@ -992,7 +992,7 @@ def khop_out_subgraph(
...
@@ -992,7 +992,7 @@ def khop_out_subgraph(
return
sub_g
return
sub_g
DGL
Hetero
Graph
.
khop_out_subgraph
=
utils
.
alias_func
(
khop_out_subgraph
)
DGLGraph
.
khop_out_subgraph
=
utils
.
alias_func
(
khop_out_subgraph
)
def
node_type_subgraph
(
graph
,
ntypes
,
output_device
=
None
):
def
node_type_subgraph
(
graph
,
ntypes
,
output_device
=
None
):
...
@@ -1073,7 +1073,7 @@ def node_type_subgraph(graph, ntypes, output_device=None):
...
@@ -1073,7 +1073,7 @@ def node_type_subgraph(graph, ntypes, output_device=None):
return
edge_type_subgraph
(
graph
,
etypes
,
output_device
=
output_device
)
return
edge_type_subgraph
(
graph
,
etypes
,
output_device
=
output_device
)
DGL
Hetero
Graph
.
node_type_subgraph
=
utils
.
alias_func
(
node_type_subgraph
)
DGLGraph
.
node_type_subgraph
=
utils
.
alias_func
(
node_type_subgraph
)
def
edge_type_subgraph
(
graph
,
etypes
,
output_device
=
None
):
def
edge_type_subgraph
(
graph
,
etypes
,
output_device
=
None
):
...
@@ -1178,13 +1178,13 @@ def edge_type_subgraph(graph, etypes, output_device=None):
...
@@ -1178,13 +1178,13 @@ def edge_type_subgraph(graph, etypes, output_device=None):
rel_graphs
,
rel_graphs
,
utils
.
toindex
(
num_nodes_per_induced_type
,
"int64"
),
utils
.
toindex
(
num_nodes_per_induced_type
,
"int64"
),
)
)
hg
=
DGL
Hetero
Graph
(
hg
=
DGLGraph
(
hgidx
,
induced_ntypes
,
induced_etypes
,
node_frames
,
edge_frames
hgidx
,
induced_ntypes
,
induced_etypes
,
node_frames
,
edge_frames
)
)
return
hg
if
output_device
is
None
else
hg
.
to
(
output_device
)
return
hg
if
output_device
is
None
else
hg
.
to
(
output_device
)
DGL
Hetero
Graph
.
edge_type_subgraph
=
utils
.
alias_func
(
edge_type_subgraph
)
DGLGraph
.
edge_type_subgraph
=
utils
.
alias_func
(
edge_type_subgraph
)
#################### Internal functions ####################
#################### Internal functions ####################
...
@@ -1233,7 +1233,7 @@ def _create_hetero_subgraph(
...
@@ -1233,7 +1233,7 @@ def _create_hetero_subgraph(
edge_frames
=
utils
.
extract_edge_subframes
(
edge_frames
=
utils
.
extract_edge_subframes
(
parent
,
induced_edges_or_device
,
store_ids
parent
,
induced_edges_or_device
,
store_ids
)
)
hsg
=
DGL
Hetero
Graph
(
sgi
.
graph
,
parent
.
ntypes
,
parent
.
etypes
)
hsg
=
DGLGraph
(
sgi
.
graph
,
parent
.
ntypes
,
parent
.
etypes
)
utils
.
set_new_frames
(
hsg
,
node_frames
=
node_frames
,
edge_frames
=
edge_frames
)
utils
.
set_new_frames
(
hsg
,
node_frames
=
node_frames
,
edge_frames
=
edge_frames
)
return
hsg
return
hsg
...
...
python/dgl/transforms/functional.py
View file @
3132da28
...
@@ -30,7 +30,7 @@ except ImportError:
...
@@ -30,7 +30,7 @@ except ImportError:
from
.._ffi.function
import
_init_api
from
.._ffi.function
import
_init_api
from
..base
import
dgl_warning
,
DGLError
,
NID
,
EID
from
..base
import
dgl_warning
,
DGLError
,
NID
,
EID
from
..
import
convert
from
..
import
convert
from
..heterograph
import
DGL
Hetero
Graph
,
DGLBlock
from
..heterograph
import
DGLGraph
,
DGLBlock
from
..heterograph_index
import
create_metagraph_index
,
create_heterograph_from_relations
from
..heterograph_index
import
create_metagraph_index
,
create_heterograph_from_relations
from
..frame
import
Frame
from
..frame
import
Frame
from
..
import
ndarray
as
nd
from
..
import
ndarray
as
nd
...
@@ -68,13 +68,11 @@ __all__ = [
...
@@ -68,13 +68,11 @@ __all__ = [
'to_block'
,
'to_block'
,
'to_simple'
,
'to_simple'
,
'to_simple_graph'
,
'to_simple_graph'
,
'as_immutable_graph'
,
'sort_csr_by_tag'
,
'sort_csr_by_tag'
,
'sort_csc_by_tag'
,
'sort_csc_by_tag'
,
'metis_partition_assignment'
,
'metis_partition_assignment'
,
'partition_graph_with_halo'
,
'partition_graph_with_halo'
,
'metis_partition'
,
'metis_partition'
,
'as_heterograph'
,
'adj_product_graph'
,
'adj_product_graph'
,
'adj_sum_graph'
,
'adj_sum_graph'
,
'reorder_graph'
,
'reorder_graph'
,
...
@@ -1034,7 +1032,7 @@ def line_graph(g, backtracking=True, shared=False):
...
@@ -1034,7 +1032,7 @@ def line_graph(g, backtracking=True, shared=False):
'only homogeneous graph is supported'
'only homogeneous graph is supported'
dev
=
g
.
device
dev
=
g
.
device
lg
=
DGL
Hetero
Graph
(
_CAPI_DGLHeteroLineGraph
(
g
.
_graph
.
copy_to
(
nd
.
cpu
()),
backtracking
))
lg
=
DGLGraph
(
_CAPI_DGLHeteroLineGraph
(
g
.
_graph
.
copy_to
(
nd
.
cpu
()),
backtracking
))
lg
=
lg
.
to
(
dev
)
lg
=
lg
.
to
(
dev
)
if
shared
:
if
shared
:
new_frames
=
utils
.
extract_edge_subframes
(
g
,
None
)
new_frames
=
utils
.
extract_edge_subframes
(
g
,
None
)
...
@@ -1042,7 +1040,7 @@ def line_graph(g, backtracking=True, shared=False):
...
@@ -1042,7 +1040,7 @@ def line_graph(g, backtracking=True, shared=False):
return
lg
return
lg
DGL
Hetero
Graph
.
line_graph
=
utils
.
alias_func
(
line_graph
)
DGLGraph
.
line_graph
=
utils
.
alias_func
(
line_graph
)
def
khop_adj
(
g
,
k
):
def
khop_adj
(
g
,
k
):
"""Return the matrix of :math:`A^k` where :math:`A` is the adjacency matrix of the graph
"""Return the matrix of :math:`A^k` where :math:`A` is the adjacency matrix of the graph
...
@@ -1276,7 +1274,7 @@ def reverse(g, copy_ndata=True, copy_edata=False, *, share_ndata=None, share_eda
...
@@ -1276,7 +1274,7 @@ def reverse(g, copy_ndata=True, copy_edata=False, *, share_ndata=None, share_eda
# currently reversing a block results in undefined behavior
# currently reversing a block results in undefined behavior
raise
DGLError
(
'Reversing a block graph is not supported.'
)
raise
DGLError
(
'Reversing a block graph is not supported.'
)
gidx
=
g
.
_graph
.
reverse
()
gidx
=
g
.
_graph
.
reverse
()
new_g
=
DGL
Hetero
Graph
(
gidx
,
g
.
ntypes
,
g
.
etypes
)
new_g
=
DGLGraph
(
gidx
,
g
.
ntypes
,
g
.
etypes
)
# handle ndata
# handle ndata
if
copy_ndata
:
if
copy_ndata
:
...
@@ -1293,7 +1291,7 @@ def reverse(g, copy_ndata=True, copy_edata=False, *, share_ndata=None, share_eda
...
@@ -1293,7 +1291,7 @@ def reverse(g, copy_ndata=True, copy_edata=False, *, share_ndata=None, share_eda
return
new_g
return
new_g
DGL
Hetero
Graph
.
reverse
=
utils
.
alias_func
(
reverse
)
DGLGraph
.
reverse
=
utils
.
alias_func
(
reverse
)
def
to_simple_graph
(
g
):
def
to_simple_graph
(
g
):
"""Convert the graph to a simple graph with no multi-edge.
"""Convert the graph to a simple graph with no multi-edge.
...
@@ -1959,7 +1957,7 @@ def add_self_loop(g, edge_feat_names=None, fill_data=1., etype=None):
...
@@ -1959,7 +1957,7 @@ def add_self_loop(g, edge_feat_names=None, fill_data=1., etype=None):
new_g
=
add_edges
(
g
,
nodes
,
nodes
,
etype
=
etype
)
new_g
=
add_edges
(
g
,
nodes
,
nodes
,
etype
=
etype
)
return
new_g
return
new_g
DGL
Hetero
Graph
.
add_self_loop
=
utils
.
alias_func
(
add_self_loop
)
DGLGraph
.
add_self_loop
=
utils
.
alias_func
(
add_self_loop
)
def
remove_self_loop
(
g
,
etype
=
None
):
def
remove_self_loop
(
g
,
etype
=
None
):
r
""" Remove self-loops for each node in the graph and return a new graph.
r
""" Remove self-loops for each node in the graph and return a new graph.
...
@@ -2034,7 +2032,7 @@ def remove_self_loop(g, etype=None):
...
@@ -2034,7 +2032,7 @@ def remove_self_loop(g, etype=None):
new_g
=
remove_edges
(
g
,
self_loop_eids
,
etype
=
etype
)
new_g
=
remove_edges
(
g
,
self_loop_eids
,
etype
=
etype
)
return
new_g
return
new_g
DGL
Hetero
Graph
.
remove_self_loop
=
utils
.
alias_func
(
remove_self_loop
)
DGLGraph
.
remove_self_loop
=
utils
.
alias_func
(
remove_self_loop
)
def
compact_graphs
(
graphs
,
always_preserve
=
None
,
copy_ndata
=
True
,
copy_edata
=
True
):
def
compact_graphs
(
graphs
,
always_preserve
=
None
,
copy_ndata
=
True
,
copy_edata
=
True
):
"""Given a list of graphs with the same set of nodes, find and eliminate the common
"""Given a list of graphs with the same set of nodes, find and eliminate the common
...
@@ -2192,7 +2190,7 @@ def compact_graphs(graphs, always_preserve=None, copy_ndata=True, copy_edata=Tru
...
@@ -2192,7 +2190,7 @@ def compact_graphs(graphs, always_preserve=None, copy_ndata=True, copy_edata=Tru
induced_nodes
=
[
F
.
from_dgl_nd
(
nodes
)
for
nodes
in
induced_nodes
]
induced_nodes
=
[
F
.
from_dgl_nd
(
nodes
)
for
nodes
in
induced_nodes
]
new_graphs
=
[
new_graphs
=
[
DGL
Hetero
Graph
(
new_graph_index
,
graph
.
ntypes
,
graph
.
etypes
)
DGLGraph
(
new_graph_index
,
graph
.
ntypes
,
graph
.
etypes
)
for
new_graph_index
,
graph
in
zip
(
new_graph_indexes
,
graphs
)]
for
new_graph_index
,
graph
in
zip
(
new_graph_indexes
,
graphs
)]
if
copy_ndata
:
if
copy_ndata
:
...
@@ -2616,7 +2614,7 @@ def to_simple(g,
...
@@ -2616,7 +2614,7 @@ def to_simple(g,
if
g
.
is_block
:
if
g
.
is_block
:
raise
DGLError
(
'Cannot convert a block graph to a simple graph.'
)
raise
DGLError
(
'Cannot convert a block graph to a simple graph.'
)
simple_graph_index
,
counts
,
edge_maps
=
_CAPI_DGLToSimpleHetero
(
g
.
_graph
)
simple_graph_index
,
counts
,
edge_maps
=
_CAPI_DGLToSimpleHetero
(
g
.
_graph
)
simple_graph
=
DGL
Hetero
Graph
(
simple_graph_index
,
g
.
ntypes
,
g
.
etypes
)
simple_graph
=
DGLGraph
(
simple_graph_index
,
g
.
ntypes
,
g
.
etypes
)
counts
=
[
F
.
from_dgl_nd
(
count
)
for
count
in
counts
]
counts
=
[
F
.
from_dgl_nd
(
count
)
for
count
in
counts
]
edge_maps
=
[
F
.
from_dgl_nd
(
edge_map
)
for
edge_map
in
edge_maps
]
edge_maps
=
[
F
.
from_dgl_nd
(
edge_map
)
for
edge_map
in
edge_maps
]
...
@@ -2644,7 +2642,7 @@ def to_simple(g,
...
@@ -2644,7 +2642,7 @@ def to_simple(g,
return
simple_graph
return
simple_graph
DGL
Hetero
Graph
.
to_simple
=
utils
.
alias_func
(
to_simple
)
DGLGraph
.
to_simple
=
utils
.
alias_func
(
to_simple
)
def
_unitgraph_less_than_int32
(
g
):
def
_unitgraph_less_than_int32
(
g
):
"""Check if a graph with only one edge type has more than 2 ** 31 - 1
"""Check if a graph with only one edge type has more than 2 ** 31 - 1
...
@@ -2789,7 +2787,7 @@ def adj_product_graph(A, B, weight_name, etype='_E'):
...
@@ -2789,7 +2787,7 @@ def adj_product_graph(A, B, weight_name, etype='_E'):
C_gidx
=
create_heterograph_from_relations
(
C_gidx
=
create_heterograph_from_relations
(
C_metagraph
,
[
C_gidx
],
utils
.
toindex
(
num_nodes_per_type
))
C_metagraph
,
[
C_gidx
],
utils
.
toindex
(
num_nodes_per_type
))
C
=
DGL
Hetero
Graph
(
C_gidx
,
ntypes
,
etypes
)
C
=
DGLGraph
(
C_gidx
,
ntypes
,
etypes
)
C
.
edata
[
weight_name
]
=
C_weights
C
.
edata
[
weight_name
]
=
C_weights
return
C
return
C
...
@@ -2890,29 +2888,10 @@ def adj_sum_graph(graphs, weight_name):
...
@@ -2890,29 +2888,10 @@ def adj_sum_graph(graphs, weight_name):
C_gidx
,
C_weights
=
F
.
csrsum
(
gidxs
,
weights
)
C_gidx
,
C_weights
=
F
.
csrsum
(
gidxs
,
weights
)
C_gidx
=
create_heterograph_from_relations
(
metagraph
,
[
C_gidx
],
num_nodes
)
C_gidx
=
create_heterograph_from_relations
(
metagraph
,
[
C_gidx
],
num_nodes
)
C
=
DGL
Hetero
Graph
(
C_gidx
,
graphs
[
0
].
ntypes
,
graphs
[
0
].
etypes
)
C
=
DGLGraph
(
C_gidx
,
graphs
[
0
].
ntypes
,
graphs
[
0
].
etypes
)
C
.
edata
[
weight_name
]
=
C_weights
C
.
edata
[
weight_name
]
=
C_weights
return
C
return
C
def
as_heterograph
(
g
,
ntype
=
'_U'
,
etype
=
'_E'
):
# pylint: disable=unused-argument
"""Convert a DGLGraph to a DGLHeteroGraph with one node and edge type.
DEPRECATED: DGLGraph and DGLHeteroGraph have been merged. This function will
do nothing and can be removed safely in all cases.
"""
dgl_warning
(
'DEPRECATED: DGLGraph and DGLHeteroGraph have been merged in v0.5.
\n
'
'
\t
dgl.as_heterograph will do nothing and can be removed safely in all cases.'
)
return
g
def
as_immutable_graph
(
hg
):
"""Convert a DGLHeteroGraph with one node and edge type into a DGLGraph.
DEPRECATED: DGLGraph and DGLHeteroGraph have been merged. This function will
do nothing and can be removed safely in all cases.
"""
dgl_warning
(
'DEPRECATED: DGLGraph and DGLHeteroGraph have been merged in v0.5.
\n
'
'
\t
dgl.as_immutable_graph will do nothing and can be removed safely in all cases.'
)
return
hg
def
sort_csr_by_tag
(
g
,
tag
,
tag_offset_name
=
'_TAG_OFFSET'
,
tag_type
=
'node'
):
def
sort_csr_by_tag
(
g
,
tag
,
tag_offset_name
=
'_TAG_OFFSET'
,
tag_type
=
'node'
):
r
"""Return a new graph whose CSR matrix is sorted by the given tag.
r
"""Return a new graph whose CSR matrix is sorted by the given tag.
...
@@ -3398,7 +3377,7 @@ def reorder_graph(g, node_permute_algo=None, edge_permute_algo='src',
...
@@ -3398,7 +3377,7 @@ def reorder_graph(g, node_permute_algo=None, edge_permute_algo='src',
return
rg
return
rg
DGL
Hetero
Graph
.
reorder_graph
=
utils
.
alias_func
(
reorder_graph
)
DGLGraph
.
reorder_graph
=
utils
.
alias_func
(
reorder_graph
)
def
metis_perm
(
g
,
k
):
def
metis_perm
(
g
,
k
):
...
@@ -3750,7 +3729,7 @@ def to_half(g):
...
@@ -3750,7 +3729,7 @@ def to_half(g):
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
Clone of graph with the feature data converted to float16.
Clone of graph with the feature data converted to float16.
"""
"""
ret
=
copy
.
copy
(
g
)
ret
=
copy
.
copy
(
g
)
...
@@ -3767,7 +3746,7 @@ def to_float(g):
...
@@ -3767,7 +3746,7 @@ def to_float(g):
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
Clone of graph with the feature data converted to float32.
Clone of graph with the feature data converted to float32.
"""
"""
ret
=
copy
.
copy
(
g
)
ret
=
copy
.
copy
(
g
)
...
@@ -3784,7 +3763,7 @@ def to_double(g):
...
@@ -3784,7 +3763,7 @@ def to_double(g):
Returns
Returns
-------
-------
DGL
Hetero
Graph
DGLGraph
Clone of graph with the feature data converted to float64.
Clone of graph with the feature data converted to float64.
"""
"""
ret
=
copy
.
copy
(
g
)
ret
=
copy
.
copy
(
g
)
...
...
python/dgl/traversal.py
View file @
3132da28
...
@@ -4,7 +4,7 @@ from __future__ import absolute_import
...
@@ -4,7 +4,7 @@ from __future__ import absolute_import
from
.
import
backend
as
F
from
.
import
backend
as
F
from
.
import
utils
from
.
import
utils
from
._ffi.function
import
_init_api
from
._ffi.function
import
_init_api
from
.heterograph
import
DGL
Hetero
Graph
from
.heterograph
import
DGLGraph
__all__
=
[
__all__
=
[
"bfs_nodes_generator"
,
"bfs_nodes_generator"
,
...
@@ -20,7 +20,7 @@ def bfs_nodes_generator(graph, source, reverse=False):
...
@@ -20,7 +20,7 @@ def bfs_nodes_generator(graph, source, reverse=False):
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
source : list, tensor of nodes
source : list, tensor of nodes
Source nodes.
Source nodes.
...
@@ -46,8 +46,8 @@ def bfs_nodes_generator(graph, source, reverse=False):
...
@@ -46,8 +46,8 @@ def bfs_nodes_generator(graph, source, reverse=False):
[tensor([0]), tensor([1]), tensor([2, 3]), tensor([4, 5])]
[tensor([0]), tensor([1]), tensor([2, 3]), tensor([4, 5])]
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"bfs_nodes_generator only support homogeneous graph"
),
"bfs_nodes_generator only support homogeneous graph"
...
@@ -67,7 +67,7 @@ def bfs_edges_generator(graph, source, reverse=False):
...
@@ -67,7 +67,7 @@ def bfs_edges_generator(graph, source, reverse=False):
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
source : list, tensor of nodes
source : list, tensor of nodes
Source nodes.
Source nodes.
...
@@ -94,8 +94,8 @@ def bfs_edges_generator(graph, source, reverse=False):
...
@@ -94,8 +94,8 @@ def bfs_edges_generator(graph, source, reverse=False):
[tensor([0]), tensor([1, 2]), tensor([4, 5])]
[tensor([0]), tensor([1, 2]), tensor([4, 5])]
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"bfs_edges_generator only support homogeneous graph"
),
"bfs_edges_generator only support homogeneous graph"
...
@@ -115,7 +115,7 @@ def topological_nodes_generator(graph, reverse=False):
...
@@ -115,7 +115,7 @@ def topological_nodes_generator(graph, reverse=False):
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
reverse : bool, optional
reverse : bool, optional
If True, traverse following the in-edge direction.
If True, traverse following the in-edge direction.
...
@@ -139,8 +139,8 @@ def topological_nodes_generator(graph, reverse=False):
...
@@ -139,8 +139,8 @@ def topological_nodes_generator(graph, reverse=False):
[tensor([0]), tensor([1]), tensor([2]), tensor([3, 4]), tensor([5])]
[tensor([0]), tensor([1]), tensor([2]), tensor([3, 4]), tensor([5])]
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"topological_nodes_generator only support homogeneous graph"
),
"topological_nodes_generator only support homogeneous graph"
...
@@ -163,7 +163,7 @@ def dfs_edges_generator(graph, source, reverse=False):
...
@@ -163,7 +163,7 @@ def dfs_edges_generator(graph, source, reverse=False):
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
source : list, tensor of nodes
source : list, tensor of nodes
Source nodes.
Source nodes.
...
@@ -191,8 +191,8 @@ def dfs_edges_generator(graph, source, reverse=False):
...
@@ -191,8 +191,8 @@ def dfs_edges_generator(graph, source, reverse=False):
[tensor([0]), tensor([1]), tensor([3]), tensor([5]), tensor([4])]
[tensor([0]), tensor([1]), tensor([3]), tensor([5]), tensor([4])]
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"dfs_edges_generator only support homogeneous graph"
),
"dfs_edges_generator only support homogeneous graph"
...
@@ -234,7 +234,7 @@ def dfs_labeled_edges_generator(
...
@@ -234,7 +234,7 @@ def dfs_labeled_edges_generator(
Parameters
Parameters
----------
----------
graph : DGL
Hetero
Graph
graph : DGLGraph
The graph object.
The graph object.
source : list, tensor of nodes
source : list, tensor of nodes
Source nodes.
Source nodes.
...
@@ -271,8 +271,8 @@ def dfs_labeled_edges_generator(
...
@@ -271,8 +271,8 @@ def dfs_labeled_edges_generator(
(tensor([0]), tensor([0]), tensor([0]), tensor([0]), tensor([0]), tensor([2]))
(tensor([0]), tensor([0]), tensor([0]), tensor([0]), tensor([0]), tensor([2]))
"""
"""
assert
isinstance
(
assert
isinstance
(
graph
,
DGL
Hetero
Graph
graph
,
DGLGraph
),
"DGLGraph is
deprecated
, Please use DGL
Hetero
Graph"
),
"DGL
Hetero
Graph is
merged with DGLGraph
, Please use DGLGraph"
assert
(
assert
(
len
(
graph
.
canonical_etypes
)
==
1
len
(
graph
.
canonical_etypes
)
==
1
),
"dfs_labeled_edges_generator only support homogeneous graph"
),
"dfs_labeled_edges_generator only support homogeneous graph"
...
...
Prev
1
2
3
Next
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