dgl.khop_adj

dgl.khop_adj(g, k)[source]

Return the matrix of \(A^k\) where \(A\) is the adjacency matrix of the graph \(g\).

The returned matrix is a 32-bit float dense matrix on CPU. The graph must be homogeneous.

Parameters
  • g (DGLGraph) – The input graph.

  • k (int) – The \(k\) in \(A^k\).

Returns

The returned tensor.

Return type

Tensor

Examples

>>> import dgl
>>> g = dgl.graph(([0,1,2,3,4,0,1,2,3,4], [0,1,2,3,4,1,2,3,4,0]))
>>> dgl.khop_adj(g, 1)
tensor([[1., 0., 0., 0., 1.],
        [1., 1., 0., 0., 0.],
        [0., 1., 1., 0., 0.],
        [0., 0., 1., 1., 0.],
        [0., 0., 0., 1., 1.]])
>>> dgl.khop_adj(g, 3)
tensor([[1., 0., 1., 3., 3.],
        [3., 1., 0., 1., 3.],
        [3., 3., 1., 0., 1.],
        [1., 3., 3., 1., 0.],
        [0., 1., 3., 3., 1.]])