MCPcopy Index your code
hub / github.com/dmlc/dgl / inc

Method inc

python/dgl/heterograph.py:3950–4024  ·  view source on GitHub ↗

Return the incidence matrix representation of edges with the given edge type. An incidence matrix is an n-by-m sparse matrix, where n is the number of nodes and m is the number of edges. Each nnz value indicating whether the edge is incident to the node or no

(self, typestr, ctx=F.cpu(), etype=None)

Source from the content-addressed store, hash-verified

3948 return self._graph.adjacency_matrix_tensors(etid, False, fmt)[2:]
3949
3950 def inc(self, typestr, ctx=F.cpu(), etype=None):
3951 """Return the incidence matrix representation of edges with the given
3952 edge type.
3953
3954 An incidence matrix is an n-by-m sparse matrix, where n is
3955 the number of nodes and m is the number of edges. Each nnz
3956 value indicating whether the edge is incident to the node
3957 or not.
3958
3959 There are three types of incidence matrices :math:`I`:
3960
3961 * ``in``:
3962
3963 - :math:`I[v, e] = 1` if :math:`e` is the in-edge of :math:`v`
3964 (or :math:`v` is the dst node of :math:`e`);
3965 - :math:`I[v, e] = 0` otherwise.
3966
3967 * ``out``:
3968
3969 - :math:`I[v, e] = 1` if :math:`e` is the out-edge of :math:`v`
3970 (or :math:`v` is the src node of :math:`e`);
3971 - :math:`I[v, e] = 0` otherwise.
3972
3973 * ``both`` (only if source and destination node type are the same):
3974
3975 - :math:`I[v, e] = 1` if :math:`e` is the in-edge of :math:`v`;
3976 - :math:`I[v, e] = -1` if :math:`e` is the out-edge of :math:`v`;
3977 - :math:`I[v, e] = 0` otherwise (including self-loop).
3978
3979 Parameters
3980 ----------
3981 typestr : str
3982 Can be either ``in``, ``out`` or ``both``
3983 ctx : context, optional
3984 The context of returned incidence matrix. (Default: cpu)
3985 etype : str or (str, str, str), optional
3986 The type names of the edges. The allowed type name formats are:
3987
3988 * ``(str, str, str)`` for source node type, edge type and destination node type.
3989 * or one ``str`` edge type name if the name can uniquely identify a
3990 triplet format in the graph.
3991
3992 Can be omitted if the graph has only one type of edges.
3993
3994 Returns
3995 -------
3996 Framework SparseTensor
3997 The incidence matrix.
3998
3999 Examples
4000 --------
4001
4002 The following example uses PyTorch backend.
4003
4004 >>> import dgl
4005
4006 >>> g = dgl.graph(([0, 1], [0, 2]))
4007 >>> g.inc('in')

Callers 1

test_incFunction · 0.80

Calls 3

get_etype_idMethod · 0.95
cpuMethod · 0.45
incidence_matrixMethod · 0.45

Tested by 1

test_incFunction · 0.64