galax.heterograph.graph

galax.heterograph.graph(data: Any, n_nodes: Optional[Union[Mapping, int]] = None)[source]

Create a heterogeneous graph and return.

Parameters
  • data (Any)

  • n_nodes (Optional[Union[Mapping, int]] (default=None))

Returns

The created graph.

Return type

HeteroGraph

Examples

Create a small three-edge graph. >>> # Source nodes for edges (2, 1), (3, 2), (4, 3) >>> src_ids = jnp.array([2, 3, 4]) >>> # Destination nodes for edges (2, 1), (3, 2), (4, 3) >>> dst_ids = jnp.array([1, 2, 3]) >>> g = graph((src_ids, dst_ids)) >>> int(g.number_of_nodes()) 5 >>> int(g.number_of_edges()) 3 >>> g.ntypes (’N_’,) >>> g.etypes (’E_’,)

Explicitly specify the number of nodes in the graph. >>> g = graph((src_ids, dst_ids), n_nodes=2666) >>> int(g.number_of_nodes()) 2666 >>> int(g.number_of_edges()) 3

>>> data_dict = {
...     ('user', 'follows', 'user'): ((0, 1), (1, 2)),
...     ('user', 'follows_', 'topic'): ((1, 1), (1, 2)), # etype different
...     ('user', 'plays', 'game'): ((0, 3), (3, 4)),
... }
>>> g = graph(data_dict)
>>> g.number_of_nodes('user').item()
4
>>> int(g.number_of_edges('follows'))
2