
    קgf                     L   d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ 	 ddede	e         de
ee         ee	e         f         fd	Zd
ee         dee         fdZ G d de          Z ej        d          d             Zd Z G d de          Zd ZdS )    N)dedent)AnyList
NamedTupleOptionalTuple)ErrorReport)SourceRangeFactoryobj	error_msgreturnc                     d}	 t          j        |           }t          j        |           \  }}n2# t          $ r%}d|  d}|r|d|z   z  }t          |          |d}~ww xY w|||fS )z{
    Wrapper around inspect.getsourcelines and inspect.getsourcefile.

    Returns: (sourcelines, file_lino, filename)
    NzCan't get source for zs. TorchScript requires source access in order to carry out compilation, make sure original .py files are available.
)inspectgetsourcefilegetsourcelinesOSError)r   r   filenamesourcelinesfile_linenoemsgs          J/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/_sources.pyget_source_lines_and_filer      s     H"(--#*#9##>#> [[ " " "C    	
  	$4)##Ccll!" X--s   +0 
A AAr   c                 t   d d}t          |           D ]0\  }}|                                                    d          r|} n1|| S | |         }|                    d          d         fd| d|         D             }fd| |dz   d         D             }|                    |           ||z   S )a   
    This helper function accepts a list of source lines. It finds the
    indentation level of the function definition (`def`), then it indents
    all lines in the function body to a point at or greater than that
    level. This allows for comments and continued string literals that
    are at a lower indentation than the rest of the code.
    Args:
        sourcelines: function source code, separated into lines by
                        the '
' character
    Returns:
        A list of source lines that have been correctly aligned
    c                 Z    | |                      |          ot          |          d          S N)
startswithlen)textprefixs     r   remove_prefixz-normalize_source_lines.<locals>.remove_prefix4   s*    DOOF++;F==>>    Ndefr   c                 .    g | ]} |          z   S  r&   .0sr"   
whitespaces     r   
<listcomp>z*normalize_source_lines.<locals>.<listcomp>I   7       67
]]1j111  r#   c                 .    g | ]} |          z   S r&   r&   r'   s     r   r+   z*normalize_source_lines.<locals>.<listcomp>L   r,   r#      )	enumeratelstripr   splitappend)	r   idxilfn_defaligned_prefixaligned_suffixr"   r*   s	          @@r   normalize_source_linesr9   &   s"   ? ? ? C+&&  188::  '' 	CE	 { Fe$$Q'J    ;Ftt;L  N    ;FsQwyy;Q  N
 &!!!N**r#   c                   $     e Zd Z	 	 d fd	Z xZS )SourceContextTNc                 z    t                                          ||||           || _        || _        || _        d S r   )super__init__uses_true_divisionr   funcname)selfsourcer   r   leading_whitespace_lenr?   r@   	__class__s          r   r>   zSourceContext.__init__X   s>     	;8NOOO"4  r#   )TN)__name__
__module____qualname__r>   __classcell__)rD   s   @r   r;   r;   W   sE          ! ! ! ! ! ! ! ! ! !r#   r;   )maxsizec                      t          |  S r   )r;   )argss    r   make_source_contextrL   g   s    $r#   c                  N    t          dd dd                              dd          S )N r   r.   )r;   make_raw_ranger&   r#   r   
fake_rangerP   l   s&    T1a((771===r#   c                   X    e Zd ZU ej        ed<   eed<   eed<   ee         ed<   e	ed<   dS )	ParsedDefastctxrB   r   r   N)
rE   rF   rG   rS   Module__annotations__r;   strr   intr&   r#   r   rR   rR   p   sN         	OOO	KKKsmr#   rR   c                 |   t          | t          j                              \  }}}t          |          }d                    |          }t          |          }t          j        |          }t          |j	                  dk    s%t          |j	        d         t          j                  st          d| d|           t          |                    dd          d                   t          |                    dd          d                   z
  }t          ||||d| j                  }t!          |||||          S )NrN   r.   r   z&Expected a single top-level function: :r   T)r   r	   
call_stackr9   joinr   rS   parser   body
isinstanceFunctionDefRuntimeErrorr1   rL   rE   rR   )	fnr   r   r   rB   
dedent_srcpy_astrC   rT   s	            r   	parse_defre   x   s6   )B
K"$$* *&Kh )55KWW[!!FJYz""F
6;1Jv{1~s$O$OMXMMMM
 
 	
 !dA!6!6q!9::Sq!!!$> >  +'=tR[ C VS&(K@@@r#   r   )rS   	functoolsr   textwrapr   typingr   r   r   r   r   torch._Cr	   torch._C._jit_tree_viewsr
   rW   rX   r   r9   r;   	lru_cacherL   rP   rR   re   r&   r#   r   <module>rl      s   



            9 9 9 9 9 9 9 9 9 9 9 9 9 9             7 7 7 7 7 7
  $. .	.}. 49c8C=(). . . .4,+S	 ,+d3i ,+ ,+ ,+ ,+b! ! ! ! !& ! ! !  T"""    #" > > >    
   A A A A Ar#   