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

Class SparseNodes

graphlearn/python/data/values.py:362–445  ·  view source on GitHub ↗

SparseNodes is the returned value of full neighbor sampler which is 2D. It can be easily transformed to Tensorflow or PyTorch Sparse Tensors.

Source from the content-addressed store, hash-verified

360 (self.shape[0], self._get_decoder().float_attr_num))
361
362class SparseNodes(Nodes, SparseBase):
363 """ SparseNodes is the returned value of full neighbor sampler which
364 is 2D. It can be easily transformed to Tensorflow or PyTorch Sparse
365 Tensors.
366 """
367
368 def __init__(self,
369 ids,
370 offsets,
371 dense_shape,
372 node_type,
373 int_attrs=None,
374 float_attrs=None,
375 string_attrs=None,
376 weights=None,
377 labels=None,
378 graph=None):
379 """ Sparse Nodes.
380 Args:
381 ids: A 1D numpy array, the ids of the nodes.
382 offsets: A python list, each elem of list is an int,
383 which indicates the number of nodes.
384 dense_shape: The shape of the the corresponding dense Nodes.
385 For example, ids=[5, 2, 1, 6, 2, 4],
386 offsets=[3, 2, 1],
387 dense_shape=[3, 5].
388 The corresponding dense Nodes is
389 [[ 5, 2, 1, -1, -1],
390 [ 6, 2, -1, -1, -1],
391 [ 4, -1, -1, -1, -1]]
392 """
393 Nodes.__init__(self, ids,
394 node_type,
395 int_attrs=None,
396 float_attrs=None,
397 string_attrs=None,
398 weights=weights,
399 labels=labels,
400 shape=None,
401 graph=graph)
402 SparseBase.__init__(self, offsets, dense_shape)
403 num_nodes = sum(offsets)
404 if ids.shape[0] != num_nodes:
405 raise ValueError("Ids must be the same length of indices")
406
407 def __next__(self):
408 if self._it < len(self._offsets):
409 l = self._global_offsets[self._it]
410 r = self._global_offsets[self._it + 1]
411 self._it += 1
412 nodes = Nodes(self._ids[l: r], self._type, graph=self._graph,
413 int_attrs=np.array([int_attr[l: r] \
414 for int_attr in self._int_attrs]) \
415 if self._int_attrs is not None else None,
416 float_attrs=np.array([float_attr[l: r] \
417 for float_attr in self._float_attrs]) \
418 if self._float_attrs is not None else None, \
419 string_attrs=np.array([string_attr[l: r] \

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected