§
    z”jÏ%  ã                  ó’   — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ erd dlmZ g Z	 ddd„Z	 ddd„Z	 ddd„Z	 ddd„ZdS )é    )Úannotations)ÚTYPE_CHECKING)Ú_C_ops)Úcheck_variable_and_dtype)ÚLayerHelper)Úin_dynamic_or_pir_mode)ÚTensorNÚdatar	   Úsegment_idsÚnameú
str | NoneÚreturnc                ót  — t          ¦   «         rt          j        | |d¦  «        S t          | ddd¦  «         t          |ddd¦  «         t	          di t          ¦   «         ¤Ž}|                     | j        ¬¦  «        }|                     | j        ¬¦  «        }|                     d| |d	œ||d
œddi¬¦  «         |S )a¥  
    Segment Sum Operator.

    This operator sums the elements of input `data` which with
    the same index in `segment_ids`.
    It computes a tensor such that $out_i = \\sum_{j} data_{j}$
    where sum is over j such that `segment_ids[j] == i`.

    Args:
        data (Tensor): A tensor, available data type float32, float64, int32, int64, float16.
        segment_ids (Tensor): A 1-D tensor, which have the same size
                            with the first dimension of input data.
                            Available data type is int32, int64.
        name (str, optional): Name for the operation (optional, default is None).
                            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        - output (Tensor), the reduced result.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> 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')
            >>> out = paddle.geometric.segment_sum(data, segment_ids)
            >>> print(out.numpy())
            [[4. 4. 4.]
             [4. 5. 6.]]

    ÚSUMÚX©Úfloat32Úfloat64Úint32Úint64Úfloat16Úuint16Úsegment_poolÚ
SegmentIds©r   r   Úsegment_sum©Údtype©r   r   ©ÚOutÚ	SummedIdsÚpooltype©ÚtypeÚinputsÚoutputsÚattrsN)r   ©	r   r   r   r   r   ÚlocalsÚ"create_variable_for_type_inferencer   Ú	append_op©r
   r   r   ÚhelperÚoutÚ
summed_idss         úe/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/paddle/geometric/math.pyr   r      sò   € õD ÑÔð ÝÔ" 4¨°eÑ<Ô<Ð<å ØØØIØñ		
ô 	
ð 	
õ 	!Ø˜Ð'9¸>ñ	
ô 	
ð 	
õ Ð7Ð7­f©h¬hÐ7Ð7ˆØ×7Ò7¸d¼jÐ7ÑIÔIˆØ×>Ò>ÀTÄZÐ>ÑPÔPˆ
Ø×ÒØØ¨[Ð9Ð9Ø¨jÐ9Ð9Ø˜uÐ%ð	 	ñ 	
ô 	
ð 	
ð ˆ
ó    c                ót  — t          ¦   «         rt          j        | |d¦  «        S t          | ddd¦  «         t          |ddd¦  «         t	          di t          ¦   «         ¤Ž}|                     | j        ¬¦  «        }|                     | j        ¬¦  «        }|                     d| |d	œ||d
œddi¬¦  «         |S )aü  
    Segment mean Operator.

    This operator calculate the mean value of input `data` which
    with the same index in `segment_ids`.
    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
    of all index 'segment_ids[j] == i'.

    Args:
        data (tensor): a tensor, available data type float32, float64, int32, int64, float16.
        segment_ids (tensor): a 1-d tensor, which have the same size
                            with the first dimension of input data.
                            available data type is int32, int64.
        name (str, optional): Name for the operation (optional, default is None).
                            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        - output (Tensor), the reduced result.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> 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')
            >>> out = paddle.geometric.segment_mean(data, segment_ids)
            >>> print(out.numpy())
            [[2. 2. 2.]
             [4. 5. 6.]]

    ÚMEANr   r   r   r   r   Úsegment_meanr   r   r    r#   r$   N)r5   r)   r-   s         r1   r5   r5   X   sò   € õH ÑÔð ÝÔ" 4¨°fÑ=Ô=Ð=å ØØØIØñ		
