
    /j                        d dl mZ d dlZd dlmZ d dlmZmZ d dl	m
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dS )    )annotationsN)TensorProto)np_dtype_to_tensor_dtypetensor_dtype_to_np_dtype)OpRun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      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         l/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/onnx/reference/ops/op_dequantize_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 )_CommonDequantizeLinearNr   r   xr	   x_scalex_zero_pointnp.ndarray | Noner   r   r   output_dtyper   c                <   t          |j                  }|t          j        t          j        t          j        t          j        hv }|z|sx|t          j        k    rht          |j                  }	||	k    rt          d| d|	 d          |	                    t          j                  t          ||j        ||          z
  }
n|rv|t|	                    t          j                  }|                                }|                                }||k    s|t          j        d          k    rt          d          |	                    t          j                  }
|
t          ||j        ||          z  }|	                    |rt#          |          n|j                  fS )NzType mismatch z != z in DequantizeLinear.r   z=x_zero_point is not null but should be zero for float8 types.)r   dtyper   FLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZ
FLOAT4E2M1r   astyper   float32r$   r
   uint8minmaxr   )selfr'   r(   r)   r   r   r+   x_typefp8_type	zero_typedxu_x_zero_pointumiumays                  r#   _runz_CommonDequantizeLinear._run@   s    *!'22$&"&	
 
 $ %+00001CDDI"" QVQQQQQ   "*%%agtZ) ) BB  L4!-!4!4RX!>!>$((**$((**#::!3!3$W   "*%%B$
CCCHH#(666] 
 	
    )Nr   r   N)r'   r	   r(   r	   r)   r*   r   r   r   r   r+   r   )__name__
__module____qualname__rA    rB   r#   r&   r&   ?   s;        
 +/#'/
 /
 /
 /
 /
 /
 /
rB   r&   c                  "     e Zd Zdd fdZ xZS )DequantizeLinear_19Nr   r   r   c                    t          |j                  dk    rt          d          t                                          ||||          S )Nr   z%Input 2 must be a vector or a number.)r   r
   r   superrA   )r8   r'   r(   r)   r   	__class__s        r#   rA   zDequantizeLinear_19._runs   sC    w}!!DEEEww||Awd;;;rB   )Nr   )r   r   rC   rD   rE   rA   __classcell__rK   s   @r#   rH   rH   r   sB        < < < < < < < < < < <rB   rH   c                  (     e Zd Zdddd fdZ xZS )	DequantizeLinear_21r   r   r   r   r   r   r   c               8     t                      j        |||dS )NrQ   rJ   rA   )r8   r   r   argsrK   s       r#   rA   zDequantizeLinear_21._runz   s     uww|TDDDDrB   r   r   r   r   rL   rN   s   @r#   rP   rP   y   sX        &'1 E E E E E E E E E E E ErB   rP   c                  *     e Zd Zddddd	 fdZ xZS )
DequantizeLinear_23r   r   Nr   r   r+   r   r   r   c               :     t                      j        ||||dS NrX   rS   r8   r   r   r+   rT   rK   s        r#   rA   zDequantizeLinear_23._run   +    uww|,
 
 
 	
rB   rU   rL   rN   s   @r#   rW   rW      N        &'14 
 
 
 
 
 
 
 
 
 
 
 
rB   rW   c                  *     e Zd Zddddd	 fdZ xZS )
DequantizeLinear_25r   r   NrX   r   r   r   c               :     t                      j        ||||dS rZ   rS   r[   s        r#   rA   zDequantizeLinear_25._run   r\   rB   rU   rL   rN   s   @r#   r_   r_      r]   rB   r_   )N)
r   r	   r
   r   r   r   r   r   r   r	   )
__future__r   numpyr   onnxr   onnx.helperr   r   onnx.reference.op_runr   r$   r&   rH   rP   rW   r_   rF   rB   r#   <module>rf      si   # " " " " "           J J J J J J J J ' ' ' ' ' ' "	/ / / / /d0
 0
 0
 0
 0
e 0
 0
 0
f< < < < <1 < < <E E E E E1 E E E
 
 
 
 
1 
 
 

 
 
 
 
1 
 
 
 
 
rB   