o
    Zh(                     @   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   F/var/www/auris/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   sV   | d u r|}n|  d| }| dt t|d | |j|d   dt|j }|S )N.(r"   z) -> )r   r%   r   r'   r&   )modr   schema	arg_startpaddingZqualified_name
schema_strr   r   r   _emit_schema.   s   r0   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   ZisSubtypeOftorch_CZ
TensorTypeget)r,   r1   r   r   r   is_tensor_method<   s   

z)_get_tensor_ops.<locals>.is_tensor_methodaten::Tensorr"   )r-   zSupported Tensor Methods)dirr2   r7   r	   r3   _jit_get_schemas_for_operatorappendr0   )r5   methodselemschemasr,   r   r   r   _get_tensor_ops;   s   
r>   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)r2   nnZ
functional__name__r8   getattrinspect
isfunctionr	   	getmoduleRuntimeErrorjitscriptr,   r:   r0   	_builtinsZ_modules_containing_builtinsr   r3   r9   )	functionsr+   r   r<   attrZattr_moduleZscriptedZscripted_schemabuiltinr=   r,   r   r   r   _get_nn_functional_opsR   s<   


rN   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 )NrB   ztorch._C)r2   rH   rJ   Z_builtin_opsrD   rF   hasattrr	   rB   __qualname__r:   )builtinsfn_builtin_namer+   r   r   r   _get_builtins_helper}   s   


rT   c                 C   s(   t | }|std|  d|jdkS )Nr?   r@   math)rD   rF   rG   rB   )rR   r+   r   r   r   _is_math_fn   s   

rV   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   rV   rR   r   r   r   <lambda>   s    z+_get_torchscript_builtins.<locals>.<lambda>r?   r@   zTorchScript Builtin Functions)filterrT   listrD   rF   rG   r   r2   r3   r9   r:   r0   rB   )	rK   rQ   builtins_listrR   rS   r+   rM   r=   r,   r   r   r   _get_torchscript_builtins   s   
r^   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 rW   rX   rY   r   r   r   rZ      s    z$_get_math_builtins.<locals>.<lambda>r?   r@   r7   z``math`` Module)r[   rT   r\   rD   rF   rG   r   r2   r3   r9   r0   rB   r:   )
rK   rQ   r]   rR   rS   r+   rM   r=   r,   r/   r   r   r   _get_math_builtins   s"   
r_   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   rC   rO   
isinstancer%   hexoctroundhashminmaxabsalldivmodr\   ordchrbinrangezipr   sortedz
aten::Boolz	aten::Intzaten::Floatzaten::Complexz	prim::absz	prim::maxz	prim::minzfake::does_not_exist)re   rd   rb   rc   rm   rl   rk   rs   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`   ra   rC   rO   rf   rt   r   rs   ))rc   __complex__)rb   	__float__)rd   __int__)re   __bool__)r   __str__)r%   __len__)rg   Z__hex__)rh   Z__oct__"z", "``z``"r6   r   )r.    z":external+python:py:obj:`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:   r2   r3   r9   r0   r%   r   textwrapr   )Zsupported_builtinsZ
op_renamesZschemaless_op_explanationsZmagic_methodsZmagic_methods_rowsrR   Zmagic_methodZschematized_opsZschemaless_opsZop_namer=   sZ	table_rowZschematized_ops_strZschemaless_ops_strZmagic_methods_rows_strsectionr   r   r   _get_global_builtins   sf    



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>)formatr   )Zdeclsr   r   r   
emit_block>  s   z'_list_supported_ops.<locals>.emit_blockr}   `-r   r   ~z.. _:r   )
r>   rN   r^   r   r_   replacelowerrf   r   r%   )r   bodyZop_gathering_fnsrR   headeritemsZlink_targetr   r   r   r   _list_supported_ops=  s"   
 
  
r   )r   r(   )rD   r   Z	torch.jitr2   Ztorch.jit._builtinsr   r	   r   r   r   r!   r'   r0   r>   rN   rT   rV   r^   r_   r   r   __doc__r   r   r   r   <module>   s(   

+y
