mindspore_gl.GraphField

View Source On Gitee
class mindspore_gl.GraphField(src_idx=None, dst_idx=None, n_nodes=None, n_edges=None, indices=None, indptr=None, indices_backward=None, indptr_backward=None, csr=False)[source]

The data container for a graph.

The edge information are stored in COO format.

Parameters
  • src_idx (Tensor, optional) – A tensor with shape \((N\_EDGES)\), with int dtype, represents the source node index of COO edge matrix. Default: None.

  • dst_idx (Tensor, optional) – A tensor with shape \((N\_EDGES)\), with int dtype, represents the destination node index of COO edge matrix. Default: None.

  • n_nodes (int, optional) – An integer, represent the nodes count of the graph. Default: None.

  • n_edges (int, optional) – An integer, represent the edges count of the graph. Default: None.

  • indices (Tensor, optional) – A tensor with shape \((N\_EDGES)\), with int dtype, represents the indices of CSR edge matrix. Default: None.

  • indptr (Tensor, optional) – A tensor with shape \((N\_NODES)\), with int dtype, represents the indptr of CSR edge matrix. Default: None.

  • indices_backward (Tensor, optional) – A tensor with shape \((N\_EDGES)\), with int dtype, represents the indices backward of CSR edge matrix. Default: None.

  • indptr_backward (Tensor, optional) – A tensor with shape \((N\_NODES)\), with int dtype, represents the indptr backward of CSR edge matrix. Default: None.

  • csr (bool, optional) – Is the matrix CSR type. Default: False.

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore as ms
>>> from mindspore_gl import GraphField
>>> n_nodes = 9
>>> n_edges = 11
>>> src_idx = ms.Tensor([0, 2, 2, 3, 4, 5, 5, 6, 8, 8, 8], ms.int32)
>>> dst_idx = ms.Tensor([1, 0, 1, 5, 3, 4, 6, 4, 8, 8, 8], ms.int32)
>>> graph_field = GraphField(src_idx, dst_idx, n_nodes, n_edges)
>>> print(graph_field.get_graph())
[Tensor(shape=[11], dtype=Int32, value= [0, 2, 2, 3, 4, 5, 5, 6, 8, 8, 8]),
Tensor(shape=[11], dtype=Int32, value= [1, 0, 1, 5, 3, 4, 6, 4, 8, 8, 8]), 9, 11]
get_graph()[source]

Get the Graph.

Returns

List, a list of tensor, which should be used for construct function.