dgl.DGLHeteroGraph.restrict_format

DGLHeteroGraph.restrict_format(etype=None)[source]

Return the allowed sparse formats of the given edge/relation type.

Parameters:etype (str or tuple of str, optional) – The edge type. Can be omitted if there is only one edge type in the graph.
Returns:str'any' indicates all sparse formats are allowed in .
Return type:'any', 'coo', 'csr', or 'csc'

Examples

For graph with only one edge type.

>>> g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows', restrict_format='csr')
>>> g.restrict_format()
'csr'

For a graph with multiple types.

>>> g = dgl.heterograph({
...     ('user', 'plays', 'game'): ([0, 1, 1, 2], [0, 0, 1, 1]),
...     ('developer', 'develops', 'game'): ([0, 1], [0, 1]),
...     }, restrict_format='any')
>>> g.restrict_format('develops')
'any'

which is equivalent to:

>>> g['develops'].restrict_format()
'any'

See also

format_in_use(), request_format(), to_format()