未验证 提交 220b676d 编写于 作者: O ooooo-create 提交者: GitHub

[xdoctest][task 60-64] reformat example code with google style in...

[xdoctest][task 60-64] reformat example code with google style in `geometric/*` ,`hapi/callbacks.py` (#55919)

* [Doctest]fix No.21, test=docs_preview

* Revert "[Doctest]fix No.21, test=docs_preview"

This reverts commit 76bcdb280e254d682be6fc6f85588f1940bb1ade.

* [Doctest]fix No.60-64, test=docs_preview
上级 801a8655
...@@ -43,11 +43,13 @@ def segment_sum(data, segment_ids, name=None): ...@@ -43,11 +43,13 @@ def segment_sum(data, segment_ids, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32') >>> data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32')
segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32') >>> segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32')
out = paddle.geometric.segment_sum(data, segment_ids) >>> out = paddle.geometric.segment_sum(data, segment_ids)
#Outputs: [[4., 4., 4.], [4., 5., 6.]] >>> print(out.numpy())
[[4. 4. 4.]
[4. 5. 6.]]
""" """
if in_dynamic_mode(): if in_dynamic_mode():
...@@ -99,11 +101,13 @@ def segment_mean(data, segment_ids, name=None): ...@@ -99,11 +101,13 @@ def segment_mean(data, segment_ids, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32') >>> data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32')
segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32') >>> segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32')
out = paddle.geometric.segment_mean(data, segment_ids) >>> out = paddle.geometric.segment_mean(data, segment_ids)
#Outputs: [[2., 2., 2.], [4., 5., 6.]] >>> print(out.numpy())
[[2. 2. 2.]
[4. 5. 6.]]
""" """
...@@ -155,11 +159,13 @@ def segment_min(data, segment_ids, name=None): ...@@ -155,11 +159,13 @@ def segment_min(data, segment_ids, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32') >>> data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32')
segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32') >>> segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32')
out = paddle.geometric.segment_min(data, segment_ids) >>> out = paddle.geometric.segment_min(data, segment_ids)
#Outputs: [[1., 2., 1.], [4., 5., 6.]] >>> print(out.numpy())
[[1. 2. 1.]
[4. 5. 6.]]
""" """
...@@ -211,11 +217,13 @@ def segment_max(data, segment_ids, name=None): ...@@ -211,11 +217,13 @@ def segment_max(data, segment_ids, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32') >>> data = paddle.to_tensor([[1, 2, 3], [3, 2, 1], [4, 5, 6]], dtype='float32')
segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32') >>> segment_ids = paddle.to_tensor([0, 0, 1], dtype='int32')
out = paddle.geometric.segment_max(data, segment_ids) >>> out = paddle.geometric.segment_max(data, segment_ids)
#Outputs: [[3., 2., 3.], [4., 5., 6.]] >>> print(out.numpy())
[[3. 2. 3.]
[4. 5. 6.]]
""" """
......
...@@ -88,26 +88,34 @@ def send_u_recv( ...@@ -88,26 +88,34 @@ def send_u_recv(
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") >>> x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32")
indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32") >>> indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32")
src_index, dst_index = indexes[:, 0], indexes[:, 1] >>> src_index, dst_index = indexes[:, 0], indexes[:, 1]
out = paddle.geometric.send_u_recv(x, src_index, dst_index, reduce_op="sum") >>> out = paddle.geometric.send_u_recv(x, src_index, dst_index, reduce_op="sum")
# Outputs: [[0., 2., 3.], [2., 8., 10.], [1., 4., 5.]] >>> print(out.numpy())
[[ 0. 2. 3.]
x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") [ 2. 8. 10.]
indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32") [ 1. 4. 5.]]
src_index, dst_index = indexes[:, 0], indexes[:, 1]
out_size = paddle.max(dst_index) + 1 >>> x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32")
out = paddle.geometric.send_u_recv(x, src_index, dst_index, reduce_op="sum", out_size=out_size) >>> indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32")
# Outputs: [[0., 2., 3.], [[2., 8., 10.]]] >>> src_index, dst_index = indexes[:, 0], indexes[:, 1]
>>> out_size = paddle.max(dst_index) + 1
x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") >>> out = paddle.geometric.send_u_recv(x, src_index, dst_index, reduce_op="sum", out_size=out_size)
indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32") >>> print(out.numpy())
src_index, dst_index = indexes[:, 0], indexes[:, 1] [[ 0. 2. 3.]
out = paddle.geometric.send_u_recv(x, src_index, dst_index, reduce_op="sum") [ 2. 8. 10.]]
# Outputs: [[0., 2., 3.], [2., 8., 10.], [0., 0., 0.]]
>>> x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32")
>>> indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32")
>>> src_index, dst_index = indexes[:, 0], indexes[:, 1]
>>> out = paddle.geometric.send_u_recv(x, src_index, dst_index, reduce_op="sum")
>>> print(out.numpy())
[[ 0. 2. 3.]
[ 2. 8. 10.]
[ 0. 0. 0.]]
""" """
...@@ -247,29 +255,37 @@ def send_ue_recv( ...@@ -247,29 +255,37 @@ def send_ue_recv(
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") >>> x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32")
y = paddle.to_tensor([1, 1, 1, 1], dtype="float32") >>> y = paddle.to_tensor([1, 1, 1, 1], dtype="float32")
indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32") >>> indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32")
src_index, dst_index = indexes[:, 0], indexes[:, 1] >>> src_index, dst_index = indexes[:, 0], indexes[:, 1]
out = paddle.geometric.send_ue_recv(x, y, src_index, dst_index, message_op="add", reduce_op="sum") >>> out = paddle.geometric.send_ue_recv(x, y, src_index, dst_index, message_op="add", reduce_op="sum")
# Outputs: [[1., 3., 4.], [4., 10., 12.], [2., 5., 6.]] >>> print(out.numpy())
[[ 1. 3. 4.]
x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") [ 4. 10. 12.]
y = paddle.to_tensor([1, 1, 1], dtype="float32") [ 2. 5. 6.]]
indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32")
src_index, dst_index = indexes[:, 0], indexes[:, 1] >>> x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32")
out_size = paddle.max(dst_index) + 1 >>> y = paddle.to_tensor([1, 1, 1], dtype="float32")
out = paddle.geometric.send_ue_recv(x, y, src_index, dst_index, message_op="add", reduce_op="sum", out_size=out_size) >>> indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32")
# Outputs: [[1., 3., 4.], [[4., 10., 12.]]] >>> src_index, dst_index = indexes[:, 0], indexes[:, 1]
>>> out_size = paddle.max(dst_index) + 1
x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") >>> out = paddle.geometric.send_ue_recv(x, y, src_index, dst_index, message_op="add", reduce_op="sum", out_size=out_size)
y = paddle.to_tensor([1, 1, 1], dtype="float32") >>> print(out.numpy())
indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32") [[ 1. 3. 4.]
src_index, dst_index = indexes[:, 0], indexes[:, 1] [ 4. 10. 12.]]
out = paddle.geometric.send_ue_recv(x, y, src_index, dst_index, message_op="add", reduce_op="sum")
# Outputs: [[1., 3., 4.], [4., 10., 12.], [0., 0., 0.]] >>> x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32")
>>> y = paddle.to_tensor([1, 1, 1], dtype="float32")
>>> indexes = paddle.to_tensor([[0, 1], [2, 1], [0, 0]], dtype="int32")
>>> src_index, dst_index = indexes[:, 0], indexes[:, 1]
>>> out = paddle.geometric.send_ue_recv(x, y, src_index, dst_index, message_op="add", reduce_op="sum")
>>> print(out.numpy())
[[ 1. 3. 4.]
[ 4. 10. 12.]
[ 0. 0. 0.]]
""" """
...@@ -425,15 +441,19 @@ def send_uv(x, y, src_index, dst_index, message_op="add", name=None): ...@@ -425,15 +441,19 @@ def send_uv(x, y, src_index, dst_index, message_op="add", name=None):
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") >>> x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32")
y = paddle.to_tensor([[0, 1, 2], [2, 3, 4], [4, 5, 6]], dtype="float32") >>> y = paddle.to_tensor([[0, 1, 2], [2, 3, 4], [4, 5, 6]], dtype="float32")
indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32") >>> indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32")
src_index = indexes[:, 0] >>> src_index = indexes[:, 0]
dst_index = indexes[:, 1] >>> dst_index = indexes[:, 1]
out = paddle.geometric.send_uv(x, y, src_index, dst_index, message_op="add") >>> out = paddle.geometric.send_uv(x, y, src_index, dst_index, message_op="add")
# Outputs: [[2., 5., 7.], [5., 9., 11.], [4., 9., 11.], [0., 3., 5.]] >>> print(out.numpy())
[[ 2. 5. 7.]
[ 5. 9. 11.]
[ 4. 9. 11.]
[ 0. 3. 5.]]
""" """
......
...@@ -69,18 +69,21 @@ def reindex_graph( ...@@ -69,18 +69,21 @@ def reindex_graph(
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
x = [0, 1, 2] >>> x = [0, 1, 2]
neighbors = [8, 9, 0, 4, 7, 6, 7] >>> neighbors = [8, 9, 0, 4, 7, 6, 7]
count = [2, 3, 2] >>> count = [2, 3, 2]
x = paddle.to_tensor(x, dtype="int64") >>> x = paddle.to_tensor(x, dtype="int64")
neighbors = paddle.to_tensor(neighbors, dtype="int64") >>> neighbors = paddle.to_tensor(neighbors, dtype="int64")
count = paddle.to_tensor(count, dtype="int32") >>> count = paddle.to_tensor(count, dtype="int32")
reindex_src, reindex_dst, out_nodes = paddle.geometric.reindex_graph(x, neighbors, count) >>> reindex_src, reindex_dst, out_nodes = paddle.geometric.reindex_graph(x, neighbors, count)
# reindex_src: [3, 4, 0, 5, 6, 7, 6] >>> print(reindex_src.numpy())
# reindex_dst: [0, 0, 1, 1, 1, 2, 2] [3 4 0 5 6 7 6]
# out_nodes: [0, 1, 2, 8, 9, 4, 7, 6] >>> print(reindex_dst.numpy())
[0 0 1 1 1 2 2]
>>> print(out_nodes.numpy())
[0 1 2 8 9 4 7 6]
""" """
use_buffer_hashtable = ( use_buffer_hashtable = (
...@@ -182,24 +185,27 @@ def reindex_heter_graph( ...@@ -182,24 +185,27 @@ def reindex_heter_graph(
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
x = [0, 1, 2] >>> x = [0, 1, 2]
neighbors_a = [8, 9, 0, 4, 7, 6, 7] >>> neighbors_a = [8, 9, 0, 4, 7, 6, 7]
count_a = [2, 3, 2] >>> count_a = [2, 3, 2]
x = paddle.to_tensor(x, dtype="int64") >>> x = paddle.to_tensor(x, dtype="int64")
neighbors_a = paddle.to_tensor(neighbors_a, dtype="int64") >>> neighbors_a = paddle.to_tensor(neighbors_a, dtype="int64")
count_a = paddle.to_tensor(count_a, dtype="int32") >>> count_a = paddle.to_tensor(count_a, dtype="int32")
neighbors_b = [0, 2, 3, 5, 1] >>> neighbors_b = [0, 2, 3, 5, 1]
count_b = [1, 3, 1] >>> count_b = [1, 3, 1]
neighbors_b = paddle.to_tensor(neighbors_b, dtype="int64") >>> neighbors_b = paddle.to_tensor(neighbors_b, dtype="int64")
count_b = paddle.to_tensor(count_b, dtype="int32") >>> count_b = paddle.to_tensor(count_b, dtype="int32")
neighbors = [neighbors_a, neighbors_b] >>> neighbors = [neighbors_a, neighbors_b]
count = [count_a, count_b] >>> count = [count_a, count_b]
reindex_src, reindex_dst, out_nodes = paddle.geometric.reindex_heter_graph(x, neighbors, count) >>> reindex_src, reindex_dst, out_nodes = paddle.geometric.reindex_heter_graph(x, neighbors, count)
# reindex_src: [3, 4, 0, 5, 6, 7, 6, 0, 2, 8, 9, 1] >>> print(reindex_src.numpy())
# reindex_dst: [0, 0, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2] [3 4 0 5 6 7 6 0 2 8 9 1]
# out_nodes: [0, 1, 2, 8, 9, 4, 7, 6, 3, 5] >>> print(reindex_dst.numpy())
[0 0 1 1 1 2 2 0 1 1 1 2]
>>> print(out_nodes.numpy())
[0 1 2 8 9 4 7 6 3 5]
""" """
use_buffer_hashtable = ( use_buffer_hashtable = (
......
...@@ -77,18 +77,18 @@ def sample_neighbors( ...@@ -77,18 +77,18 @@ def sample_neighbors(
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
# edges: (3, 0), (7, 0), (0, 1), (9, 1), (1, 2), (4, 3), (2, 4), >>> # edges: (3, 0), (7, 0), (0, 1), (9, 1), (1, 2), (4, 3), (2, 4),
# (9, 5), (3, 5), (9, 6), (1, 6), (9, 8), (7, 8) >>> # (9, 5), (3, 5), (9, 6), (1, 6), (9, 8), (7, 8)
row = [3, 7, 0, 9, 1, 4, 2, 9, 3, 9, 1, 9, 7] >>> row = [3, 7, 0, 9, 1, 4, 2, 9, 3, 9, 1, 9, 7]
colptr = [0, 2, 4, 5, 6, 7, 9, 11, 11, 13, 13] >>> colptr = [0, 2, 4, 5, 6, 7, 9, 11, 11, 13, 13]
nodes = [0, 8, 1, 2] >>> nodes = [0, 8, 1, 2]
sample_size = 2 >>> sample_size = 2
row = paddle.to_tensor(row, dtype="int64") >>> row = paddle.to_tensor(row, dtype="int64")
colptr = paddle.to_tensor(colptr, dtype="int64") >>> colptr = paddle.to_tensor(colptr, dtype="int64")
nodes = paddle.to_tensor(nodes, dtype="int64") >>> nodes = paddle.to_tensor(nodes, dtype="int64")
out_neighbors, out_count = paddle.geometric.sample_neighbors(row, colptr, nodes, sample_size=sample_size) >>> out_neighbors, out_count = paddle.geometric.sample_neighbors(row, colptr, nodes, sample_size=sample_size)
""" """
...@@ -228,20 +228,20 @@ def weighted_sample_neighbors( ...@@ -228,20 +228,20 @@ def weighted_sample_neighbors(
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
# edges: (3, 0), (7, 0), (0, 1), (9, 1), (1, 2), (4, 3), (2, 4), >>> # edges: (3, 0), (7, 0), (0, 1), (9, 1), (1, 2), (4, 3), (2, 4),
# (9, 5), (3, 5), (9, 6), (1, 6), (9, 8), (7, 8) >>> # (9, 5), (3, 5), (9, 6), (1, 6), (9, 8), (7, 8)
row = [3, 7, 0, 9, 1, 4, 2, 9, 3, 9, 1, 9, 7] >>> row = [3, 7, 0, 9, 1, 4, 2, 9, 3, 9, 1, 9, 7]
colptr = [0, 2, 4, 5, 6, 7, 9, 11, 11, 13, 13] >>> colptr = [0, 2, 4, 5, 6, 7, 9, 11, 11, 13, 13]
weight = [0.1, 0.5, 0.2, 0.5, 0.9, 1.9, 2.0, 2.1, 0.01, 0.9, 0,12, 0.59, 0.67] >>> weight = [0.1, 0.5, 0.2, 0.5, 0.9, 1.9, 2.0, 2.1, 0.01, 0.9, 0,12, 0.59, 0.67]
nodes = [0, 8, 1, 2] >>> nodes = [0, 8, 1, 2]
sample_size = 2 >>> sample_size = 2
row = paddle.to_tensor(row, dtype="int64") >>> row = paddle.to_tensor(row, dtype="int64")
colptr = paddle.to_tensor(colptr, dtype="int64") >>> colptr = paddle.to_tensor(colptr, dtype="int64")
weight = paddle.to_tensor(weight, dtype="float32") >>> weight = paddle.to_tensor(weight, dtype="float32")
nodes = paddle.to_tensor(nodes, dtype="int64") >>> nodes = paddle.to_tensor(nodes, dtype="int64")
out_neighbors, out_count = paddle.geometric.weighted_sample_neighbors(row, colptr, weight, nodes, sample_size=sample_size) >>> out_neighbors, out_count = paddle.geometric.weighted_sample_neighbors(row, colptr, weight, nodes, sample_size=sample_size)
""" """
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册