
    ΑipJ                    f   % S SK Jr  S SKJrJr  S SKrS SKJr  S SK	J
r
  S SKJrJrJr  S SKJr  S SKJr  S S	KJr  S
SKJrJrJr  \(       a  S SK	Jr  \S   rS\S'   \S   rS\S'   / r   S             SS jjr    S                 SS jjr  S             SS jjr g)    )annotations)TYPE_CHECKINGLiteralN)	TypeAlias)_C_ops)check_dtype
check_typecheck_variable_and_dtype)Variable)LayerHelper)in_dynamic_or_pir_mode   )convert_out_size_to_listget_out_size_tensor_inputsreshape_lhs_rhs)Tensorsummeanmaxminr   	_ReduceOpaddsubmuldiv
_MessageOpc                   US;  a  [        SU 35      e[        5       (       a2  [        US5      n[        R                  " XX#R                  5       U5      $ [        U SSS5        [        USSS5        [        USSS5        U(       a6  [        US	[        [        R                  [        R                  [        4S5        [        U[        5      (       a  [        UR                  S	S
S/S5        [!        S0 [#        5       D6nUR%                  U R                  S9nUR%                  S
SS9nXUS.n	SUR                  5       0n
['        U	U
USS9  UR)                  SU	XxS.U
S9  U$ )aG  
Graph Learning message passing api.

This api is mainly used in Graph Learning domain, and the main purpose is to reduce intermediate memory
consumption in the process of message passing. Take `x` as the input tensor, we first use `src_index`
to gather the corresponding data, and then use `dst_index` to update the corresponding position of output tensor
in different reduce ops, like sum, mean, max, or min. Besides, we can use `out_size` to set necessary output shape.

.. code-block:: text

       Given:

       x = [[0, 2, 3],
            [1, 4, 5],
            [2, 6, 7]]

       src_index = [0, 1, 2, 0]

       dst_index = [1, 2, 1, 0]

       reduce_op = "sum"

       out_size = None

       Then:

       out = [[0, 2, 3],
              [2, 8, 10],
              [1, 4, 5]]

Args:
    x (Tensor): The input tensor, and the available data type is float32, float64, int32, int64.
                And we support float16 in gpu version.
    src_index (Tensor): An 1-D tensor, and the available data type is int32, int64.
    dst_index (Tensor): An 1-D tensor, and should have the same shape as `src_index`.
                        The available data type is int32, int64.
    reduce_op (str): Different reduce ops, including `sum`, `mean`, `max`, `min`.
                     Default value is `sum`.
    out_size (int|Tensor|None): We can set `out_size` to get necessary output shape. If not set or
                                out_size is smaller or equal to 0, then this input will not be used.
                                Otherwise, `out_size` should be equal with or larger than
                                max(dst_index) + 1.
    name (str, optional): Name for the operation (optional, default is None).
                          For more information, please refer to :ref:`api_guide_Name`.

Returns:
    - 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 the 0th dimension.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> 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")
        >>> 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.]
         [ 1. 4. 5.]]

        >>> 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_size = paddle.max(dst_index) + 1
        >>> out = paddle.geometric.send_u_recv(x, src_index, dst_index, reduce_op="sum", out_size=out_size)
        >>> print(out.numpy())
        [[ 0. 2. 3.]
         [ 2. 8. 10.]]

        >>> 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.]]

r   @reduce_op should be `sum`, `mean`, `max` or `min`, but received graph_send_recvXfloat32float64int32int64float16	Src_indexr&   r'   	Dst_indexout_sizer&   r'   dtypeTr.   stop_gradient)r"   r)   r+   	reduce_opinputsattrsr,   op_typeOut	Dst_counttyper3   outputsr4   )send_u_recv)
ValueErrorr   r   r   r<   upperr
   r	   intnpr&   r'   r   
isinstancer   r.   r   locals"create_variable_for_type_inferencer   	append_op)x	src_index	dst_indexr1   r,   namehelperout	dst_countr3   r4   s              j/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/geometric/message_passing/send_recv.pyr<   r<   7   s   v 55NykZ
 	
 +H6GH!!)__%6
 	
 	!?		
 	!{$68I	
 	!{$68I	
 bhh(3!	 h))'"!	 7fh777agg7F== > 
	 yIioo/0"%		
 	"8	 	 	
 
    c           	        US;  a  [        SU 35      eUS;  a  [        SU 35      e[        X5      u  pUS:X  a  SnU* nUS:X  a
  SnS	US
-   -  n[        5       (       aD  [        US5      n[        R
                  " U UUUUR                  5       UR                  5       U5      $ [        U SSS5        [        USSS5        [        USSS5        [        USSS5        U(       a6  [        US[        [        R                  [        R                  [        4S5        [        U[        5      (       a  [        UR                   SSS/S5        [#        S0 [%        5       D6nUR'                  U R                   S9n	UR'                  SSS9n
U UUUS.nUR                  5       UR                  5       S.n[)        UUUSS9  UR+                  SUXS.US9  U	$ )a   

Graph Learning message passing api.

This api is mainly used in Graph Learning domain, and the main purpose is to reduce intermediate memory
consumption in the process of message passing. Take `x` as the input tensor, we first use `src_index`
to gather the corresponding data, after computing with `y` in different message ops like add/sub/mul/div, then use `dst_index` to
update the corresponding position of output tensor in different reduce ops, like sum, mean, max, or min.
Besides, we can use `out_size` to set necessary output shape.

.. code-block:: text

       Given:

       x = [[0, 2, 3],
            [1, 4, 5],
            [2, 6, 7]]

       y = [1, 1, 1]

       src_index = [0, 1, 2, 0]

       dst_index = [1, 2, 1, 0]

       message_op = "add"

       reduce_op = "sum"

       out_size = None

       Then:

       out = [[1, 3, 4],
              [4, 10, 12],
              [2, 5, 6]]

Args:
    x (Tensor): The input node feature tensor, and the available data type is float32, float64, int32, int64.
                And we support float16 in gpu version.
    y (Tensor): The input edge feature tensor, and the available data type is float32, float64, int32, int64.
                And we support float16 in gpu version.
    src_index (Tensor): An 1-D tensor, and the available data type is int32, int64.
    dst_index (Tensor): An 1-D tensor, and should have the same shape as `src_index`.
                        The available data type is int32, int64.
    message_op (str, optional): Different message ops for x and e, including `add`, `sub`, `mul`, `div`.
    reduce_op (str, optional): Different reduce ops, including `sum`, `mean`, `max`, `min`.
                     Default value is `sum`.
    out_size (int|Tensor, optional): We can set `out_size` to get necessary output shape. If not set or
                                out_size is smaller or equal to 0, then this input will not be used.
                                Otherwise, `out_size` should be equal with or larger than
                                max(dst_index) + 1. Default value is `None`.
    name (str, optional): Name for the operation (optional, default is None).
                          For more information, please refer to :ref:`api_guide_Name`.

Returns:
    - 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 the 0th dimension.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> 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")
        >>> indexes = paddle.to_tensor([[0, 1], [1, 2], [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.]
         [ 2. 5. 6.]]

        >>> 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_size = paddle.max(dst_index) + 1
        >>> out = paddle.geometric.send_ue_recv(x, y, src_index, dst_index, message_op="add", reduce_op="sum", out_size=out_size)
        >>> print(out.numpy())
        [[ 1. 3. 4.]
         [ 4. 10. 12.]]

        >>> 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.]]

r   >message_op should be `add`, `sub`, `mul`, `div`, but received r   r    r   r   r   r         ?-q=graph_send_ue_recvr"   r#   Yr)   r*   r+   r,   r&   r'   r-   Tr/   )r"   rS   r)   r+   )
message_opr1   r2   r6   r9   )send_ue_recv)r=   r   r   r   r   rU   r>   r
   r	   r?   r@   r&   r'   r   rA   r   r.   r   rB   rC   r   rD   )rE   yrF   rG   rT   r1   r,   rH   rI   rJ   rK   r3   r4   s                rL   rU   rU      s7   R 55LZLY
 	
 55NykZ
 	
 1 DAU
BU
1u9 +H6JK""OO
 	
 	!? 		
 	!? 		
 	!{$68L	
 	!{$68L	
 bhh(3$	 h))'"$	 8vx877agg7F== > 
	
 ""	
 %**,"*
 	#(		
 	%8	 	 	
 
rM   c                   US;  a  [        SU 35      e[        X5      u  pUS:X  a  SnU* nUS:X  a
  SnSUS-   -  n[        5       (       a&  [        R                  " XX#UR                  5       5      $ [        S0 [        5       D6n[        U S
/ SQS	5        [        US/ SQS	5        [        USSS/S	5        [        USSS/S	5        UR                  U R                  S9nU UUUS.nSUR                  5       0n	UR                  S	UU	SU0S9  U$ )a	  

Graph Learning message passing api.

This api is mainly used in Graph Learning domain, and the main purpose is to reduce intermediate memory
consumption in the process of message passing. Take `x` as the source node feature tensor, take `y` as
the destination node feature tensor. Then we use `src_index` and `dst_index` to gather the corresponding data,
and then compute the edge features in different message_ops like `add`, `sub`, `mul`, `div`.

.. code-block:: text

       Given:

       x = [[0, 2, 3],
            [1, 4, 5],
            [2, 6, 7]]

       y = [[0, 1, 2],
            [2, 3, 4],
            [4, 5, 6]]

       src_index = [0, 1, 2, 0]

       dst_index = [1, 2, 1, 0]

       message_op = "add"

       Then:

       out = [[2, 5, 7],
              [5, 9, 11],
              [4, 9, 11],
              [0, 3, 5]]

Args:
    x (Tensor): The source node feature tensor, and the available data type is float32, float64, int32, int64. And we support float16 in gpu version.
    y (Tensor): The destination node feature tensor, and the available data type is float32, float64, int32, int64. And we support float16 in gpu version.
    src_index (Tensor): An 1-D tensor, and the available data type is int32, int64.
    dst_index (Tensor): An 1-D tensor, and should have the same shape as `src_index`.
                        The available data type is int32, int64.
    message_op (str): Different message ops for x and y, including `add`, `sub`, `mul` and `div`.
    name (str, optional): Name for the operation (optional, default is None).
                          For more information, please refer to :ref:`api_guide_Name`.

Returns:
    - out (Tensor), the output tensor.

Examples:

    .. code-block:: python

        >>> import paddle

        >>> 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")
        >>> indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32")
        >>> src_index = indexes[:, 0]
        >>> dst_index = indexes[:, 1]
        >>> out = paddle.geometric.send_uv(x, y, src_index, dst_index, message_op="add")
        >>> print(out.numpy())
        [[ 2. 5. 7.]
         [ 5. 9. 11.]
         [ 4. 9. 11.]
         [ 0. 3. 5.]]

r   rO   r   r   r   r   rP   rQ   graph_send_uvrE   )r&   r'   r$   r%   r(   rV   rF   r&   r'   rG   r-   )rE   rV   rF   rG   rT   rJ   )r:   r3   r4   r;   )rX   )r=   r   r   r   send_uvr>   r   rB   r
   rC   r.   rD   )
rE   rV   rF   rG   rT   rH   rI   rJ   r3   r4   s
             rL   rY   rY     s]   V 55LZLY
 	
 1 DAU
BU
1u9~~aI*:J:J:LMM99 ?		
 	!?		
 	!{Wg$6	
 	!{Wg$6	
 77agg7F ""	
 z//12 CL	 	 	
 
rM   )r   NN)rE   r   rF   r   rG   r   r1   r   r,   int | Tensor | NonerH   
str | Nonereturnr   )r   r   NN)rE   r   rV   r   rF   r   rG   r   rT   r   r1   r   r,   rZ   rH   r[   r\   r   )r   N)rE   r   rV   r   rF   r   rG   r   rT   r   rH   r[   r\   r   )!
__future__r   typingr   r   numpyr@   typing_extensionsr   paddler   paddle.base.data_feederr   r	   r
   paddle.base.frameworkr   paddle.base.layer_helperr   paddle.frameworkr   utilsr   r   r   r   r   __annotations__r   __all__r<   rU   rY    rM   rL   <module>rj      s   # )  '  
 + 0 3  "	Iy  $	J	   !$(XXX X 	X
 "X X X@ # $(HHH H 	H
 H H "H H H` #~~~ ~ 	~
 ~ ~ ~rM   