o
    soi+                     @  s`   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 deZdS )	    )annotationsN)TensorProto)Base)expect)make_tensorc                   @  s   e Zd Zed ddZed ddZed ddZed d	d
Zed ddZed ddZ	ed ddZ
ed ddZed ddZed ddZed ddZed ddZed ddZed ddZdS )!DequantizeLinearreturnNonec                  C  r   t jjdg ddgd} tg dtj}td}td}tjg dtjd	}t| |||g|gd
d d S )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    r'   `/home/ubuntu/.local/lib/python3.10/site-packages/onnx/backend/test/case/node/dequantizelinear.pyexport   s   


zDequantizeLinear.exportc                  C  s   t jjdg ddg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ggtjd}tjg dtjd}tjg dtjd}|tj|ddddtj |dddd }t	| |||g|gdd d S )Nr   r   r   r   r   Y   "      J   ;         W             c         y   f   r   )r   r6   r/   )T   r0         test_dequantizelinear_axisr   )
r   r   r   r    r!   r#   r$   r"   reshaper   r%   r'   r'   r(   export_axis%   s0   
"
zDequantizeLinear.export_axisc                  C  h   t jjdddgdgdd} tdtjdgg d}td	}tjg d
tjd}t	| ||g|gdd d S )Nr   r   r   r   r   r   r   axisr/   r         ?r<   i  ir                 ?       @g      @g      jr   test_dequantizelinear_e4m3fnr   
r   r   r   r   r   FLOAT8E4M3FNr    r$   r!   r   r&   r   r   r   r'   r'   r(   export_e4m3fnE      

zDequantizeLinear.export_e4m3fnc                  C  r@   )Nr   r   r   r   r   rA   r/   rC   r   rE   r   $test_dequantizelinear_e4m3fn_float16r   )
r   r   r   r   r   rK   r    float16r!   r   rL   r'   r'   r(   export_e4m3fn_float16Z   rN   z&DequantizeLinear.export_e4m3fn_float16c                  C  s~   t jjdg ddgdd} tdtjdgg d}td	tjd
gdg}td}tjg dtjd}t	| |||g|gdd d S )Nr   )r   r   
zero_pointr   r   rA   r   r/   rC   rR   r<   r   rE   r   'test_dequantizelinear_e4m3fn_zero_pointr   rJ   )r&   r   rR   r   r   r'   r'   r(   export_e4m3fn_zero_pointo   s    

z)DequantizeLinear.export_e4m3fn_zero_pointc                  C  r@   )Nr   r   r   r   r   rA   r/   )r   rD   r<   i   ir   )rF   rG   rH   g      @g      hr   test_dequantizelinear_e5m2r   )
r   r   r   r   r   
FLOAT8E5M2r    r$   r!   r   rL   r'   r'   r(   export_e5m2   rN   zDequantizeLinear.export_e5m2c                  C  r
   )Nr   r   r   r   )i0u  iy  i   i  r   i  )g     g     rH   g      }@r   test_dequantizelinear_uint16r   )	r   r   r   r    r!   r"   uint16r$   r   r%   r'   r'   r(   export_uint16      


zDequantizeLinear.export_uint16c                  C  r
   )Nr   r   r   r   )iiii  r   i )g     @g     @g       g     @r   test_dequantizelinear_int16r   )	r   r   r   r    r!   r"   int16r$   r   r%   r'   r'   r(   export_int16   r[   zDequantizeLinear.export_int16c                  C  |   t jjdg ddgdd} tdtjdgg d}td	}td
tjddg}tjg dtjd}t	| |||g|gdd d S )Nr   r   r   r   rA   r   r/   )r   r<      
      r   r   r<   r<   )r            r   test_dequantizelinear_uint4r   )
r   r   r   r   r   UINT4r    r$   r!   r   r%   r'   r'   r(   export_uint4       

zDequantizeLinear.export_uint4c                  C  r_   )Nr   r   r   r   rA   r   r/   )r   r<   r`   r   r   rc   r<   )rd   r   re   iir   test_dequantizelinear_int4r   )
r   r   r   r   r   INT4r    r$   r!   r   r%   r'   r'   r(   export_int4   rk   zDequantizeLinear.export_int4c                  C  r_   )Nr   r   r   r   rA   r   r6   )r   r<   r   r   r   r   rc   r<   )rd   r   r   r6   r   test_dequantizelinear_uint2r   )
r   r   r   r   r   UINT2r    r$   r!   r   r%   r'   r'   r(   export_uint2   rk   zDequantizeLinear.export_uint2c                  C  r_   )Nr   r   r   r   rA   r   r6   )r   r<   rd   r   r   rc   r<   )rd   r   rl   ir   test_dequantizelinear_int2r   )
r   r   r   r   r   INT2r    r$   r!   r   r%   r'   r'   r(   export_int2  rk   zDequantizeLinear.export_int2c                  C  s|   t jjdg ddgdd} tdtjdgg d}td	}td
tjddg}tjg dtjd}t	| |||g|gdd d S )Nr   r   r   r   rA   r   r/   )r   r<   rt   g      ?rl   r   r   rc   )r   r   rd   r   rm   r    test_dequantizelinear_float4e2m1r   )
r   r   r   r   r   
FLOAT4E2M1r    r$   r!   r   r%   r'   r'   r(   export_float4e2m1  rk   z"DequantizeLinear.export_float4e2m1c                    s  t jjdg ddgd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d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d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d}j|jksJ d t fd%d&t	t
jD sJ j  j   d"ksJ j  j   }tj| d'}tj|| d'}tj|tj | }t| |g|gd(d) d S )*Nr   r   r   r<   r   )r   r   rB   
block_sizer   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   re   !   A   *   r4   r5   r6   r7   r8   r9   r   g      @rH   g      @rG   g      @r      rb   c                 3  s,    | ]}| krj | j | kV  qd S )N)shape).0i
block_axisr   r   r'   r(   	<genexpr>^  s    z2DequantizeLinear.export_blocked.<locals>.<genexpr>)repeatsrB   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(   export_blocked0  sd   	
zDequantizeLinear.export_blockedN)r   r	   )__name__
__module____qualname__staticmethodr)   r?   rM   rQ   rT   rW   rZ   r^   rj   rp   rs   rw   rz   r   r'   r'   r'   r(   r      s:    r   )
__future__r   numpyr    r   r   onnx.backend.test.case.baser   onnx.backend.test.case.noder   onnx.helperr   r   r'   r'   r'   r(   <module>   s   