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

Method get

graphlearn/python/sampler/node_sampler.py:85–117  ·  view source on GitHub ↗

Get batched sampled nodes. Return: A `Nodes` object, shape=[`batch_size`] Raise: `graphlearn.OutOfRangeError`

(self)

Source from the content-addressed store, hash-verified

83 self._node_type = dst_type
84
85 def get(self):
86 """ Get batched sampled nodes.
87
88 Return:
89 A `Nodes` object, shape=[`batch_size`]
90 Raise:
91 `graphlearn.OutOfRangeError`
92 """
93 mask_type = utils.get_mask_type(self._type, self._mask)
94 state = self._graph.node_state.get(mask_type)
95 req = pywrap.new_get_nodes_request(mask_type,
96 self._strategy,
97 self._node_from,
98 self._batch_size,
99 state)
100
101 res = pywrap.new_get_nodes_response()
102 status = self._client.get_nodes(req, res)
103 if status.ok():
104 ids = pywrap.get_node_ids(res)
105 else:
106 if status.code() == errors.OUT_OF_RANGE:
107 if self._client.connect_to_next_server():
108 return self.get()
109 else:
110 self._graph.node_state.inc(mask_type)
111
112 pywrap.del_op_response(res)
113 pywrap.del_op_request(req)
114 errors.raise_exception_on_not_ok_status(status)
115
116 nodes = self._graph.get_nodes(self._node_type, ids)
117 return nodes
118
119
120class RandomNodeSampler(NodeSampler):

Callers 15

test_1hopMethod · 0.45
test_negMethod · 0.45
test_negMethod · 0.45
test_1hopMethod · 0.45
test_2hopMethod · 0.45
test_indegreeMethod · 0.45
test_randomMethod · 0.45

Calls 5

codeMethod · 0.80
incMethod · 0.80
get_nodesMethod · 0.45
okMethod · 0.45

Tested by 15

test_1hopMethod · 0.36
test_negMethod · 0.36
test_negMethod · 0.36
test_1hopMethod · 0.36
test_2hopMethod · 0.36
test_indegreeMethod · 0.36
test_randomMethod · 0.36