o
    r::j                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ ejejejejejejejejejejejejejhZejdejdejd	ejd
ejdejdejdejdiZG dd de
ZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"dS )    )annotationsN)TensorProto)np_dtype_to_tensor_dtypetensor_dtype_to_np_dtype)OpRun)reshape_input)r      )i   )r   i  )i i  )r      )i   )r      )   c                   @  s$   e Zd Z						ddddZdS )_CommonQuantizeLinearNr   Tx
np.ndarrayy_scale
zero_pointnp.ndarray | Noneaxisintsaturatebool
block_size
int | Noneoutput_dtypeTensorProto.DataType | None	precisionreturntuple[np.ndarray]c	                 C  sv  t ||j||}|}	|d ur%t|j}
|r#||
kr#td| d|
 |
}	|	p)tj}	|	tvr6td|	 d|d urBt ||j||nd}|rUt|}|	||	| }n|| }|	t
v rt|	tj}||7 }t|	}t
|	 }t||d |d 	|fS |	tjtjtjtjhv r|rtjj|t|	dfS |	t|	fS |	tjkr||7 }|	t|	fS td|	 d)Nz+Mismatched output data-types: output_dtype=z, zero_point type=zUnexpected type: output_dtype=z# is not a supported quantized type.r   r   )dtype)_reshape_inputshaper   r    
ValueErrorr   UINT8_QUANT_TYPESr   astype_QUANT_INTEGER_RANGESnprintint32clipFLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZonnxnumpy_helpersaturate_cast
FLOAT4E2M1)selfr   r   r   r   r   r   r   r   tensor_typezero_point_typeprecision_npxir    quant_range r:   l/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/onnx/reference/ops/op_quantize_linear.py_run0   s\   




z_CommonQuantizeLinear._run)Nr   TNNN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname__r<   r:   r:   r:   r;   r   /   s    r   c                      s    e Zd Zdd fddZ  ZS )	QuantizeLinear_10Nr   r   r   c                   s*   t |jdkrtdt j||||dS )Nr   %Input 2 must be a vector or a number.)r   lenr"   r#   superr<   )r4   r   r   r   r   	__class__r:   r;   r<   x   s   zQuantizeLinear_10._run)Nr   )r   r   r=   r>   r?   r<   __classcell__r:   r:   rE   r;   r@   w       r@   c                      s    e Zd Zd
d fdd	Z  ZS )QuantizeLinear_19Nr   Tr   r   r   r   c                   s,   t |jdkrtdt j|||||dS )Nr   rA   )r   r   rB   )r4   r   r   r   r   r   rE   r:   r;   r<      s   zQuantizeLinear_19._run)Nr   T)r   r   r   r   rG   r:   r:   rE   r;   rJ   ~   rI   rJ   c                      s*   e Zd Zdddddd fddZ  ZS )QuantizeLinear_21r   Tr   Nr   r   r   r   r   r   r   r   r   c                  s   t  j|||||dS )NrL   rD   r<   )r4   r   r   r   r   argsrE   r:   r;   r<      s   	zQuantizeLinear_21._runr   r   r   r   r   r   rG   r:   r:   rE   r;   rK      s    rK   c                      ,   e Zd Zddddddd fddZ  ZS )QuantizeLinear_23r   Tr   Nr   r   r   r   r   r   r   r   r   r   c                     t  j||||||dS NrR   rM   r4   r   r   r   r   r   rN   rE   r:   r;   r<         
zQuantizeLinear_23._runrO   rG   r:   r:   rE   r;   rQ          rQ   c                      rP   )QuantizeLinear_25r   Tr   NrR   r   r   r   r   r   c                  rS   rT   rM   rU   rE   r:   r;   r<      rV   zQuantizeLinear_25._runrO   rG   r:   r:   rE   r;   rX      rW   rX   )#
__future__r   numpyr(   r0   r   onnx.helperr   r   onnx.reference.op_runr   onnx.reference.ops._quant_utilsr   r!   r$   INT8UINT16INT16INT2UINT2UINT4INT4r,   r-   r.   r/   r3   r%   r'   r   r@   rJ   rK   rQ   rX   r:   r:   r:   r;   <module>   sH   H