a
    dr(                     @   s   d dl Zd dlmZ d dlZd dl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   `/var/www/html/stable-diffusion-webui/venv/lib/python3.9/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   sN   d |jt|j}|j}|d ur2d |t|}|dkrJd d|  |}|S )Nz{} : {}z{}={}r   z
{}{} )formatr   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>       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   s2   t | dkrt| d S 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   !   r   z_emit_rets.<locals>.<genexpr>)lenr!   r   r   )returnsr   r   r   
_emit_rets   s    r&      c                 C   sN   | d u r|}nd | |}d |tt|d | |j|d  t|j}|S )Nz{}.{}z{}({}) -> {}r"   )r   r   r$   r   r&   r%   )modr   schema	arg_startpaddingZqualified_name
schema_strr   r   r   _emit_schema#   s    r-   c               
   C   sd   dd } g }t tjD ]D}t|stjd| }|D ]"}| |r6|td||dd q6q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 sBdS dS )Nr   FselfT)	r$   r   r   r   ZisSubtypeOftorch_CZ
TensorTypeget)r)   r.   r   r   r   is_tensor_method.   s    

z)_get_tensor_ops.<locals>.is_tensor_methodzaten::Tensorr"   )r*   zSupported Tensor Methods)dirr/   r3   r	   r0   _jit_get_schemas_for_operatorappendr-   )r2   methodselemschemasr)   r   r   r   _get_tensor_ops-   s    
r:   c            
   	   C   s  g } t jj}|j}tt jjD ]}t||}t|rt|d rDqt	|}|sbt
d| dd|jvrnqz(t j|}|j}| t||| W q   Y q0 qt jjjD ]^}|j}t|D ]J}tt||}|d urt j|}	|	D ]}t|s| t||| qqqd| fS )Nr   Module for 
 not foundztorch.nn.functionalzSupported PyTorch Functions)r/   nnZ
functional__name__r4   getattrinspect
isfunctionr	   	getmoduleRuntimeErrorjitscriptr)   r6   r-   	_builtinsZ_modules_containing_builtinsr   r0   r5   )
	functionsr(   r   r8   attrZattr_moduleZscriptedr)   builtinr9   r   r   r   _get_nn_functional_opsC   s8    


rJ   c                  C   sr   g } t jjjD ]^\}}t|}t|ds,q|s2qt|jst|j	st|jrRqd|jv r^q| 
||f q| S )Nr>   ztorch._C)r/   rD   rF   Z_builtin_opsr@   rB   hasattrr	   r>   __qualname__r6   )builtinsfn_builtin_namer(   r   r   r   _get_builtins_helperm   s    


rP   c                 C   s(   t | }|std|  d|jdkS )Nr;   r<   math)r@   rB   rC   r>   )rN   r(   r   r   r   _is_math_fn   s    
rR   c            	      C   s   g } t dd t }t|}|D ]b\}}t|}|sFtd| dt|}|d ur tj	|}|D ]}| 
t|j|j| qfq d| fS )Nc                 S   s   t | d  S Nr   rR   rN   r   r   r   <lambda>   r   z+_get_torchscript_builtins.<locals>.<lambda>r;   r<   zTorchScript Builtin Functions)filterrP   listr@   rB   rC   r   r/   r0   r5   r6   r-   r>   )	rG   rM   builtins_listrN   rO   r(   rI   r9   r)   r   r   r   _get_torchscript_builtins   s    
rZ   c            
      C   s   g } t dd t }t|}|D ]p\}}t|}|sFtd| dt|}|d ur tj	|}|D ](}t
|j|j|}	d|	v rqf| | qfq d| fS )Nc                 S   s   t | d S rS   rT   rU   r   r   r   rV      r   z$_get_math_builtins.<locals>.<lambda>r;   r<   r3   z``math`` Module)rW   rP   rX   r@   rB   rC   r   r/   r0   r5   r-   r>   r6   )
rG   rM   rY   rN   rO   r(   rI   r9   r)   r,   r   r   r   _get_math_builtins   s"    

r[   c               
   C   sB  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|| qDg }g }| D ]|}d|}	||v r|| }	tj|	}
|
D ]}| td ||dd qt|
dkr| d qld||| }| | qld|}d|}d|}t	|d}t	|d}t	|d}d|||}d|fS )N)printtuplefloatcomplexintboolr   r?   rK   
isinstancer$   hexoctroundhashminmaxabsalldivmodrX   ordchrbinrangezipr   sortedz
aten::Boolz	aten::Intzaten::Floatzaten::Complexz	prim::absz	prim::maxz	prim::minzfake::does_not_exist)ra   r`   r^   r_   ri   rh   rg   ro   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)r\   r]   r?   rK   rb   rp   r   ro   ))r_   __complex__)r^   	__float__)r`   __int__)ra   __bool__)r   __str__)r$   __len__)rc   Z__hex__)rd   Z__oct__z"{}", "``{}``"zaten::{}r   )r+    z":any:`{}`", "{}"
	a  
The functions in the following table are supported but do not have a static schema

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

{}

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

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

{}

These built-in functions use the schema

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

::

{}
    zPython Built-in Functions)
r6   r   r/   r0   r5   r-   r$   r   textwrapr   )Zsupported_builtinsZ
op_renamesZschemaless_op_explanationsZmagic_methodsZmagic_methods_rowsrN   Zmagic_methodZschematized_opsZschemaless_opsZop_namer9   sZ	table_rowZschematized_ops_strZschemaless_ops_strZmagic_methods_rows_strsectionr   r   r   _get_global_builtins   s\     



r~   c                  C   s   dd } d}t ttttf}|D ]}| \}}|dddd dd}t|trnd	|dt
| |}nd		|dt
| | |}d
	|d | }||7 }q|S )Nc                 S   s   d ddd | D S )Nz1
.. rst-class:: codeblock-height-limiter

::

{}
rx   c                 s   s   | ]}d  |V  qdS )z    {}

N)r   )r   dr   r   r   r   .  r   z:_list_supported_ops.<locals>.emit_block.<locals>.<genexpr>)r   r   )Zdeclsr   r   r   
emit_block-  s    z'_list_supported_ops.<locals>.emit_blockrx   `-r   z	{}
{}
{}
~z{}
{}
{}z.. _{}:z

)r:   rJ   rZ   r~   r[   replacelowerrb   r   r   r$   )r   bodyZop_gathering_fnsrN   headeritemsZlink_targetr}   r   r   r   _list_supported_ops,  s"    
 

r   )r   r'   )Z	torch.jitr/   Ztorch.jit._builtinsr   r@   r{   r	   r   r   r   r!   r&   r-   r:   rJ   rP   rR   rZ   r[   r~   r   __doc__r   r   r   r   <module>   s&   	

*w