
    bIg#                    f    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lm	Z	 d dl
mZ  G d de      Zy)	    )annotationsN)TensorProto)Base)expect)make_tensorc                      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y)DequantizeLinearc                 ~   t         j                  j                  dg ddg      } t        j                  g d      j                  t        j                        }t        j                  d      }t        j                  d      }t        j                  g dt        j                  	      }t        | |||g|gd
       y )Nr	   xx_scalex_zero_pointyinputsoutputs)r               r   )i ir      dtypetest_dequantizelinearr   r   name)	onnxhelper	make_nodenparrayastypeuint8float32r   noder   r   r   r   s        i/var/www/html/answerous/venv/lib/python3.12/site-packages/onnx/backend/test/case/node/dequantizelinear.pyexportzDequantizeLinear.export   s    {{$$3E % 
 HH%&--bhh7**Q-xx}HH)<w-C(		
    c                 d   t         j                  j                  dg ddg      } t        j                  ddgddgd	d
ggddgddgddggddgddgddggggt        j
                        }t        j                  g dt        j                        }t        j                  g dt        j
                        }|j                  t        j                        |j                  dddd      j                  t        j                        z
  |j                  dddd      z  }t        | |||g|gd       y )Nr	   r   r   r   r   Y   "      J   ;         W             c         y   f   r   )r   r7   r0   )T   r1         test_dequantizelinear_axisr   )
r   r   r   r    r!   r#   r$   r"   reshaper   r%   s        r'   export_axiszDequantizeLinear.export_axis%   s$   {{$$3E % 
 HH Wr3i"b2Wr2hR12YC3*5 ((	
 ((9BJJ7xxRXX>HHRZZ <#7#71a#C#J#J2::#VVOOAq!Q'( 	w-C-		
r)   c                 *   t         j                  j                  dddgdgd      } t        dt        j
                  dgg d      }t        j                  d	      }t        j                  g d
t        j                        }t        | ||g|gd       y )Nr	   r   r   r   r   r   r   axisr0   r         ?r=   i  ir                 ?       @g      @g      jr   test_dequantizelinear_e4m3fnr   
r   r   r   r   r   FLOAT8E4M3FNr    r$   r!   r   r&   r   r   r   s       r'   export_e4m3fnzDequantizeLinear.export_e4m3fnE   s    {{$$#E	 % 
 [55s<RS**Q-HH32::Fw<C/		
r)   c                 *   t         j                  j                  dddgdgd      } t        dt        j
                  dgg d      }t        j                  d	      }t        j                  g d
t        j                        }t        | ||g|gd       y )Nr	   r   r   r   r   rB   r0   rD   r   rF   r   $test_dequantizelinear_e4m3fn_float16r   )
r   r   r   r   r   rL   r    float16r!   r   rM   s       r'   export_e4m3fn_float16z&DequantizeLinear.export_e4m3fn_float16Z   s    {{$$#E	 % 
 [55s<RS**Q-HH32::Fw<C7		
r)   c                 h   t         j                  j                  dg ddgd      } t        dt        j
                  dgg d      }t        d	t        j
                  d
gdg      }t        j                  d      }t        j                  g dt        j                        }t        | |||g|gd       y )Nr	   )r   r   
zero_pointr   r   rB   r   r0   rD   rT   r=   r   rF   r   'test_dequantizelinear_e4m3fn_zero_pointr   rK   )r&   r   rT   r   r   s        r'   export_e4m3fn_zero_pointz)DequantizeLinear.export_e4m3fn_zero_pointo   s    {{$$1E	 % 
 [55s<RS {/G/G!qcR
**Q-HH32::Fw
+C:		
r)   c                 *   t         j                  j                  dddgdgd      } t        dt        j
                  dgg d      }t        j                  d	      }t        j                  g d
t        j                        }t        | ||g|gd       y )Nr	   r   r   r   r   rB   r0   )r   rE   r=   i   ir   )rG   rH   rI   g      @g      hr   test_dequantizelinear_e5m2r   )
r   r   r   r   r   
FLOAT8E5M2r    r$   r!   r   rM   s       r'   export_e5m2zDequantizeLinear.export_e5m2   s    {{$$#E	 % 
 [33aS:QR**Q-HH5RZZHw<C-		
r)   c                 ~   t         j                  j                  dg ddg      } t        j                  g d      j                  t        j                        }t        j                  d      }t        j                  d      }t        j                  g dt        j                  	      }t        | |||g|gd
       y )Nr	   r   r   r   )i0u  iy  i   i  r   i  )g     g     rI   g      }@r   test_dequantizelinear_uint16r   )	r   r   r   r    r!   r"   uint16r$   r   r%   s        r'   export_uint16zDequantizeLinear.export_uint16   s    {{$$3E % 
 HH1299"))D**Q-yy'HH32::Fw-C/		
