MCPcopy
hub / github.com/dmlc/dgl / adj_external

Method adj_external

python/dgl/heterograph.py:3838–3908  ·  view source on GitHub ↗

Return the adjacency matrix in an external format, such as Scipy or backend dependent sparse tensor. By default, a row of returned adjacency matrix represents the source of an edge and the column represents the destination. When transpose is True, a row represents t

(
        self, transpose=False, ctx=F.cpu(), scipy_fmt=None, etype=None
    )

Source from the content-addressed store, hash-verified

3836 )
3837
3838 def adj_external(
3839 self, transpose=False, ctx=F.cpu(), scipy_fmt=None, etype=None
3840 ):
3841 """Return the adjacency matrix in an external format, such as Scipy or
3842 backend dependent sparse tensor.
3843
3844 By default, a row of returned adjacency matrix represents the
3845 source of an edge and the column represents the destination.
3846
3847 When transpose is True, a row represents the destination and a column
3848 represents the source.
3849
3850 Parameters
3851 ----------
3852 transpose : bool, optional
3853 A flag to transpose the returned adjacency matrix. (Default: False)
3854 ctx : context, optional
3855 The context of returned adjacency matrix. (Default: cpu)
3856 scipy_fmt : str, optional
3857 If specified, return a scipy sparse matrix in the given format.
3858 Otherwise, return a backend dependent sparse tensor. (Default: None)
3859 etype : str or (str, str, str), optional
3860 The type names of the edges. The allowed type name formats are:
3861
3862 * ``(str, str, str)`` for source node type, edge type and destination node type.
3863 * or one ``str`` edge type name if the name can uniquely identify a
3864 triplet format in the graph.
3865
3866 Can be omitted if the graph has only one type of edges.
3867
3868 Returns
3869 -------
3870 SparseTensor or scipy.sparse.spmatrix
3871 Adjacency matrix.
3872
3873 Examples
3874 --------
3875
3876 The following example uses PyTorch backend.
3877
3878 >>> import dgl
3879 >>> import torch
3880
3881 Instantiate a heterogeneous graph.
3882
3883 >>> g = dgl.heterograph({
3884 ... ('user', 'follows', 'user'): ([0, 1], [0, 1]),
3885 ... ('developer', 'develops', 'game'): ([0, 1], [0, 2])
3886 ... })
3887
3888 Get a backend dependent sparse tensor. Here we use PyTorch for example.
3889
3890 >>> g.adj_external(etype='develops')
3891 tensor(indices=tensor([[0, 1],
3892 [0, 2]]),
3893 values=tensor([1., 1.]),
3894 size=(2, 3), nnz=2, layout=torch.sparse_coo)
3895

Callers 15

test_dense_cheb_convFunction · 0.95
khop_adjFunction · 0.80
khop_graphFunction · 0.80
laplacian_lambda_maxFunction · 0.80
metapath_reachable_graphFunction · 0.80
rcmk_permFunction · 0.80
random_walk_peFunction · 0.80
lap_peFunction · 0.80
shortest_distFunction · 0.80
svd_peFunction · 0.80
test_graph_convFunction · 0.80

Calls 4

get_etype_idMethod · 0.95
cpuMethod · 0.45
adjacency_matrixMethod · 0.45

Tested by 15

test_dense_cheb_convFunction · 0.76
test_graph_convFunction · 0.64
test_tagconvFunction · 0.64
test_dense_cheb_convFunction · 0.64
test_dense_graph_convFunction · 0.64
test_dense_sage_convFunction · 0.64
test_adj_externalFunction · 0.64
test_topological_nodesFunction · 0.64
_test_oneFunction · 0.64
_test_csr_oneFunction · 0.64
test_scipy_adjmatFunction · 0.64
test_sort_with_tagFunction · 0.64