
    x-j                     T    d dl Z d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d Z
ddZdS )	    N)_C_ops)convert_dtype)convert_np_dtype_to_dtype_corein_dynamic_or_pir_mode)LayerHelperc                 ~   | j         dvrt          d| j                    | j        t          j        t          j        fvrt          d| j                   |ddt          j        t          j        fvrt          d| d          ||k     rt          d| d	| d
          |                                                                 dk    rt          j        ||z
  g|          S | j         dk    r*| 	                    dg          
                    d          } n | j         dk    r| 
                    d          } |                                                                 }|                                                                 }|dk     rt          d|           t          |dz   |          }t          j        | j        d         |g| j                  }|                    | t          j        d| j                  dd          }t          j        |d                              |          }|||         S )a4  
    A mathematically equivalent implementation of int_bincount using scatter and sum

    Args:
        x (Tensor): A 1D or 2D int64 tensor containing category indices.
        low (int): The minimum possible category index (usually 0).
        high (int): One past the maximum category index (i.e., number of categories).
        dtype (paddle.dtype): Data type of the output tensor (e.g., paddle.int64).

    Returns:
        Tensor: A 1D tensor of shape [high - low], where each element is
                the count of occurrences of that category in `x`.
    )r         z.x must be a 0D, 1D or 2D tensor, but got ndim=z(x.dtype must be int32 or int64, but got int32int64z+dtype must be 'int32' or 'int64', but got ''z'high' (z*) must be greater than or equal to 'low' ()r   dtyper
   z0Elements of x must be non-negative, but got min=g      ?add)axisreduce)r   )ndim
ValueErrorr   paddler   r   numelitemzerosreshape	unsqueezeminmaxshapeput_along_axis	to_tensorsumcast)	xlowhighr   x_minx_maxmax_valmaskcounts	            j/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/incubate/nn/functional/int_bincount.pymath_int_bincountr.      s1    	vYEQVEE
 
 	
 	wv|V\222MAGMMNNNWgv|V\BBBOuOOOPPPczzMtMMsMMM
 
 	
 	wwyy~~1|TCZL6666v{{IIrdOO%%a((	
1KKNNEEGGLLNNEEEGGLLNNEqyyFuFF
 
 	
 %!)T""G<W-QW===D	6Cqw///a   D Jt!$$$))%00ET?    c           	         t                      rvt          |t          j        j        t          j        f          st          |          }t          j                    rt          | |||          S t          j        | |||          S t          di t                      }||n| j        }|                    |          }t!          |          }|                    dd| id|i|||d           |S )Nint_bincountr   r%   y)r&   r'   r   )typeinputsoutputsattrs)r1   )r   
isinstancer   VarDescVarTypeDataTyper   r   is_compiled_with_xpur.   r   r1   r   localsr   "create_variable_for_type_inferencer   	append_op)	r%   r&   r'   r   namehelper	out_dtyper2   
dtype_attrs	            r-   r1   r1   R   s	    <%$,"6!FGG 	6.u55E&(( 	<$QT5999&q#tU;;;4468844F*I11	1BBAy))J
Qxa
 
	  	 	 	 Hr/   )NN)r   r   paddle.base.data_feederr   paddle.base.frameworkr   r   r   paddle.base.layer_helperr   r.   r1    r/   r-   <module>rG      s           1 1 1 1 1 1         
 1 0 0 0 0 05 5 5p     r/   