o
    h'                     @   s   d dl Z d dlZd dlZd dlmZ dd Zdd Zdd Zd	d
 Z	dd Z
dd Zd"ddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Ze ZdS )#    N)_find_builtinc                 C   s   |  do
|  d S )N___)
startswith)name r   M/var/www/html/ai/venv/lib/python3.10/site-packages/torch/jit/supported_ops.py_hidden   s   r	   c                 C   s   t | S N)str)typer   r   r   
_emit_type   s   r   c                 C   sT   |j  dt|j }|j}|d ur| dt| }|dkr(dd|   | }|S )Nz : =r   
 )r   r   r   default_valuer   )indentiargvdefaultr   r   r   	_emit_arg   s   r   c                    s   d  fddt|D S )N,c                 3   s     | ]\}}t  ||V  qd S r
   )r   ).0r   r   r   r   r   	<genexpr>   s    z_emit_args.<locals>.<genexpr>)join	enumerate)r   	argumentsr   r   r   
_emit_args   s   r   c                 C   s
   t | jS r
   )r   r   )retr   r   r   	_emit_ret"   s   
r!   c                 C   s4   t | dkrt| d S dddd | D  dS )N   r   zTuple[z, c                 s   s    | ]}t |V  qd S r
   )r!   )r   rr   r   r   r   )   s    z_emit_rets.<locals>.<genexpr>])lenr!   r   )returnsr   r   r   
_emit_rets&   s   r'      c                 C   sP   | d u r|}n|  d| }d |tt|d | |j|d  t|j}|S )N.z{}({}) -> {}r"   )formatr   r%   r   r'   r&   )modr   schema	arg_startpaddingqualified_name
schema_strr   r   r   _emit_schema,   s   r1   c               
   C   sd   dd } g }t tjD ]"}t|s-tjd| }|D ]}| |r,|td||dd qqd|fS )Nc                 S   sF   t | jdkr	dS | jd }|jdkrdS |jtjj s!dS dS )Nr   FselfT)	r%   r   r   r   isSubtypeOftorch_C
TensorTypeget)r,   r2   r   r   r   is_tensor_method:   s   

z)_get_tensor_ops.<locals>.is_tensor_methodaten::Tensorr"   )r-   zSupported Tensor Methods)dirr4   r:   r	   r5   _jit_get_schemas_for_operatorappendr1   )r8   methodselemschemasr,   r   r   r   _get_tensor_ops9   s   
rA   c            
   	   C   s  g } t jj}|j}tt jjD ]A}t||}t|r!t|d r"qt	|}|s1t
d| dd|jvr7qzt j|}|j}| t||| W q   Y qt jjjD ]/}|j}t|D ]%}tt||}|d urt j|}	|	D ]}t|s| t||| qtq_qVd| fS )Nr   Module for 
 not foundztorch.nn.functionalzSupported PyTorch Functions)r4   nn
functional__name__r;   getattrinspect
isfunctionr	   	getmoduleRuntimeErrorjitscriptr,   r=   r1   	_builtins_modules_containing_builtinsr   r5   r<   )
	functionsr+   r   r?   attrattr_modulescriptedr,   builtinr@   r   r   r   _get_nn_functional_opsP   s<   


rU   c                  C   sr   g } t jjjD ]/\}}t|}t|dsq|sqt|js(t|j	s(t|jr)qd|jv r/q| 
||f q| S )NrF   ztorch._C)r4   rL   rN   _builtin_opsrH   rJ   hasattrr	   rF   __qualname__r=   )builtinsfn_builtin_namer+   r   r   r   _get_builtins_helper{   s   


r\   c                 C   s(   t | }|std|  d|jdkS )NrB   rC   math)rH   rJ   rK   rF   )rZ   r+   r   r   r   _is_math_fn   s   

