
    /j                       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
 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	 d$d%dZ G d de
          Z G d de          Z G d de          Z G d de          Z G d  d!e          Z G d" d#e          Z dS )&    )annotationsN)TensorProto)np_dtype_to_tensor_dtypetensor_dtype_to_np_dtype)OpRun)r      )i   )r   i  )i i  )r      )i   )r      )   value
np.ndarrayshapetuple[int, ...]axisint
block_size
int | Nonereturnc           
        t          | j                  dk    r| S t          | j                  dk    r| j        dk    r| d         S |st          | j                  dk    sJ dgt          |          z  }	 | j        ||<   |                     t	          |                    S # t
          $ r$}t          d| d| j         d| d          |d}~ww xY w|dk    rt          d          t          j        | ||	          } ||         | j        |         k    r*| 	                    t          ||                   |
          } | j        |k    rt          d          t          j        || j                  |k    sJ | S )a  Reshape/Replicate scale/zero-point to be broadcastable to shape.

    Args:
        value: the array to be reshaped/replicated
        shape: the target shape
        axis: quantization axis, applicable for per-axis and blocked quantization
        block_size: size of quantization block, applicable only for blocked quantization

    Returns:
        value array after reshape/replicate according to quantization mode.
    r   r   zaxis is out of boundary, axis=z, value.shape=z, shape=.Nz&block_size must be a positive integer.)repeatsr   )indicesr   zInvalid shapes for Blocked Quantization. Input 2 shape should identical to Input 1 shape, except for one dimension, in which blocking is performed)lenr   sizereshapetuple
IndexError
ValueErrornprepeattakerangebroadcast_shapes)r   r   r   r   dimses         j/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/onnx/reference/ops/op_quantize_linear.py_reshape_inputr*   .   s   " 5;1
5;!
aQx 
5;1$$$$sSZZ	DJ==t--- 	 	 	= = =${= =49= = =  	 QABBB IeZd;;;Edu{4(((

5t#5#5D
AA{e a
 
 	
 uek22e;;;;Ls   6+B" "
C,CCc                  $    e Zd Z	 	 	 	 	 	 dddZdS )_CommonQuantizeLinearNr   Txr   y_scale
zero_pointnp.ndarray | Noner   r   saturateboolr   r   output_dtypeTensorProto.DataType | None	precisionr   tuple[np.ndarray]c	                l   t          ||j        ||          }|}	|3t          |j                  }
|r||
k    rt	          d| d|
           |
}	|	pt
          j        }	|	t          vrt	          d|	 d          |t          ||j        ||          nd}|r;t          |          }|	                    |          |	                    |          z  }n||z  }|	t          v rt          j        |          	                    t          j                  }||z  }t          |	          }t          |	         }t          j        ||d         |d                   	                    |          fS |	t
          j        t
          j        t
          j        t
          j        hv rT|r/t&          j                            |t          |	                    fS |	                    t          |	                    fS |	t
          j        k    r(||z  }|	                    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)r*   r   r   r8   r!   r   UINT8_QUANT_TYPESr   astype_QUANT_INTEGER_RANGESr"   rintint32clipFLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZonnxnumpy_helpersaturate_cast
FLOAT4E2M1)selfr-   r.   r/   r   r1   r   r3   r5   tensor_typezero_point_typeprecision_npxir8   quant_ranges                  r)   _runz_CommonQuantizeLinear._runa   sl    !!'4DD #!6z7GHHO  ? ? s,ssbqss   *K!6[%6l**aaaa   % :qwjAAA 	
  	3I>>L&&)E)EEAAGA///""28,,B*B,[99E/<KGBAA??FFuMMOO$&"&	
 
 
  %33!9+!F!F 4   
 HH5kBBCCEE+000OAHH5kBBCCEE][]]]
 
 	
    )Nr   TNNN)r-   r   r.   r   r/   r0   r   r   r1   r2   r   r   r3   r4   r5   r   r   r6   )__name__
__module____qualname__rN    rO   r)   r,   r,   `   sH        
 )-!%48 $D
 D
 D
 D
 D
 D
 D
rO   r,   c                  "     e Zd Zdd fdZ xZS )QuantizeLinear_10Nr   r   r   c                    t          |j                  dk    rt          d          t                                          ||||          S )Nr   %Input 2 must be a vector or a number.)r   r   r   r!   superrN   )rH   r-   r.   r/   r   	__class__s        r)   rN   zQuantizeLinear_10._run   sE    w}!!DEEEww||Aw
|>>>rO   )Nr   )r   r   rP   rQ   rR   rN   __classcell__rZ   s   @r)   rU   rU      sB        ? ? ? ? ? ? ? ? ? ? ?rO   rU   c                  "     e Zd Zd	d
 fdZ xZS )QuantizeLinear_19Nr   Tr   r   r1   r2   c                    t          |j                  dk    rt          d          t                                          |||||          S )Nr   rW   )r   r1   rX   )rH   r-   r.   r/   r   r1   rZ   s         r)   rN   zQuantizeLinear_19._run   sG    w}!!DEEEww||Aw
|QQQrO   )Nr   T)r   r   r1   r2   r[   r]   s   @r)   r_   r_      sM        R R R R R R R R R R RrO   r_   c                  ,     e Zd Zdddddd fdZ xZS )QuantizeLinear_21r   Tr   Nr   r1   r   r3   r   r   r1   r2   r   c               <     t                      j        |||||dS )Nrc   rY   rN   )rH   r   r1   r   r3   argsrZ   s         r)   rN   zQuantizeLinear_21._run   s3     uww|!%
 
 
 	
rO   r   r   r1   r2   r   r   r[   r]   s   @r)   rb   rb      sU         
 
 
 
 
 
 
 
 
 
 
 
rO   rb   c                  .     e Zd Zddddddd fdZ xZS )QuantizeLinear_23r   Tr   Nr   r1   r   r3   r5   r   r   r1   r2   r   c          	     >     t                      j        ||||||dS Nrj   re   rH   r   r1   r   r3   r5   rf   rZ   s          r)   rN   zQuantizeLinear_23._run   6     uww|!%
 
 
 	
rO   rg   r[   r]   s   @r)   ri   ri      X         
 
 
 
 
 
 
 
 
 
 
 
rO   ri   c                  .     e Zd Zddddddd fdZ xZS )QuantizeLinear_25r   Tr   Nrj   r   r   r1   r2   r   c          	     >     t                      j        ||||||dS rl   re   rm   s          r)   rN   zQuantizeLinear_25._run   rn   rO   rg   r[   r]   s   @r)   rq   rq      ro   rO   rq   )N)
r   r   r   r   r   r   r   r   r   r   )!
__future__r   numpyr"   rD   r   onnx.helperr   r   onnx.reference.op_runr   r9   INT8UINT16INT16INT2UINT2UINT4INT4r@   rA   rB   rC   rG   r:   r<   r*   r,   rU   r_   rb   ri   rq   rS   rO   r)   <module>r~      sX   # " " " " "                   ( ' ' ' ' ' " xk
wgvg	   "	/ / / / /dE
 E
 E
 E
 E
E E
 E
 E
P? ? ? ? ?- ? ? ?R R R R R- R R R
 
 
 
 
- 
 
 
&
 
 
 
 
- 
 
 
*
 
 
 
 
- 
 
 
 
 
rO   