r)   c                 ~   t         j                  j                  dg ddg      } t        j                  g d      j                  t        j                        }t        j                  d      }t        j                  d      }t        j                  g dt        j                  	      }t        | |||g|gd
       y )Nr	   r   r   r   )iiii  r   i )g     @g     @g       g     @r   test_dequantizelinear_int16r   )	r   r   r   r    r!   r"   int16r$   r   r%   s        r'   export_int16zDequantizeLinear.export_int16   s    {{$$3E % 
 HH-.55bhh?**Q-xxHH32::Fw-C.		
r)   c                 f   t         j                  j                  dg ddgd      } t        dt        j
                  dgg d      }t        j                  d	      }t        d
t        j
                  ddg      }t        j                  g dt        j                        }t        | |||g|gd       y )Nr	   r   r   r   rB   r   r0   )r   r=      
      r   r   r=   r=   )r            r   test_dequantizelinear_uint4r   )
r   r   r   r   r   UINT4r    r$   r!   r   r%   s        r'   export_uint4zDequantizeLinear.export_uint4   s    {{$$3E	 % 
 [..5FG**Q-">;3D3DdQCPHH(

;w-C.		
r)   c                 f   t         j                  j                  dg ddgd      } t        dt        j
                  dgg d      }t        j                  d	      }t        d
t        j
                  ddg      }t        j                  g dt        j                        }t        | |||g|gd       y )Nr	   r   r   r   rB   r   r0   )r   r=   rd   ir   r   rg   r=   )rh   r   ri   iir   test_dequantizelinear_int4r   )
r   r   r   r   r   INT4r    r$   r!   r   r%   s        r'   export_int4zDequantizeLinear.export_int4   s    {{$$3E	 % 
 [--s4EF**Q-">;3C3CTA3OHH*"**=w-C-		
r)   c            	        t         j                  j                  dg ddgdd      } t        j                  ddgd	d
gddggddgddgddggddgddgddggddgddgddggggt        j
                        t        j                  ddgdd gddggd!dgddgd!dggggt        j                        t        j                  dd"gd"dgdd#ggddgddgd$dggggt        j
                        }j                  |j                  k(  sJ dt        fd%t        t        j                              D              sJ j                     j                     z  d"k(  sJ j                     j                     z  }t        j                  |&      }t        j                  ||&      }j                  t        j                        |j                  t        j                        z
  |z  }t        | |g|gd'(       y ))Nr	   r   r   r=   r   )r   r   rC   
block_sizer   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   ri   !   A   *   r5   r6   r7   r8   r9   r:   r   g      @rI   g      @rH   g      @r      rf   c              3  f   K   | ](  }|k7  r!j                   |   j                   |   k(   * y w)N)shape).0i
block_axisr   r   s     r'   	<genexpr>z2DequantizeLinear.export_blocked.<locals>.<genexpr>  s6      
J GGAJ'--**
s   .1)repeatsrC   test_dequantizelinear_blockedr   )r   r   r   r    r!   r#   r$   r{   allrangelenrepeatr"   r   )	r&   r   r   x_scale_elementwisex_zero_point_elementwiser   r~   r   r   s	         @@@r'   export_blockedzDequantizeLinear.export_blocked   sU   {{$$3E % 
 HH Wr3i"b2Wr2hR1Wr2hR12YC3*5	 ((

 (( 3Z#sc3Z83Z#sc3Z8 **
 xx VaVaW-VaVb!W- ((
 }} 2 2222
 
3qww<(
 
 	
 

 wwz"W]]:%>>!CCC''*%z)BB !iizR#%99'
$
 
 HHRZZ #;#B#B2::#NN  	w-C0		
r)   N)returnNone)__name__
__module____qualname__staticmethodr(   r@   rN   rR   rV   rZ   r^   rb   rn   rs   r    r)   r'   r	   r	      s    
 
( 
 
> 
 
( 
 
( 
 
* 
 
( 
 
& 
 
& 
 
* 
 
* D
 D
r)   r	   )
__future__r   numpyr    r   r   onnx.backend.test.case.baser   onnx.backend.test.case.noder   onnx.helperr   r	   r   r)   r'   <module>r      s*    #    , . #d
t d
r)   