MCPcopy Create free account
hub / github.com/alibaba/graph-learn / Nodes

Class Nodes

graphlearn/python/data/values.py:226–360  ·  view source on GitHub ↗

As returned object of `get_next` api of `node_sampler` and `negative_sampler`, as returned object of `get_nodes` of `Graph` or as in-memory object for constructing graph.

Source from the content-addressed store, hash-verified

224
225
226class Nodes(Values):
227 """ As returned object of `get_next` api of `node_sampler` and
228 `negative_sampler`, as returned object of `get_nodes` of `Graph`
229 or as in-memory object for constructing graph.
230 """
231
232 def __init__(self,
233 ids,
234 node_type,
235 int_attrs=None,
236 float_attrs=None,
237 string_attrs=None,
238 weights=None,
239 labels=None,
240 shape=None,
241 graph=None):
242 super(Nodes, self).__init__(int_attrs=int_attrs,
243 float_attrs=float_attrs,
244 string_attrs=string_attrs,
245 weights=weights,
246 labels=labels,
247 shape=shape,
248 graph=graph)
249
250 ids = np.array(ids)
251 if shape is None:
252 self._shape = ids.shape
253 else:
254 if np.prod(ids.shape) == np.prod(shape):
255 self._shape = shape
256 else:
257 self._shape = ids.shape[0:] if len(shape) == 1 else \
258 (int(np.prod(ids.shape) / np.prod(shape[1:])), ) + shape[-1:]
259 self._ids = self._reshape(ids)
260 self._type = node_type
261
262 self._out_degrees = {} # key: edge_type, value: count
263 self._in_degrees = {}
264
265 def _get_decoder(self):
266 return self._graph.get_node_decoder(self._type)
267
268 def _lookup(self):
269 return self._graph.lookup_nodes(self._type, self._ids)
270
271 @property
272 def ids(self):
273 return self._ids
274
275 @property
276 def type(self): # pylint: disable=redefined-builtin
277 return self._type
278
279 @property
280 def shape(self):
281 return self._shape
282
283 @property

Callers 2

__next__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected