未验证 提交 a3e8ca42 编写于 作者: S Siming Dai 提交者: GitHub

[geometric] fix english doc (#46485)

* fix geometric doc
上级 b420d4dd
...@@ -38,10 +38,9 @@ def segment_sum(data, segment_ids, name=None): ...@@ -38,10 +38,9 @@ def segment_sum(data, segment_ids, name=None):
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
output (Tensor): the reduced result. - output (Tensor), the reduced result.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
...@@ -85,7 +84,7 @@ def segment_mean(data, segment_ids, name=None): ...@@ -85,7 +84,7 @@ def segment_mean(data, segment_ids, name=None):
r""" r"""
Segment mean Operator. Segment mean Operator.
Ihis operator calculate the mean value of input `data` which This operator calculate the mean value of input `data` which
with the same index in `segment_ids`. with the same index in `segment_ids`.
It computes a tensor such that $out_i = \\frac{1}{n_i} \\sum_{j} data[j]$ It computes a tensor such that $out_i = \\frac{1}{n_i} \\sum_{j} data[j]$
where sum is over j such that 'segment_ids[j] == i' and $n_i$ is the number where sum is over j such that 'segment_ids[j] == i' and $n_i$ is the number
...@@ -100,10 +99,9 @@ def segment_mean(data, segment_ids, name=None): ...@@ -100,10 +99,9 @@ def segment_mean(data, segment_ids, name=None):
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
output (Tensor): the reduced result. - output (Tensor), the reduced result.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
...@@ -162,10 +160,9 @@ def segment_min(data, segment_ids, name=None): ...@@ -162,10 +160,9 @@ def segment_min(data, segment_ids, name=None):
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
output (Tensor): the reduced result. - output (Tensor), the reduced result.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
...@@ -224,10 +221,9 @@ def segment_max(data, segment_ids, name=None): ...@@ -224,10 +221,9 @@ def segment_max(data, segment_ids, name=None):
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
output (Tensor): the reduced result. - output (Tensor), the reduced result.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
......
...@@ -36,7 +36,6 @@ def send_u_recv( ...@@ -36,7 +36,6 @@ def send_u_recv(
x, src_index, dst_index, reduce_op="sum", out_size=None, name=None x, src_index, dst_index, reduce_op="sum", out_size=None, name=None
): ):
""" """
Graph Learning message passing api. Graph Learning message passing api.
This api is mainly used in Graph Learning domain, and the main purpose is to reduce intermediate memory This api is mainly used in Graph Learning domain, and the main purpose is to reduce intermediate memory
...@@ -82,9 +81,8 @@ def send_u_recv( ...@@ -82,9 +81,8 @@ def send_u_recv(
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
out (Tensor): The output tensor, should have the same shape and same dtype as input tensor `x`. - out (Tensor), the output tensor, should have the same shape and same dtype as input tensor `x`.
If `out_size` is set correctly, then it should have the same shape as `x` except If `out_size` is set correctly, then it should have the same shape as `x` except the 0th dimension.
the 0th dimension.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -229,6 +227,7 @@ def send_ue_recv( ...@@ -229,6 +227,7 @@ def send_ue_recv(
out = [[1, 3, 4], out = [[1, 3, 4],
[4, 10, 12], [4, 10, 12],
[2, 5, 6]] [2, 5, 6]]
Args: Args:
x (Tensor): The input node feature tensor, and the available data type is float32, float64, int32, int64. x (Tensor): The input node feature tensor, and the available data type is float32, float64, int32, int64.
And we support float16 in gpu version. And we support float16 in gpu version.
...@@ -248,9 +247,8 @@ def send_ue_recv( ...@@ -248,9 +247,8 @@ def send_ue_recv(
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
out (Tensor): The output tensor, should have the same shape and same dtype as input tensor `x`. - out (Tensor), the output tensor, should have the same shape and same dtype as input tensor `x`.
If `out_size` is set correctly, then it should have the same shape as `x` except If `out_size` is set correctly, then it should have the same shape as `x` except the 0th dimension.
the 0th dimension.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -432,9 +430,10 @@ def send_uv(x, y, src_index, dst_index, message_op="add", name=None): ...@@ -432,9 +430,10 @@ def send_uv(x, y, src_index, dst_index, message_op="add", name=None):
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
out (Tensor): The output tensor. - out (Tensor), the output tensor.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
......
...@@ -28,25 +28,19 @@ def reindex_graph( ...@@ -28,25 +28,19 @@ def reindex_graph(
Reindex Graph API. Reindex Graph API.
This API is mainly used in Graph Learning domain, which should be used This API is mainly used in Graph Learning domain, which should be used
in conjunction with `graph_sample_neighbors` API. And the main purpose in conjunction with `paddle.geometric.sample_neighbors` API. And the main purpose
is to reindex the ids information of the input nodes, and return the is to reindex the ids information of the input nodes, and return the
corresponding graph edges after reindex. corresponding graph edges after reindex.
**Notes**: Take input nodes x = [0, 1, 2] as an example. If we have neighbors = [8, 9, 0, 4, 7, 6, 7], and count = [2, 3, 2],
The number in x should be unique, otherwise it would cause potential errors. then we know that the neighbors of 0 is [8, 9], the neighbors of 1 is [0, 4, 7], and the neighbors of 2 is [6, 7].
We will reindex all the nodes from 0. Then after graph_reindex, we will have 3 different outputs: reindex_src: [3, 4, 0, 5, 6, 7, 6], reindex_dst: [0, 0, 1, 1, 1, 2, 2]
and out_nodes: [0, 1, 2, 8, 9, 4, 7, 6]. We can see that the numbers in `reindex_src` and `reindex_dst` is the corresponding index
Take input nodes x = [0, 1, 2] as an example.
If we have neighbors = [8, 9, 0, 4, 7, 6, 7], and count = [2, 3, 2],
then we know that the neighbors of 0 is [8, 9], the neighbors of 1
is [0, 4, 7], and the neighbors of 2 is [6, 7].
Then after graph_reindex, we will have 3 different outputs:
1. reindex_src: [3, 4, 0, 5, 6, 7, 6]
2. reindex_dst: [0, 0, 1, 1, 1, 2, 2]
3. out_nodes: [0, 1, 2, 8, 9, 4, 7, 6]
We can see that the numbers in `reindex_src` and `reindex_dst` is the corresponding index
of nodes in `out_nodes`. of nodes in `out_nodes`.
Note:
The number in x should be unique, otherwise it would cause potential errors. We will reindex all the nodes from 0.
Args: Args:
x (Tensor): The input nodes which we sample neighbors for. The available x (Tensor): The input nodes which we sample neighbors for. The available
data type is int32, int64. data type is int32, int64.
...@@ -64,27 +58,23 @@ def reindex_graph( ...@@ -64,27 +58,23 @@ def reindex_graph(
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
reindex_src (Tensor): The source node index of graph edges after reindex. - reindex_src (Tensor), the source node index of graph edges after reindex.
reindex_dst (Tensor): The destination node index of graph edges after reindex.
out_nodes (Tensor): The index of unique input nodes and neighbors before reindex,
where we put the input nodes `x` in the front, and put neighbor
nodes in the back.
Examples: - reindex_dst (Tensor), the destination node index of graph edges after reindex.
- out_nodes (Tensor), the index of unique input nodes and neighbors before reindex, where we put the input nodes `x` in the front, and put neighbor nodes in the back.
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] # reindex_src: [3, 4, 0, 5, 6, 7, 6]
# reindex_dst: [0, 0, 1, 1, 1, 2, 2] # reindex_dst: [0, 0, 1, 1, 1, 2, 2]
# out_nodes: [0, 1, 2, 8, 9, 4, 7, 6] # out_nodes: [0, 1, 2, 8, 9, 4, 7, 6]
...@@ -150,26 +140,18 @@ def reindex_heter_graph( ...@@ -150,26 +140,18 @@ def reindex_heter_graph(
Reindex HeterGraph API. Reindex HeterGraph API.
This API is mainly used in Graph Learning domain, which should be used This API is mainly used in Graph Learning domain, which should be used
in conjunction with `graph_sample_neighbors` API. And the main purpose in conjunction with `paddle.geometric.sample_neighbors` API. And the main purpose
is to reindex the ids information of the input nodes, and return the is to reindex the ids information of the input nodes, and return the
corresponding graph edges after reindex. corresponding graph edges after reindex.
**Notes**: Take input nodes x = [0, 1, 2] as an example. For graph A, suppose we have neighbors = [8, 9, 0, 4, 7, 6, 7], and count = [2, 3, 2],
The number in x should be unique, otherwise it would cause potential errors. then we know that the neighbors of 0 is [8, 9], the neighbors of 1 is [0, 4, 7], and the neighbors of 2 is [6, 7]. For graph B,
We support multi-edge-types neighbors reindexing in reindex_heter_graph api. suppose we have neighbors = [0, 2, 3, 5, 1], and count = [1, 3, 1], then we know that the neighbors of 0 is [0], the neighbors of 1 is [2, 3, 5],
We will reindex all the nodes from 0. and the neighbors of 3 is [1]. We will get following outputs: reindex_src: [3, 4, 0, 5, 6, 7, 6, 0, 2, 8, 9, 1], reindex_dst: [0, 0, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2]
and out_nodes: [0, 1, 2, 8, 9, 4, 7, 6, 3, 5].
Take input nodes x = [0, 1, 2] as an example.
For graph A, suppose we have neighbors = [8, 9, 0, 4, 7, 6, 7], and count = [2, 3, 2], Note:
then we know that the neighbors of 0 is [8, 9], the neighbors of 1 The number in x should be unique, otherwise it would cause potential errors. We support multi-edge-types neighbors reindexing in reindex_heter_graph api. We will reindex all the nodes from 0.
is [0, 4, 7], and the neighbors of 2 is [6, 7].
For graph B, suppose we have neighbors = [0, 2, 3, 5, 1], and count = [1, 3, 1],
then we know that the neighbors of 0 is [0], the neighbors of 1 is [2, 3, 5],
and the neighbors of 3 is [1].
We will get following outputs:
1. reindex_src: [3, 4, 0, 5, 6, 7, 6, 0, 2, 8, 9, 1]
2. reindex_dst: [0, 0, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2]
3. out_nodes: [0, 1, 2, 8, 9, 4, 7, 6, 3, 5]
Args: Args:
x (Tensor): The input nodes which we sample neighbors for. The available x (Tensor): The input nodes which we sample neighbors for. The available
...@@ -188,34 +170,31 @@ def reindex_heter_graph( ...@@ -188,34 +170,31 @@ def reindex_heter_graph(
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
reindex_src (Tensor): The source node index of graph edges after reindex. - reindex_src (Tensor), the source node index of graph edges after reindex.
reindex_dst (Tensor): The destination node index of graph edges after reindex.
out_nodes (Tensor): The index of unique input nodes and neighbors before reindex, - reindex_dst (Tensor), the destination node index of graph edges after reindex.
- out_nodes (Tensor), the index of unique input nodes and neighbors before reindex,
where we put the input nodes `x` in the front, and put neighbor where we put the input nodes `x` in the front, and put neighbor
nodes in the back. nodes in the back.
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 = \ reindex_src, reindex_dst, out_nodes = paddle.geometric.reindex_heter_graph(x, neighbors, count)
paddle.geometric.reindex_heter_graph(x, neighbors, count)
# reindex_src: [3, 4, 0, 5, 6, 7, 6, 0, 2, 8, 9, 1] # reindex_src: [3, 4, 0, 5, 6, 7, 6, 0, 2, 8, 9, 1]
# reindex_dst: [0, 0, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2] # reindex_dst: [0, 0, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2]
# out_nodes: [0, 1, 2, 8, 9, 4, 7, 6, 3, 5] # out_nodes: [0, 1, 2, 8, 9, 4, 7, 6, 3, 5]
......
...@@ -65,14 +65,17 @@ def sample_neighbors( ...@@ -65,14 +65,17 @@ def sample_neighbors(
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
out_neighbors (Tensor): The sample neighbors of the input nodes. - out_neighbors (Tensor), the sample neighbors of the input nodes.
out_count (Tensor): The number of sampling neighbors of each input node, and the shape
- out_count (Tensor), the number of sampling neighbors of each input node, and the shape
should be the same with `input_nodes`. should be the same with `input_nodes`.
out_eids (Tensor): If `return_eids` is True, we will return the eid information of the
- out_eids (Tensor), if `return_eids` is True, we will return the eid information of the
sample edges. sample edges.
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)
...@@ -83,9 +86,7 @@ def sample_neighbors( ...@@ -83,9 +86,7 @@ def sample_neighbors(
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 = \ out_neighbors, out_count = paddle.geometric.sample_neighbors(row, colptr, nodes, sample_size=sample_size)
paddle.geometric.sample_neighbors(row, colptr, nodes,
sample_size=sample_size)
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册