
    x-jm(                    F   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 d dlmZ erd dlmZ g Z ed	d
dd          	 dd d            Z ed	ddd          	 dd d            Z ed	ddd          	 dd d            Z ed	ddd          	 dd d            ZdS )!    )annotations)TYPE_CHECKING)_C_ops)check_variable_and_dtype)LayerHelper)in_dynamic_or_pir_mode)
deprecated)Tensorz2.4.0zpaddle.geometric.segment_sum   z5paddle.incubate.segment_sum will be removed in future)since	update_tolevelreasonN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.

    Sum the elements of input `data` which with
    the same index in `segment_ids`.
    It computes a tensor such that

    .. math::

        out_i = \sum_{j \in \{segment\_ids_j == i \} } 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.
        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:
       Tensor, the Segment Sum 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.incubate.segment_sum(data, segment_ids)
            >>> print(out)
            Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[4., 4., 4.],
             [4., 5., 6.]])

    SUMXfloat32float64int32int64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         [/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/incubate/tensor/math.pyr    r       s    ^  "4e<<< #?	
 	
 	
 	!'9>	
 	
 	
 77fhh7777dj7II>>TZ>PP
[99j99u%	 	 	
 	
 	
 
    zpaddle.geometric.segment_meanz6paddle.incubate.segment_mean will be removed in futurec                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 )an  
    Segment Mean Operator.

    Ihis operator calculate the mean value of input `data` which
    with the same index in `segment_ids`.
    It computes a tensor such that

    .. math::

        out_i = \mathop{mean}_{j \in \{segment\_ids_j == i \} } 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.
        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:
       Tensor, the Segment Mean 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.incubate.segment_mean(data, segment_ids)
            >>> print(out)
            Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[2., 2., 2.],
             [4., 5., 6.]])

    MEANr   r   r   r   r   segment_meanr!   r#   r$   r'   r(   )r9   r-   r1   s         r5   r9   r9   d   s    b  >"4f===c;^   \#5~   4468844F

3
3$*
3
E
EC:::LLJ
55*556"	     Jr6   zpaddle.geometric.segment_minz5paddle.incubate.segment_min will be removed in futurec                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.

    Calculate the minimum elements of input `data` which with
    the same index in `segment_ids`.
    It computes a tensor such that

    .. math::

        out_i = \min_{j \in \{segment\_ids_j == i \} } 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.
        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:
       Tensor, the minimum 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.incubate.segment_min(data, segment_ids)
            >>> print(out)
            Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[1., 2., 1.],
             [4., 5., 6.]])

    MINr   r   r   r   r   segment_minr!   r#   r$   r'   r(   )r<   r-   r1   s         r5   r<   r<      s    `  ="4e<<<c;^   \#5~   33&((33F

3
3$*
3
E
EC:::LLJ
55*555!	     Jr6   zpaddle.geometric.segment_maxz5paddle.incubate.segment_max will be removed in futurec                x   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.

    Calculate the maximum elements of input `data` which with
    the same index in `segment_ids`.
    It computes a tensor such that

    .. math::

        out_i = \max_{j \in \{segment\_ids_j == i \} } 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.
        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:
       Tensor, the maximum 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.incubate.segment_max(data, segment_ids)
            >>> print(out)
            Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[3., 2., 3.],
             [4., 5., 6.]])

    MAXr   r   r   r   r   segment_maxr!   r#   r$   r'   r(   )r?   r-   )r   r   r   r3   r2   r4   s         r5   r?   r?      s    `  !$U;;
c;^   \#5~   33&((33F

3
3$*
3
E
EC:::LLJ
55*555!	     Jr6   )N)r   r
   r   r
   r   r   r   r
   )
__future__r   typingr   paddler   paddle.base.data_feederr   paddle.base.layer_helperr   paddle.frameworkr   paddle.utilsr	   r
   __all__r    r9   r<   r?    r6   r5   <module>rI      s   # " " " " "                   < < < < < < 0 0 0 0 0 0 3 3 3 3 3 3 # # # # # # 
 
,
B	   ;?< < < < <~ 
-
C	   ;?> > > > >B 
,
B	   ;?= = = = =@ 
,
B	   ;?> > > > > > >r6   