r^   c            	      C   s   g } t dd t }t|}|D ]1\}}t|}|s#td| dt|}|d urAtj	|}|D ]}| 
t|j|j| q3qd| fS )Nc                 S   s   t | d  S Nr   r^   rZ   r   r   r   <lambda>   s    z+_get_torchscript_builtins.<locals>.<lambda>rB   rC   zTorchScript Builtin Functions)filterr\   listrH   rJ   rK   r   r4   r5   r<   r=   r1   rF   )	rP   rY   builtins_listrZ   r[   r+   rT   r@   r,   r   r   r   _get_torchscript_builtins   s   
rf   c            
      C   s   g } t dd t }t|}|D ]8\}}t|}|s#td| dt|}|d urHtj	|}|D ]}t
|j|j|}	d|	v rBq3| | q3qd| fS )Nc                 S   s   t | d S r_   r`   ra   r   r   r   rb      s    z$_get_math_builtins.<locals>.<lambda>rB   rC   r:   z``math`` Module)rc   r\   rd   rH   rJ   rK   r   r4   r5   r<   r1   rF   r=   )
rP   rY   re   rZ   r[   r+   rT   r@   r,   r0   r   r   r   _get_math_builtins   s$   

rg   c               
   C   sX  g d} dddddddd	d
}ddddddddd}g d}g }|D ]\}}| d| d| d q"g }g }| D ]A}d| }	||v rH|| }	tj|	}
|
D ]}| td ||dd qPt|
dkrj| d q9d| d||  d}| | q9d|}d|}d|}t|d}t|d}t|d}d| d| d | d!}d"|fS )#N)printtuplefloatcomplexintboolr   rG   rW   
isinstancer%   hexoctroundhashminmaxabsalldivmodrd   ordchrbinrangezipr   sortedz
aten::Boolz	aten::Intzaten::Floatzaten::Complexz	prim::absz	prim::maxz	prim::minzfake::does_not_exist)rm   rl   rj   rk   ru   rt   rs   r{   zPrint any valuez]Lists cannot be converted to tuples with this method since their size is not statically knownz'Attribute name must be a literal stringzResult is staticzMArguments must be iterable. See :ref:`Iterables <jit_iterables>` for details.z-Can only be used as an iterator in a for loop)rh   ri   rG   rW   rn   r|   r   r{   ))rk   __complex__)rj   	__float__)rl   __int__)rm   __bool__)r   __str__)r%   __len__)ro   __hex__)rp   __oct__"z", "``z``"r9   r   )r.    z":any:`z`", "r   	z
The functions in the following table are supported but do not have a static schema

.. csv-table::
    :header: "Function", "Note"

z

The following functions will use the corresponding magic method on :any:`TorchScript classes`

.. csv-table::
    :header: "Function", "Magic Method"

zX

These built-in functions use the schema

.. rst-class:: codeblock-height-limiter

::

z
    zPython Built-in Functions)	r=   r4   r5   r<   r1   r%   r   textwrapr   )supported_builtins
op_renamesschemaless_op_explanationsmagic_methodsmagic_methods_rowsrZ   magic_methodschematized_opsschemaless_opsop_namer@   s	table_rowschematized_ops_strschemaless_ops_strmagic_methods_rows_strsectionr   r   r   _get_global_builtins   sd    



r   c                  C   s   dd } d}t ttttf}|D ]J}| \}}|dddd dd}t|tr;| ddt	|  d| d}n| ddt	|  d| | }d	| d
d | }||7 }q|S )Nc                 S   s   d ddd | D S )Nz1
.. rst-class:: codeblock-height-limiter

::

{}
r   c                 s   s    | ]	}d | dV  qdS )z    

Nr   )r   dr   r   r   r   >  s    z:_list_supported_ops.<locals>.emit_block.<locals>.<genexpr>)r*   r   )declsr   r   r   
emit_block<  s   z'_list_supported_ops.<locals>.emit_blockr   `-r   r   ~z.. _:r   )
rA   rU   rf   r   rg   replacelowerrn   r   r%   )r   bodyop_gathering_fnsrZ   headeritemslink_targetr   r   r   r   _list_supported_ops;  s"   
 
  
r   )r   r(   )rH   r   	torch.jitr4   torch.jit._builtinsr   r	   r   r   r   r!   r'   r1   rA   rU   r\   r^   rf   rg   r   r   __doc__r   r   r   r   <module>   s(    

+w
