
    Fg	                     P    S SK r S SKr S SKrS SKJr  S SKrS SKJr   " S S5      rg)    N)numpy_helper)onnx_operatorsc                       \ rS rSrS rS\R                  4S jrS rS r	S\R                  S\
R                  4S jrS	rg
)OnnxProfile	   c                     g )N )selfs    b/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/thop/onnx_profile.py__init__OnnxProfile.__init__
   s        modelc                     UR                   R                  nSnU H=  n [        R                  " U5      nU[        R
                  " UR                  5      -  nM?     U$ ! [         a  n S nAMS  S nAff = fNr   )graphinitializerr   to_arraynpprodshape	Exception)r
   r   onnx_weightsparamsonnx_wweight_s          r   calculate_paramsOnnxProfile.calculate_params   sh    {{.."F%..v6"''&,,// #   s   9A
A3.A3c                 r   0 nU Hy  n[         R                  " UR                  5      nXd[        UR                  5      '   UR
                  S:X  d  ML  [         R                  " SU5      U[        UR                  5      '   M{     U GH  n[         R                  " UR                  R                  R                  R                  S   R                  5      n/ nUR                  R                  R                  R                   H-  n[         R                  " U[        UR                  5      5      nM/     Xd[        UR                  5      '   UR
                  S:X  d  M  [         R                  " SU5      U[        UR                  5      '   GM     U H  n	[         R                  " U	R                  R                  R                  R                  S   R                  5      nU/U[        U	R                  5      '   UR
                  S:X  d  My  [         R                  " SU5      U[        U	R                  5      '   M     U$ )N   r   )r   arraydimsstrnamesizeappendtypetensor_typer   dim	dim_valueint)
r
   r   inputoutputdictionwr*   ikeyos
             r   create_dictOnnxProfile.create_dict   s   A((166"C#&CK xx1}')yyC'8AFF$	 
 A((166--3377:DDEC Cvv))//33iiS%78 4 $'CK xx1}')yyC'8AFF$  A((166--3377:DDEC$'5GCK xx1}')yyC'8AFF$	 
 r   c                     UR                   [        ;  a  [        SUR                   S5        g[        UR                      nU" X5      $ )NzSorry, we haven't add zinto dictionary.)r   NN)op_typer   print)r
   r/   nodefns       r   nodes_counterOnnxProfile.nodes_counter5   s<    <<~-*DLL:LM -Bg$$r   returnc                 ^   Sn0 nUR                   R                  nUR                   R                  nUR                   R                  nUR                   R                  nU R                  XFU5      nSnU H  nU R                  X85      u  pnXU'   X)-  nM!     [        R                  " US   5      $ r   )	r   r   r9   r-   r.   r4   r;   r   r"   )r
   r   macs	name2dimsr   nodesr-   r.   nmacs_addingout_sizeoutnames               r   calculate_macsOnnxProfile.calculate_macs=   s    	((  !!##$$VF;	A-1-?-?	-M*K7!)gD	 
 xxQ  r   r	   N)__name__
__module____qualname____firstlineno__r   onnx
ModelProtor   r4   r;   torchDoubleTensorrF   __static_attributes__r	   r   r   r   r   	   s>    doo 6%!DOO !8J8J !r   r   )	rN   torch.nnrL   r   numpyr   thop.vision.onnx_counterr   r   r	   r   r   <module>rT      s#         3B! B!r   