
    NgL                     R    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 )	    N)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|
                    |          }|	6|	|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                  q/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/backend/test/case/node/negativeloglikelihoodloss.py$compute_negative_log_likelihood_lossr,      sg   +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3DK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returnNc                     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noner/   r   r   r*   inputsoutputsr   r      r   highsizer   r   test_nllloss_NCr4   r5   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_NCL   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 )Nr2   r/   r   r   r*   r3   r   r7      rM   r   r8   r;   test_nllloss_NCd1d2r=   r?   	r   rH   r#   r$   dim1dim2r   r   rI   s	            r+   export_input_shape_is_NCd1d2z6NegativeLogLikelihoodLoss.export_input_shape_is_NCd1d2f   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   r/   r   r   r*   r3   rL   r   r8   r;   "test_nllloss_NCd1d2_reduction_meanr=   r?   rO   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   r/   r   r   r*   r3   rL   r   r8   r;   !test_nllloss_NCd1d2_reduction_sumr=   r?   rO   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 )Nr2   r/   r   r   r   r*   r3   rL   r   r8   r;   test_nllloss_NCd1d2_with_weightr=   r?   
r   rH   r#   r$   rP   rQ   r   r   r   rI   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   r/   rZ   r*   r3   rL   r   r8   r;   .test_nllloss_NCd1d2_with_weight_reduction_meanr=   r?   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   r/   rZ   r*   r3   rL   r   r8   r;   -test_nllloss_NCd1d2_with_weight_reduction_sumr=   r?   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   r/   rZ   r*   r4   r5   r   r    rL   r8   r   r   r    0test_nllloss_NCd1d2_with_weight_reduction_sum_iir=   r   rG   r@   rA   rB   rC   rD   rE   r   r   rF   r,   r   )r   r    rH   r#   r$   rP   rQ   r   r   r   rI   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   r/   r   r   r*   re   rL   r   r8   r   r    /test_nllloss_NCd1d2_no_weight_reduction_mean_iir=   rh   )
r   r    rH   r#   r$   rP   rQ   r   r   rI   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   r/   r   r   r*   r3   r   r7   r   r   r8   r;   test_nllloss_NCd1r=   r?   )r   rH   r#   r$   d1r   r   rI   s           r+   export_input_shape_is_NCd1z4NegativeLogLikelihoodLoss.export_input_shape_is_NCd1@  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   r/   rZ   r*   r3   ro   r   r8   r;   test_nllloss_NCd1_weightr=   r?   )	r   rH   r#   r$   rq   r   r   r   rI   s	            r+   !export_input_shape_is_NCd1_weightz;NegativeLogLikelihoodLoss.export_input_shape_is_NCd1_weightZ  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   r/   r   r   r*   re   ro   r   r8   rf   test_nllloss_NCd1_iir=   rh   )	r   r    rH   r#   r$   rq   r   r   rI   s	            r+   export_input_shape_is_NCd1_iiz7NegativeLogLikelihoodLoss.export_input_shape_is_NCd1_iiu  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   r/   rZ   r*   re   ro   r   r8   rf   test_nllloss_NCd1_weight_iir=   rh   )
r   r    rH   r#   r$   rq   r   r   r   rI   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   r/   rZ   r*   r3   r   r7   rM   rM   r7   r      r   r8   r;   %test_nllloss_NCd1d2d3d4d5_mean_weightr=   r?   )r   rH   r#   r$   rP   rQ   dim3dim4dim5r   r   r   rI   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 )Nr2   r/   r   r   r*   r3   r}   r   r8   )r   (test_nllloss_NCd1d2d3d4d5_none_no_weightr=   r?   )r   rH   r#   r$   rP   rQ   r   r   r   r   r   rI   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   r/   rZ   r*   re   )r   r7   rM   r   r8   rf   )test_nllloss_NCd1_mean_weight_negative_iir=   rh   )
r   r    rH   r#   r$   rP   r   r   r   rI   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 )Nr2   r/   r   r   r*   re   )r   r7   rM   rM   r7   r   r8   rk   0test_nllloss_NCd1d2d3_none_no_weight_negative_iir=   rh   )r   r    rH   r#   r$   rP   rQ   r   r   r   rI   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   
   r/   rZ   r*   re   r6   r   r8   rf   (test_nllloss_NCd1d2d3_sum_weight_high_iir=   rh   )	r   r    rH   r#   r$   r   r   r   rI   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-   )r0   N)__name__
__module____qualname__staticmethodrJ   rR   rU   rX   r]   r`   rc   ri   rm   rr   ru   rx   r{   r   r   r   r   r    r-   r+   r/   r/   K   sR       
 
 
 \
2 
 
 
 \
2 
 
 
 \
2 
 
 
 \
2 
 
 
 \
4 
 
 
 \
4 
 
 
 \
4 
 
 
 \
: 
 
 
 \
8 
 
 
 \
2 
 
 
 \
4 
 
 
 \
8 
 
 
 \
: 
 
 
 \
: 
 
 
 \
8 
 
 
 \
< 
 
 
 \
> 
 
 
 \
 
 
r-   r/   )Nr   N)	numpyr   r@   onnx.backend.test.case.baser   onnx.backend.test.case.noder   r,   r/   r   r-   r+   <module>r      s   
      , , , , , , . . . . . .< < < <~|
 |
 |
 |
 |
 |
 |
 |
 |
 |
r-   