
    /jL                    `    d dl mZ d dlZd dlZd dlmZ d dlmZ 	 d	dZ	 G d de          Z
dS )
    )annotationsN)Base)expectmeanc                   | j         }t          |          dk    rt          d          |j         }|d         }|d         }d }	|pt          j        |t          j        |t          j                  d          }	|8t          j        ||k    d|	                              t          j	                  }	n:|8t          j        ||k    dd                              t          j	                  }	t          |          dk    r/| 
                    ||df          } |
                    |df          }| j         d	         }
t          j        ||
ft          j	                  }t          |          D ]P}t          |
          D ]>}||         |         |k    r*| |         ||         |                  |          ||         |<   ?Q|}t          |          dk    r|
                    |          }|	4|	|z  }|d
k    r)|                                |	                                z  S |d
k    rt          j        |          }n|dk    rt          j        |          }|S )N   zUnsupported shaper   )dtypeclip)mode      r   sum)shapelenRuntimeErrornptakearrayint32whereastypefloat32reshapezerosranger   r   )inputtargetweight	reductionignore_indexinput_shapetarget_shapeNCgather_weightDneg_gather_element_inputidlosss                  z/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/onnx/backend/test/case/node/negativeloglikelihoodloss.py$compute_negative_log_likelihood_lossr-      se    +K
;1.///<LAAAA M
 rx(H(H(HvVVV #HV|%;QNNUUj V  M 
	!<!7A>>EEBJEWW ;1q!Rj))B(( 	AA!xAbjAAA1XX L Lq 	L 	LAay||++27(6!9Q<2H2K1K(+A.	L $D ;1||L))  t#88:: 1 1 3 333Fwt}}	e		vd||K    c                     e Zd Zedd            Zedd            Zedd            Zedd            Zedd            Zedd            Z	edd	            Z
edd
            Zedd            Zedd            Zedd            Zedd            Zedd            Zedd            Zedd            Zedd            Zedd            Zedd            ZdS )NegativeLogLikelihoodLossreturnNonec                    d} t           j                            dddgdg|           }d\  }}t          j                            d           t          j                            ||                              t          j                  }t          j        	                    d||f	                              t          j
                  }t          ||d | 
          }t          |||g|gd           d S )Nnoner0   r   r   r+   inputsoutputsr    r      r   highsizer   r    test_nllloss_NCr6   r7   nameonnxhelper	make_noder   randomseedrandr   r   randintint64r-   r   )r    noder$   r%   r   r   negative_log_likelihood_losss          r,   export_input_shape_is_NCz2NegativeLogLikelihoodLoss.export_input_shape_is_NCN   s    	{$$'X&H	 % 
 
 1
	q	q!$$++BJ77""11A4"88??II'K6$)(
 (
 (
$ 	6?12"		
 	
 	
 	
 	
 	
r.   c                    d} t           j                            dddgdg|           }d\  }}}}t          j                            d           t          j                            ||||                              t          j                  }t          j        	                    d||||f	                              t          j
                  }t          ||d | 
          }t          |||g|gd           d S )Nr4   r0   r   r   r+   r5   r   r9      rO   r   r:   r=   test_nllloss_NCd1d2r?   rA   	r    rJ   r$   r%   dim1dim2r   r   rK   s	            r,   export_input_shape_is_NCd1d2z6NegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2h   s	   	{$$'X&H	 % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT'K6$)(
 (
 (
$ 	6?12&		
 	
 	
 	
 	
 	
r.   c                    d} t           j                            dddgdg|           }d\  }}}}t          j                            d           t          j                            ||||                              t          j                  }t          j        	                    d||||f	                              t          j
                  }t          ||d | 
          }t          |||g|gd           d S )Nr   r0   r   r   r+   r5   rN   r   r:   r=   "test_nllloss_NCd1d2_reduction_meanr?   rA   rQ   s	            r,   +export_input_shape_is_NCd1d2_reduction_meanzENegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2_reduction_mean   s	   	{$$'X&H	 % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT'K6$)(
 (
 (
$ 	6?125		
 	
 	
 	
 	
 	
r.   c                    d} t           j                            dddgdg|           }d\  }}}}t          j                            d           t          j                            ||||                              t          j                  }t          j        	                    d||||f	                              t          j
                  }t          ||d | 
          }t          |||g|gd           d S )Nr   r0   r   r   r+   r5   rN   r   r:   r=   !test_nllloss_NCd1d2_reduction_sumr?   rA   rQ   s	            r,   *export_input_shape_is_NCd1d2_reduction_sumzDNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2_reduction_sum   s	   	{$$'X&H	 % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT'K6$)(
 (
 (
$ 	6?124		
 	
 	
 	
 	
 	
r.   c                 p   d} t           j                            dg ddg|           }d\  }}}}t          j                            d           t          j                            ||||                              t          j                  }t          j        	                    d||||f                              t          j
                  }t          j                            |                              t          j                  }t          |||| 	          }	t          ||||g|	gd
           d S )Nr4   r0   r   r   r   r+   r5   rN   r   r:   r=   test_nllloss_NCd1d2_with_weightr?   rA   
r    rJ   r$   r%   rR   rS   r   r   r   rK   s
             r,   (export_input_shape_is_NCd1d2_with_weightzBNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2_with_weight   s0   	{$$'000H	 % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT""))"*55'K6&I(
 (
 (
$ 	66*122		
 	
 	
 	
 	
 	
r.   c                 p   d} t           j                            dg ddg|           }d\  }}}}t          j                            d           t          j                            ||||                              t          j                  }t          j        	                    d||||f                              t          j
                  }t          j                            |                              t          j                  }t          |||| 	          }	t          ||||g|	gd
           d S )Nr   r0   r\   r+   r5   rN   r   r:   r=   .test_nllloss_NCd1d2_with_weight_reduction_meanr?   rA   r^   s
             r,   7export_input_shape_is_NCd1d2_with_weight_reduction_meanzQNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2_with_weight_reduction_mean   s0   	{$$'000H	 % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT""))"*55'K6&I(
 (
 (
$ 	66*12A		
 	
 	
 	
 	
 	
r.   c                 p   d} t           j                            dg ddg|           }d\  }}}}t          j                            d           t          j                            ||||                              t          j                  }t          j        	                    d||||f                              t          j
                  }t          j                            |                              t          j                  }t          |||| 	          }	t          ||||g|	gd
           d S )Nr   r0   r\   r+   r5   rN   r   r:   r=   -test_nllloss_NCd1d2_with_weight_reduction_sumr?   rA   r^   s
             r,   6export_input_shape_is_NCd1d2_with_weight_reduction_sumzPNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2_with_weight_reduction_sum   s0   	{$$'000H	 % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT""))"*55'K6&I(
 (
 (
$ 	66*12@		
 	
 	
 	
 	
 	
r.   c                    d} t          j        d          }t          j                            dg ddg| |          }d\  }}}}t           j                            d           t           j                            ||||                              t           j	                  }t           j        
                    d||||f                              t           j                  }t          j        d          |d         d         d<   t           j                            |                              t           j	                  }	t          |||	| |	          }
t          ||||	g|
gd
           d S )Nr   r   r0   r\   r+   r6   r7   r    r!   rN   r:   r   r    r!   0test_nllloss_NCd1d2_with_weight_reduction_sum_iir?   r   rI   rB   rC   rD   rE   rF   rG   r   r   rH   r-   r   )r    r!   rJ   r$   r%   rR   rS   r   r   r   rK   s              r,   9export_input_shape_is_NCd1d2_with_weight_reduction_sum_iizSNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2_with_weight_reduction_sum_ii  s[   	x{{{$$'000H% % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT(1++q	!Q""))"*55'K6&IL(
 (
 (
$ 	66*12C		
 	
 	
 	
 	
 	
r.   c                 f   d} t          j        d          }t          j                            dddgdg| |          }d\  }}}}t           j                            d	           t           j                            ||||                              t           j	                  }t           j        
                    d	||||f
                              t           j                  }t          j        d          |d	         d	         d	<   t          ||| |          }	t          |||g|	gd           d S )Nr   r   r0   r   r   r+   rg   rN   r   r:   r    r!   /test_nllloss_NCd1d2_no_weight_reduction_mean_iir?   rj   )
r    r!   rJ   r$   r%   rR   rS   r   r   rK   s
             r,   8export_input_shape_is_NCd1d2_no_weight_reduction_mean_iizRNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2_no_weight_reduction_mean_ii%  s2   	x{{{$$'X&H% % 
 
 &1dD
	q	q!T40077
CC""11AtT?"CCJJ28TT(1++q	!Q'K6Y\(
 (
 (
$ 	6?12B		
 	
 	
 	
 	
 	
r.   c                    d} t           j                            dddgdg|           }d\  }}}t          j                            d           t          j                            |||                              t          j                  }t          j        	                    d|||f	                              t          j
                  }t          ||d | 
          }t          |||g|gd           d S )Nr   r0   r   r   r+   r5   r   r9   r   r   r:   r=   test_nllloss_NCd1r?   rA   )r    rJ   r$   r%   d1r   r   rK   s           r,   export_input_shape_is_NCd1z4NegativeLogLikelihoodLoss.export_input_shape_is_NCd1B  s   	{$$'X&H	 % 
 
 1b
	q	q!R((//
;;""11Ar7";;BB28LL'K6$)(
 (
 (
$ 	6?12$		
 	
 	
 	
 	
 	
r.   c                 j   d} t           j                            dg ddg|           }d\  }}}t          j                            d           t          j                            |||                              t          j                  }t          j        	                    d|||f                              t          j
                  }t          j                            |                              t          j                  }t          |||| 	          }t          ||||g|gd
           d S )Nr   r0   r\   r+   r5   rq   r   r:   r=   test_nllloss_NCd1_weightr?   rA   )	r    rJ   r$   r%   rs   r   r   r   rK   s	            r,   !export_input_shape_is_NCd1_weightz;NegativeLogLikelihoodLoss.export_input_shape_is_NCd1_weight\  s)   	{$$'000H	 % 
 
 1b
	q	q!R((//
;;""11Ar7";;BB28LL""))"*55'K6&I(
 (
 (
$ 	66*12+		
 	
 	
 	
 	
 	
r.   c                 V   d} t          j        d          }t          j                            dddgdg| |          }d\  }}}t           j                            d	           t           j                            |||                              t           j	                  }t           j        
                    d	|||f
                              t           j                  }t          j        d          |d	         d	<   t          ||d | |          }t          |||g|gd           d S )Nr   r   r0   r   r   r+   rg   rq   r   r:   rh   test_nllloss_NCd1_iir?   rj   )	r    r!   rJ   r$   r%   rs   r   r   rK   s	            r,   export_input_shape_is_NCd1_iiz7NegativeLogLikelihoodLoss.export_input_shape_is_NCd1_iiw  s)   	x{{{$$'X&H% % 
 
 1b
	q	q!R((//
;;""11Ar7";;BB28LLx{{q	!'K6$),(
 (
 (
$ 	6?12'		
 	
 	
 	
 	
 	
r.   c                    d} t          j        d          }t          j                            dg ddg| |          }d\  }}}t           j                            d           t           j                            |||                              t           j	                  }t           j        
                    d|||f	                              t           j                  }t          j        d          |d         d<   t           j                            |                              t           j	                  }t          |||| |
          }	t          ||||g|	gd           d S )Nr   r   r0   r\   r+   rg   rq   r   r:   rh   test_nllloss_NCd1_weight_iir?   rj   )
r    r!   rJ   r$   r%   rs   r   r   r   rK   s
             r,   $export_input_shape_is_NCd1_weight_iiz>NegativeLogLikelihoodLoss.export_input_shape_is_NCd1_weight_ii  sP   	x{{{$$'000H% % 
 
 1b
	q	q!R((//
;;""11Ar7";;BB28LLx{{q	!""))"*55'K6&IL(
 (
 (
$ 	66*12.		
 	
 	
 	
 	
 	
r.   c            
        d} t           j                            dg ddg|           }d\  }}}}}}}t          j                            d           t          j                            |||||||                              t          j                  }	t          j        	                    d|||||||f                              t          j
                  }
t          j                            |                              t          j                  }t          |	|
|| 	          }t          ||	|
|g|gd
           d S )Nr   r0   r\   r+   r5   r   r9   rO   rO   r9   r      r   r:   r=   %test_nllloss_NCd1d2d3d4d5_mean_weightr?   rA   )r    rJ   r$   r%   rR   rS   dim3dim4dim5r   r   r   rK   s                r,   .export_input_shape_is_NCd1d2d3d4d5_mean_weightzHNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2d3d4d5_mean_weight  sO   	{$$'000H	 % 
 
 .A*1dD$d
	q	q!T4tTBBII"*UU""AQdD$= # 
 

&

 	 ""))"*55'K6&I(
 (
 (
$ 	66*128		
 	
 	
 	
 	
 	
r.   c            
        d} t           j                            dddgdg|           }d\  }}}}}}}t          j                            d           t          j                            |||||||                              t          j                  }	t          j        	                    d|||||||f	                              t          j
                  }
t          |	|
| 
          }t          ||	|
g|gd           d S )Nr4   r0   r   r   r+   r5   r   r   r:   )r    (test_nllloss_NCd1d2d3d4d5_none_no_weightr?   rA   )r    rJ   r$   r%   rR   rS   r   r   r   r   r   rK   s               r,   1export_input_shape_is_NCd1d2d3d4d5_none_no_weightzKNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2d3d4d5_none_no_weight  s'   	{$$'X&H	 % 
 
 .A*1dD$d
	q	q!T4tTBBII"*UU""AQdD$= # 
 

&

 	 (L6Y(
 (
 (
$ 	6?12;		
 	
 	
 	
 	
 	
r.   c                    d} t          j        d          }t          j                            dg ddg| |          }d\  }}}t           j                            d           t           j                            |||                              t           j	                  }t           j        
                    d|||f	                              t           j                  }d|d         d<   t           j                            |                              t           j	                  }t          |||| |
          }	t          ||||g|	gd           d S )Nr   r   r0   r\   r+   rg   )r   r9   rO   r   r:   rh   )test_nllloss_NCd1_mean_weight_negative_iir?   rj   )
r    r!   rJ   r$   r%   rR   r   r   r   rK   s
             r,   2export_input_shape_is_NCd1_mean_weight_negative_iizLNegativeLogLikelihoodLoss.export_input_shape_is_NCd1_mean_weight_negative_ii  sH   	x||{$$'000H% % 
 
 
1d
	q	q!T**11"*==""11At9"==DDRXNNq	!""))"*55'K6&IL(
 (
 (
$ 	66*12<		
 	
 	
 	
 	
 	
r.   c                 T   d} t          j        d          }t          j                            dddgdg| |          }d\  }}}}}t           j                            d	           t           j                            |||||                              t           j	                  }t           j        
                    d	|||||f
                              t           j                  }	d|	d	         d	         d	         d	<   t          ||	| |          }
t          |||	g|
gd           d S )Nr4   r0   r   r   r+   rg   )r   r9   rO   rO   r9   r   r:   rm   0test_nllloss_NCd1d2d3_none_no_weight_negative_iir?   rj   )r    r!   rJ   r$   r%   rR   rS   r   r   r   rK   s              r,   9export_input_shape_is_NCd1d2d3_none_no_weight_negative_iizSNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2d3_none_no_weight_negative_ii  s=   	x||{$$'X&H% % 
 
 "/1dD$
	q	q!T466==bjII""11AtT43H"IIPPH
 
  q	!Q'K6Y\(
 (
 (
$ 	6?12C		
 	
 	
 	
 	
 	
r.   c                    d} t          j        d          }t          j                            dg ddg| |          }d\  }}t           j                            d           t           j                            ||                              t           j	                  }t           j        
                    d||	                              t           j                  }d|d<   t           j                            |                              t           j	                  }t          |||| |
          }t          ||||g|gd           d S )Nr   
   r0   r\   r+   rg   r8   r   r:   rh   (test_nllloss_NCd1d2d3_sum_weight_high_iir?   rj   )	r    r!   rJ   r$   r%   r   r   r   rK   s	            r,   1export_input_shape_is_NCd1d2d3_sum_weight_high_iizKNegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2d3_sum_weight_high_ii,  s<   	x||{$$'000H% % 
 
 1
	q	q!$$++BJ77""11A"77>>rxHHq	""))"*55'K6&IL(
 (
 (
$ 	66*12;		
 	
 	
 	
 	
 	
r.   N)r1   r2   )__name__
__module____qualname__staticmethodrL   rT   rW   rZ   r_   rb   re   rk   ro   rt   rw   rz   r}   r   r   r   r   r    r.   r,   r0   r0   M   sR       
 
 
 \
2 
 
 
 \
2 
 
 
 \
2 
 
 
 \
2 
 
 
 \
4 
 
 
 \
4 
 
 
 \
4 
 
 
 \
: 
 
 
 \
8 
 
 
 \
2 
 
 
 \
4 
 
 
 \
8 
 
 
 \
: 
 
 
 \
: 
 
 
 \
8 
 
 
 \
< 
 
 
 \
> 
 
 
 \
 
 
r.   r0   )Nr   N)
__future__r   numpyr   rB   onnx.backend.test.case.baser   onnx.backend.test.case.noder   r-   r0   r   r.   r,   <module>r      s    # " " " " "      , , , , , , . . . . . . @D= = = =@|
 |
 |
 |
 |
 |
 |
 |
 |
 |
r.   