Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions python/dgl/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def graph(
device=None,
row_sorted=False,
col_sorted=False,
node_count_check=True,
):
"""Create a graph and return.

Expand Down Expand Up @@ -83,6 +84,9 @@ def graph(
col_sorted : bool, optional
Whether or not the columns of the COO are in ascending order within
each row. This only has an effect when ``row_sorted`` is True.
node_count_check : bool, optional
When num_nodes is passed, whether we should perform sanity checks to
ensure they are valid. Note that this comes with a performance penalty.

Returns
-------
Expand Down Expand Up @@ -160,9 +164,11 @@ def graph(
"graph, use dgl.from_networkx instead."
)

(sparse_fmt, arrays), urange, vrange = utils.graphdata2tensors(data, idtype)
(sparse_fmt, arrays), urange, vrange = utils.graphdata2tensors(
data, idtype, infer_node_count=(node_count_check or num_nodes is None)
)
if num_nodes is not None: # override the number of nodes
if num_nodes < max(urange, vrange):
if node_count_check and num_nodes < max(urange, vrange):
raise DGLError(
"The num_nodes argument must be larger than the max ID in the data,"
" but got {} and {}.".format(num_nodes, max(urange, vrange) - 1)
Expand Down