
    Si                       S SK Jr  S SKrS SKrS SKJr  S SKJrJr  S SK	J
r
  \R                  \R                  \R                  \R                  \R                  \R                   \R"                  \R$                  \R&                  \R(                  \R*                  \R,                  \R.                  1r\R                  S\R                  S\R                  S\R                  S	\R"                  S
\R$                  S\R                   S\R                  S0r S         SS jjr " S S\
5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r g)    )annotationsN)TensorProto)np_dtype_to_tensor_dtypetensor_dtype_to_np_dtype)OpRun)r      )i   )r   i  )i i  )r      )i   )r      )   c           
        [        U R                  5      S:X  a  U $ [        U R                  5      S:  a  U R                  S:X  a  U S   $ U(       dS  [        U R                  5      S:X  d   eS/[        U5      -  n U R                  XB'   U R                  [	        U5      5      $ US::  a  [        S5      e[        R                  " XUS	9n X   U R                  U   :w  a  U R                  [        X   5      US
9n U R                  U:w  a  [        S5      e[        R                  " XR                  5      U:X  d   eU $ ! [
         a%  n[        SU SU R                   SU S35      UeSnAff = f)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.)repeatsaxis)indicesr   zInvalid shapes for Blocked Quantization. Input 2 shape should identical to Input 1 shape, except for one dimension, in which blocking is performed)lenshapesizereshapetuple
IndexError
ValueErrornprepeattakerangebroadcast_shapes)valuer   r   
block_sizedimses         d/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx/reference/ops/op_quantize_linear.py_reshape_inputr%   .   sg   " 5;;1
5;;!

aQx5;;1$$$sSZ	DJ==t-- QABB IIed;Eu{{4((

5#5D
A{{e a
 	
 ukk2e;;;L)  	0 7${{m8E7!= 	s   <'D= =
E, E''E,c                  P    \ rS rSr      S                 SS jjrSrg)_CommonQuantizeLinear`   Nc	                N   [        X!R                  XF5      nUn	Ub4  [        UR                  5      n
U(       a  Xz:w  a  [	        SU SU
 35      eU
n	U	=(       d    [
        R                  n	U	[        ;  a  [	        SU	 S35      eUb  [        X1R                  XF5      OSnU(       a/  [        U5      nUR                  U5      UR                  U5      -  nOX-  nU	[        ;   ax  [        R                  " U5      R                  [        R                  5      nX-  n[        U	5      n[        U	   n[        R                  " XS   US   5      R                  U5      4$ U	[
        R                  [
        R                   [
        R"                  [
        R$                  1;   aJ  U(       a(  [&        R(                  R+                  U[        U	5      S94$ UR                  [        U	5      5      4$ U	[
        R,                  :X  a  X-  nUR                  [        U	5      5      4$ [	        SU	 S35      e)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   r*   r   r   UINT8_QUANT_TYPESr   astype_QUANT_INTEGER_RANGESr   rintint32clipFLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZonnxnumpy_helpersaturate_cast
FLOAT4E2M1)selfxy_scale
zero_pointr   saturater!   output_dtype	precisiontensor_typezero_point_typeprecision_npxir*   quant_ranges                  r$   _run_CommonQuantizeLinear._runa   s    !''4D #!6z7G7GHO ? A,Oabqars  *K!6[%6%6l*0=`a  % :wwA 	
 3I>L&)EEAA//""288,BB,[9E/<KGGBAA?FFuMOO$$&&""&&	
 
 %%33!9+!F 4  
 HH5kBCEE+000OAHH5kBCEE,[M9\]
 	
     )Nr   TNNN)r;   
np.ndarrayr<   rJ   r=   znp.ndarray | Noner   intr>   boolr!   
int | Noner?   zTensorProto.DataType | Noner@   rM   returnztuple[np.ndarray])__name__
__module____qualname____firstlineno__rF   __static_attributes__rI   rH   r$   r'   r'   `   s    
 )-!%48 $D
D
 D
 &	D

 D
 D
 D
 2D
 D
 
D
 D
rH   r'   c                  0   ^  \ rS rSrSSU 4S jjjrSrU =r$ )QuantizeLinear_10   c                h   > [        UR                  5      S:  a  [        S5      e[        TU ]  XX4S9$ )Nr   %Input 2 must be a vector or a number.)r   r   r   r   superrF   )r:   r;   r<   r=   r   	__class__s        r$   rF   QuantizeLinear_10._run   s3    w}}!DEEw|A
|>>rH   rI   )Nr   )r   rK   rO   rP   rQ   rR   rF   rS   __classcell__r[   s   @r$   rU   rU      s    ? ?rH   rU   c                  0   ^  \ rS rSrSSU 4S jjjrSrU =r$ )QuantizeLinear_19   c                j   > [        UR                  5      S:  a  [        S5      e[        TU ]  XX4US9$ )Nr   rX   )r   r>   rY   )r:   r;   r<   r=   r   r>   r[   s         r$   rF   QuantizeLinear_19._run   s5    w}}!DEEw|A
|QQrH   rI   )Nr   T)r   rK   r>   rL   r]   r_   s   @r$   ra   ra      s    R RrH   ra   c                  D   ^  \ rS rSrSSSSS.     S	U 4S jjjrSrU =r$ )
QuantizeLinear_21   r   Tr   Nr   r>   r!   r?   c               *   > [         TU ]  " UUUUUS.6$ )Nrh   rZ   rF   )r:   r   r>   r!   r?   argsr[   s         r$   rF   QuantizeLinear_21._run   s%     w|!%
 	
rH   rI   r   rK   r>   rL   r!   rK   r]   r_   s   @r$   rf   rf      s9     
 
 	

 
 
rH   rf   c                  F   ^  \ rS rSrSSSSSS.     S	U 4S jjjrSrU =r$ )
QuantizeLinear_23   r   Tr   Nr   r>   r!   r?   r@   c          	     ,   > [         TU ]  " UUUUUUS.6$ Nrq   rj   r:   r   r>   r!   r?   r@   rk   r[   s          r$   rF   QuantizeLinear_23._run   (     w|!%
 	
rH   rI   rm   r]   r_   s   @r$   ro   ro      <     
 
 	

 
 
rH   ro   c                  F   ^  \ rS rSrSSSSSS.     S	U 4S jjjrSrU =r$ )
QuantizeLinear_25   r   Tr   Nrq   c          	     ,   > [         TU ]  " UUUUUUS.6$ rs   rj   rt   s          r$   rF   QuantizeLinear_25._run   rv   rH   rI   rm   r]   r_   s   @r$   ry   ry      rw   rH   ry   )N)
r    rJ   r   ztuple[int, ...]r   rK   r!   rM   rN   rJ   )!
__future__r   numpyr   r6   r   onnx.helperr   r   onnx.reference.op_runr   r+   INT8UINT16INT16INT2UINT2UINT4INT4r2   r3   r4   r5   r9   r,   r.   r%   r'   rU   ra   rf   ro   ry   rI   rH   r$   <module>r      s   #    ( " xk
wgvg	   "	/// / 	/
 /dE
E E
P?- ?R- R
- 
&
- 
*
- 
rH   