
    ϑi                     T    S SK r S SK Jr  S SKJr  S SKJrJrJr  S SKJ	r	  S r
SS jrg)	    N)_C_ops)convert_dtype)convert_np_dtype_to_dtype_corein_dynamic_or_pir_mode)LayerHelperc                 X   U R                   S;  a  [        SU R                    35      eU R                  [        R                  [        R
                  4;  a  [        SU R                   35      eUSS[        R                  [        R
                  4;  a  [        SU S35      eX!:  a  [        SU S	U S
35      eU R                  5       R                  5       S:X  a  [        R                  " X!-
  /US9$ U R                   S:X  a"  U R                  S/5      R                  S5      n O!U R                   S:X  a  U R                  S5      n U R                  5       R                  5       nU R                  5       R                  5       nUS:  a  [        SU 35      e[        US-   U5      n[        R                  " U R                  S   U/U R                  S9nUR                  U [        R                  " SU R                  S9SSS9n[        R                   " USS9R#                  U5      nXU $ )a  
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.13/site-packages/paddle/incubate/nn/functional/int_bincount.pymath_int_bincountr.      s    	vvY<QVVHE
 	
 	wwv||V\\22CAGG9MNNWgv||V\\BBFugQOPPztfFse1M
 	
 	wwy~~1||TZL66vv{IIrdO%%a(	
1KKNEEGLLNEEEGLLNEqy>ugF
 	
 %!)T"G<<W-QWW=D	6Cqww/a  D JJt!$))%0ET?    c           	         [        5       (       a  [        U[        R                  R                  [        R
                  45      (       d  [        U5      n[        R                  " 5       (       a  [        XX#5      $ [        R                  " XX#5      $ [        S0 [        5       D6nUb  UOU R                  nUR                  US9n[!        U5      nUR#                  SSU 0SU0UUUS.S9  U$ )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"6!FGG.u5E&&(($QT99&&qt;;4684F*I11	1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5pr/   