ô 	
ð 	
õ 	!Ø˜Ð'9¸>ñ	
ô 	
ð 	
õ Ð8Ð8­v©x¬xÐ8Ð8ˆØ×7Ò7¸d¼jÐ7ÑIÔIˆØ×>Ò>ÀTÄZÐ>ÑPÔPˆ
Ø×ÒØØ¨[Ð9Ð9Ø¨jÐ9Ð9Ø˜vÐ&ð	 	ñ 	
ô 	
ð 	
ð ˆ
r2   c                ót  — t          ¦   «         rt          j        | |d¦  «        S t          | ddd¦  «         t          |ddd¦  «         t	          di t          ¦   «         ¤Ž}|                     | j        ¬¦  «        }|                     | j        ¬¦  «        }|                     d| |d	œ||d
œddi¬¦  «         |S )a²  
    Segment min operator.

    This operator calculate the minimum elements of input `data` which with
    the same index in `segment_ids`.
    It computes a tensor such that $out_i = \\min_{j} data_{j}$
    where min is over j such that `segment_ids[j] == i`.

    Args:
        data (tensor): a tensor, available data type float32, float64, int32, int64, float16.
        segment_ids (tensor): a 1-d tensor, which have the same size
                            with the first dimension of input data.
                            available data type is int32, int64.
        name (str, optional): Name for the operation (optional, default is None).
                            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        - output (Tensor), the reduced result.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> 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')
            >>> out = paddle.geometric.segment_min(data, segment_ids)
            >>> print(out.numpy())
            [[1. 2. 1.]
             [4. 5. 6.]]

    ÚMINr   r   r   r   r   Úsegment_minr   r   r    r#   r$   N)r8   r)   r-   s         r1   r8   r8   •   óò   € õF ÑÔð ÝÔ" 4¨°eÑ<Ô<Ð<å ØØØIØñ		
ô 	
ð 	
õ 	!Ø˜Ð'9¸>ñ	
ô 	
ð 	
õ Ð7Ð7­f©h¬hÐ7Ð7ˆØ×7Ò7¸d¼jÐ7ÑIÔIˆØ×>Ò>ÀTÄZÐ>ÑPÔPˆ
Ø×ÒØØ¨[Ð9Ð9Ø¨jÐ9Ð9Ø˜uÐ%ð	 	ñ 	
ô 	
ð 	
ð ˆ
r2   c                ót  — t          ¦   «         rt          j        | |d¦  «        S t          | ddd¦  «         t          |ddd¦  «         t	          di t          ¦   «         ¤Ž}|                     | j        ¬¦  «        }|                     | j        ¬¦  «        }|                     d| |d	œ||d
œddi¬¦  «         |S )a²  
    Segment max operator.

    This operator calculate the maximum elements of input `data` which with
    the same index in `segment_ids`.
    It computes a tensor such that $out_i = \\max_{j} data_{j}$
    where max is over j such that `segment_ids[j] == i`.

    Args:
        data (tensor): a tensor, available data type float32, float64, int32, int64, float16.
        segment_ids (tensor): a 1-d tensor, which have the same size
                            with the first dimension of input data.
                            available data type is int32, int64.
        name (str, optional): Name for the operation (optional, default is None).
                            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        - output (Tensor), the reduced result.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> 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')
            >>> out = paddle.geometric.segment_max(data, segment_ids)
            >>> print(out.numpy())
            [[3. 2. 3.]
             [4. 5. 6.]]

    ÚMAXr   r   r   r   r   Úsegment_maxr   r   r    r#   r$   N)r<   r)   r-   s         r1   r<   r<   Ñ   r9   r2   )N)r
   r	   r   r	   r   r   r   r	   )Ú
__future__r   Útypingr   Úpaddler   Úpaddle.base.data_feederr   Úpaddle.base.layer_helperr   Úpaddle.frameworkr   r	   Ú__all__r   r5   r8   r<   © r2   r1   ú<module>rE      s  ðð #Ð "Ð "Ð "Ð "Ð "à  Ð  Ð  Ð  Ð  Ð  à Ð Ð Ð Ð Ð Ø <Ð <Ð <Ð <Ð <Ð <Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3àð ØÐÐÐÐÐà
€ð ;?ð8ð 8ð 8ð 8ð 8ðx ;?ð:ð :ð :ð :ð :ð| ;?ð9ð 9ð 9ð 9ð 9ðz ;?ð9ð 9ð 9ð 9ð 9ð 9ð 9r2   