Return a node data view for setting/getting destination node features. Let ``g`` be a DGLGraph. If ``g`` is a graph of a single destination node type, ``g.dstdata[feat]`` returns the destination node feature associated with the name ``feat``. One can also set a destination n
(self)
| 2088 | |
| 2089 | @property |
| 2090 | def dstdata(self): |
| 2091 | """Return a node data view for setting/getting destination node features. |
| 2092 | |
| 2093 | Let ``g`` be a DGLGraph. If ``g`` is a graph of a single destination node type, |
| 2094 | ``g.dstdata[feat]`` returns the destination node feature associated with the name |
| 2095 | ``feat``. One can also set a destination node feature associated with the name |
| 2096 | ``feat`` by setting ``g.dstdata[feat]`` to a tensor. |
| 2097 | |
| 2098 | If ``g`` is a graph of multiple destination node types, ``g.dstdata[feat]`` returns a |
| 2099 | dict[str, Tensor] mapping destination node types to the node features associated with |
| 2100 | the name ``feat`` for the corresponding type. One can also set a node feature |
| 2101 | associated with the name ``feat`` for some destination node type(s) by setting |
| 2102 | ``g.dstdata[feat]`` to a dictionary as described. |
| 2103 | |
| 2104 | Notes |
| 2105 | ----- |
| 2106 | For setting features, the device of the features must be the same as the device |
| 2107 | of the graph. |
| 2108 | |
| 2109 | Examples |
| 2110 | -------- |
| 2111 | The following example uses PyTorch backend. |
| 2112 | |
| 2113 | >>> import dgl |
| 2114 | >>> import torch |
| 2115 | |
| 2116 | Set and get feature 'h' for a graph of a single destination node type. |
| 2117 | |
| 2118 | >>> g = dgl.heterograph({ |
| 2119 | ... ('user', 'plays', 'game'): (torch.tensor([0, 1]), torch.tensor([1, 2]))}) |
| 2120 | >>> g.dstdata['h'] = torch.ones(3, 1) |
| 2121 | >>> g.dstdata['h'] |
| 2122 | tensor([[1.], |
| 2123 | [1.], |
| 2124 | [1.]]) |
| 2125 | |
| 2126 | Set and get feature 'h' for a graph of multiple destination node types. |
| 2127 | |
| 2128 | >>> g = dgl.heterograph({ |
| 2129 | ... ('user', 'plays', 'game'): (torch.tensor([1, 2]), torch.tensor([1, 2])), |
| 2130 | ... ('user', 'watches', 'movie'): (torch.tensor([2, 2]), torch.tensor([1, 1])) |
| 2131 | ... }) |
| 2132 | >>> g.dstdata['h'] = {'game': torch.zeros(3, 1), 'movie': torch.ones(2, 1)} |
| 2133 | >>> g.dstdata['h'] |
| 2134 | {'game': tensor([[0.], [0.], [0.]]), |
| 2135 | 'movie': tensor([[1.], [1.]])} |
| 2136 | >>> g.dstdata['h'] = {'game': torch.ones(3, 1)} |
| 2137 | >>> g.dstdata['h'] |
| 2138 | {'game': tensor([[1.], [1.], [1.]]), |
| 2139 | 'movie': tensor([[1.], [1.]])} |
| 2140 | |
| 2141 | See Also |
| 2142 | -------- |
| 2143 | nodes |
| 2144 | ndata |
| 2145 | dstnodes |
| 2146 | """ |
| 2147 | if len(self.dsttypes) == 1: |
nothing calls this directly
no test coverage detected