dgl.DGLHeteroGraph.edge_attr_schemes

DGLHeteroGraph.edge_attr_schemes(etype=None)[source]

Return the edge feature schemes for the specified type.

The scheme of a feature describes the shape and data type of it.

Parameters

etype (str or (str, str, str), optional) –

The type names of the edges. The allowed type name formats are:

  • (str, str, str) for source node type, edge type and destination node type.

  • or one str edge type name if the name can uniquely identify a triplet format in the graph.

Can be omitted if the graph has only one type of edges.

Returns

A dictionary mapping a feature name to its associated feature scheme.

Return type

dict[str, Scheme]

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch

Query for a homogeneous graph.

>>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2])))
>>> g.edata['h1'] = torch.randn(2, 1)
>>> g.edata['h2'] = torch.randn(2, 2)
>>> g.edge_attr_schemes()
{'h1': Scheme(shape=(1,), dtype=torch.float32),
 'h2': Scheme(shape=(2,), dtype=torch.float32)}

Query for a heterogeneous graph of multiple edge types.

>>> g = dgl.heterograph({('user', 'plays', 'game'):
...                      (torch.tensor([1, 2]), torch.tensor([3, 4])),
...                      ('user', 'follows', 'user'):
...                      (torch.tensor([3, 4]), torch.tensor([5, 6]))})
>>> g.edges['plays'].data['h1'] = torch.randn(2, 1)
>>> g.edges['plays'].data['h2'] = torch.randn(2, 2)
>>> g.edge_attr_schemes('plays')
{'h1': Scheme(shape=(1,), dtype=torch.float32),
 'h2': Scheme(shape=(2,), dtype=torch.float32)}