o
    Ne%                     @   sl   d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	m
Z
 g ZdddZddd	Zdd
dZdddZdS )    )LayerHelper_non_static_mode)check_variable_and_dtype)_C_ops_legacy_C_ops)_in_legacy_dygraphin_dygraph_modeNc                 C      t  rt| |dd S t rt| |dd\}}|S t| ddd t|ddd tdi t }|j| j	d
}|j| j	d
}|j
d| |d||dddid |S )at  
    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)
            #Outputs: [[4., 4., 4.], [4., 5., 6.]]

    ZSUMr   pooltypeXZfloat32Zfloat64int32int64Zfloat16segment_pool
SegmentIdsr   r   segment_sumdtyper   r   ZOutZ	SummedIdstypeZinputsZoutputsattrsN)r   r   r   r   r   r   r   r   localsZ"create_variable_for_type_inferencer   Z	append_opdataZsegment_idsnameouttmphelperZ
summed_ids r"   ED:\Projects\ConvertPro\env\Lib\site-packages\paddle/geometric/math.pyr      s4   r   c                 C   r	   )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)
            #Outputs: [[2., 2., 2.], [4., 5., 6.]]

    ZMEANr   r
   r   r   r   r   r   segment_meanr   r   r   r   N)r$   r   r   r"   r"   r#   r$   S   s4    r$   c                 C   r	   )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)
            #Outputs:  [[1., 2., 1.], [4., 5., 6.]]

    ZMINr   r
   r   r   r   r   r   segment_minr   r   r   r   N)r%   r   r   r"   r"   r#   r%      4   r%   c                 C   r	   )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)
            #Outputs: [[3., 2., 3.], [4., 5., 6.]]

    MAXr   r
   r   r   r   r   r   segment_maxr   r   r   r   N)r(   r   r   r"   r"   r#   r(      r&   r(   )N)Zpaddle.fluid.layer_helperr   r   Zpaddle.fluid.data_feederr   Zpaddler   r   Zpaddle.fluid.frameworkr   r   __all__r   r$   r%   r(   r"   r"   r"   r#   <module>   s   

<
>=