Ë
    ˆ\;j�%  ã                   óX   — d dl mZ d dlmZ d dlmZ d dlmZ g Zd
d„Z	d
d„Z
d
d„Zd
d	„Zy)é    )Ú_C_ops)Úcheck_variable_and_dtype)ÚLayerHelper)Úin_dynamic_or_pir_modeNc                 óP  — t        «       rt        j                  | |d«      S t        | ddd«       t        |ddd«       t	        di t        «       ¤Ž}|j                  | j                  ¬«      }|j                  | 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   ©Údtype©r	   r   ©ÚOutÚ	SummedIdsÚpooltype©ÚtypeÚinputsÚoutputsÚattrs)Úsegment_sum©	r   r   r   r   r   ÚlocalsÚ"create_variable_for_type_inferencer   Ú	append_op©ÚdataÚsegment_idsÚnameÚhelperÚoutÚ
summed_idss         ú^G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/geometric/math.pyr    r       s¼   € ô@ ÔÜ×"Ñ" 4¨°eÓ<Ð<ä ØØØIØô		
ô 	!Ø˜Ð'9¸>ô	
ô Ñ7¬f«hÑ7ˆØ×7Ñ7¸d¿j¹jÐ7ÓIˆØ×>Ñ>ÀTÇZÁZÐ>ÓPˆ
Ø×ÑØØ¨[Ñ9Ø¨jÑ9Ø˜uÐ%ð	 	ô 	
ð ˆ
ó    c                 óP  — t        «       rt        j                  | |d«      S t        | ddd«       t        |ddd«       t	        di t        «       ¤Ž}|j                  | j                  ¬«      }|j                  | 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   r   r   r   r   r   )Úsegment_meanr!   r%   s         r,   r0   r0   P   s¼   € ôD ÔÜ×"Ñ" 4¨°fÓ=Ð=ä ØØØIØô		
ô 	!Ø˜Ð'9¸>ô	
ô Ñ8¬v«xÑ8ˆØ×7Ñ7¸d¿j¹jÐ7ÓIˆØ×>Ñ>ÀTÇZÁZÐ>ÓPˆ
Ø×ÑØØ¨[Ñ9Ø¨jÑ9Ø˜vÐ&ð	 	ô 	
ð ˆ
r-   c                 óP  — t        «       rt        j                  | |d«      S t        | ddd«       t        |ddd«       t	        di t        «       ¤Ž}|j                  | j                  ¬«      }|j                  | 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   r   r   r   r   r   )Úsegment_minr!   r%   s         r,   r3   r3   ‹   ó¼   € ôB ÔÜ×"Ñ" 4¨°eÓ<Ð<ä ØØØIØô		
ô 	!Ø˜Ð'9¸>ô	
ô Ñ7¬f«hÑ7ˆØ×7Ñ7¸d¿j¹jÐ7ÓIˆØ×>Ñ>ÀTÇZÁZÐ>ÓPˆ
Ø×ÑØØ¨[Ñ9Ø¨jÑ9Ø˜uÐ%ð	 	ô 	
ð ˆ
r-   c                 óP  — t        «       rt        j                  | |d«      S t        | ddd«       t        |ddd«       t	        di t        «       ¤Ž}|j                  | j                  ¬«      }|j                  | 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   r   r   r   r   r   )Úsegment_maxr!   r%   s         r,   r7   r7   Å   r4   r-   )N)Úpaddler   Úpaddle.base.data_feederr   Úpaddle.base.layer_helperr   Úpaddle.frameworkr   Ú__all__r    r0   r3   r7   © r-   r,   Ú<module>r>      s/   ðõ Ý <Ý 0Ý 3à
€ó6ór8óv7ôt7r-   