
    `i                     l    S SK r SSKJr  SSKJrJrJrJr  S SK Jr	    " S S\5      r
  " S	 S
\5      rg)    N   )QuantOperatorBase   )find_by_nameget_mul_nodeQuantizedValueQuantizedValueType)onnx_pbc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )MatMulInteger
   c                 $   > [         TU ]  X5        g Nsuper__init__selfonnx_quantizer	onnx_node	__class__s      n/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxruntime_tools/quantization/operators/matmul.pyr   MatMulInteger.__init__       3    c                    U R                   nUR                  S:X  d   eU R                  R                  USS/5      u  p#pEUR                  S   S-   nUR
                  S:w  a  UR
                  S-   OSn[        R                  R                  SX#-   U/U5      nUR                  U5        US-   n	[        R                  R                  S	U/U	/US
-   [        R                  R                  S9n
UR                  U
5        [        U5      S:X  d   eUS:w  a  US-   OUS   S-   US   -   S-   n[        XR                  R                  5      nUc   [!        XKS-   U5      nUR                  U5        UR                  S   nSnUS:w  a  US-   nUR                  [!        X/UR                  S   U5      5        U R                  =R                  U-  sl        g )NMatMulr   r   _output_quantized _quantr   _cast_outputCast_cast)tor   _scales_mul__mulz:0_output_scale_mul)nodeop_type	quantizerquantize_inputsoutputnameonnxhelper	make_nodeappend
onnx_protoTensorProtoFLOATlenr   	new_nodesr   )r   r)   quantized_input_nameszero_point_namesscale_namesnodesmatmul_integer_outputmatmul_integer_namematmul_integer_nodecast_op_output	cast_nodescales_mul_opscales_mul_nodescales_mul_op_outputoutput_scale_mul_ops                  r   quantizeMatMulInteger.quantize   s   yy()( NN**4!Q8 	F	+ !%A1D D6:ii2odii(22"kk33OEZEm5J4KM`b() /?KK))&3H2INK[*?'*I-7-C-C-I-I * K	 	Y K A%&%?RVX?X+m;^i__"1~_&(._/ '}nn6N6NO"*;8Lm\OLL).55a8 !"$"58K"K\>"H$++VW.Zmno  E) r    __name__
__module____qualname____firstlineno__r   rE   __static_attributes____classcell__r   s   @r   r   r   
   s    4&* &*r   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )QLinearMatMul<   c                 $   > [         TU ]  X5        g r   r   r   s      r   r   QLinearMatMul.__init__=   r   r   c                 ,   U R                   nUR                  S:X  d   eU R                  R                  USS/5      u  p#pEU R                  R	                  UR
                  S   5      u  pgn  n	U(       d2  [        SR                  UR
                  S   UR                  5      5      eUR
                  S   S-   n
UR                  S:w  a  UR                  S-   OSn/ nUR                  US   5        UR                  US   5        UR                  US   5        UR                  US   5        UR                  US   5        UR                  US   5        UR                  U5        UR                  U5        [        R                  R                  SX/U5      nUR                  U5        [        UR
                  S   XU[        R                  5      nXR                  R                   UR
                  S   '   U R                  =R"                  U-  sl        g )	Nr   r   r   zBQuantization parameters for output:"{}" of node:"{}" not specified
_quantizedr   r    rQ   )r)   r*   r+   r,   _get_quantization_paramsr-   
ValueErrorformatr.   r2   r/   r0   r1   r   r	   Inputquantized_value_mapr7   )r   r)   r8   r9   r:   r;   
data_foundoutput_scale_nameoutput_zp_namer&   qlinear_matmul_outputqlinear_matmul_nameqlinear_matmul_inputsqlinear_matmul_nodeq_outputs                  r   rE   QLinearMatMul.quantize@   s   yy()( NN**4!Q8 	F	+ NN33DKKNC 	<
~q! ellA		+ , , !%A =6:ii2odii(22 "$$%:1%=>$$[^4$$%5a%89$$%:1%=>$$[^4$$%5a%89$$%67$$^4"kk33OEZ\s4GI() "$++a.2G\j"4":":<=E**4;;q>:  E) r   rG   rH   rO   s   @r   rQ   rQ   <   s    4'* '*r   rQ   )r/   base_operatorr   quant_utilsr   r   r   r	   r
   r3   r   rQ   rG   r   r   <module>rg      s9     , X X &
**% **Z
+*% +*r   