a
    ==ic,  ã                   @   s&   d dl Z d dlmZ G dd„ dƒZdS )é    Nc                   @   st   e Zd ZdZdZg d¢Zg d¢Zee 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dd„ ZdS )ÚPythonDispatcherZ__test__Úfoo)ZCPUZAutogradCPUZFPGAZAutogradOtherZXLAZAutogradXLAZLazyZAutogradLazy)ÚCompositeExplicitAutogradZAutogradÚCompositeImplicitAutogradc                 C   s.   t  | j¡ t  d| jd¡| _| j d¡ d S )NZFRAGMENTÚ zfoo(Tensor x) -> Tensor)ÚCZ_dispatch_check_invariantsÚnameZ_dispatch_libraryÚ	namespaceÚrefZdef_©Úself© r   úi/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/torch/_python_dispatcher.pyÚ__init__C   s    zPythonDispatcher.__init__c                 C   s   | j S ©N)Úsupported_keysr   r   r   r   ÚkeysL   s    zPythonDispatcher.keysc                 C   s€   t t|ƒƒt |ƒkr$td|› dƒ‚d|v r<d|v r<tdƒ‚|D ]:}|| jvrdt|› d| j› dƒ‚| jjd|d| d	 q@d S )
Nz1Overriden is not allowed but found duplicates in Ú.r   r   z\Registration to both CompositeImplicitAutograd and CompositeExplicitAutograd is not allowed.z3 is not supported, please select a dispatch key in r   Zfn_)ÚdispatchÚdebug)ÚlenÚsetÚRuntimeErrorr   r
   Zimpl_t_t)r   ZdispatchKeysÚkeyr   r   r   ÚregisterV   s    
zPythonDispatcher.registerc                 C   s   d  ||¡S )Nz
{:<15} {}
)Úformat)r   r   Úkernelr   r   r   Ú_format_linee   s    zPythonDispatcher._format_linec                 C   s(   d|› d}||   dd¡7 }|d7 }|S )NÚ
r   r   z---------------------------
)r   )r   ÚheaderÚsr   r   r   Ú_format_headerk   s    ÿzPythonDispatcher._format_headerc                 C   s   t  d | j| j¡¡S ©Nz{}::{})r   Z_dispatch_dumpr   r	   r   r   r   r   r   ÚrawRegistrationsw   s    z!PythonDispatcher.rawRegistrationsc                 C   s   t  d | j| j¡¡S r"   )r   Z_dispatch_dump_tabler   r	   r   r   r   r   r   ÚrawDispatchTable~   s    z!PythonDispatcher.rawDispatchTablec                    sx   |   d¡}|  ¡ }| d¡}|D ]R}| d¡d ‰ t‡ fdd„| jD ƒƒr | d¡d  d¡d	 }||  ˆ |¡7 }q |S )
NzRegistered Kernelsr   ú:r   c                 3   s   | ]}ˆ   |¡V  qd S r   )Ú
startswith)Ú.0Úk©Úfirstr   r   Ú	<genexpr>‹   ó    z1PythonDispatcher.registrations.<locals>.<genexpr>z::ú é   )r!   r#   ÚsplitÚanyr   r   )r   ÚoutputÚstateZstate_entriesÚliner   r   r)   r   Úregistrations…   s    

zPythonDispatcher.registrationsc                 C   sr   |   d¡}|  ¡ }| d¡}t d¡}|D ]B}| d¡d }|| jv r*| d|¡}||  || d¡d ¡7 }q*|S )	NzComputed Dispatch Tabler   z)registered at .*FallbackKernel\.cpp.*(\[)r%   r   ú[z: r.   )r!   r$   r/   ÚreÚcompileÚruntime_keysÚsubr   )r   r1   ÚtableZtable_entriesÚregexr3   r(   Úentryr   r   r   ÚdispatchTable•   s    



zPythonDispatcher.dispatchTableN)Ú__name__Ú
__module__Ú__qualname__r	   r   r8   Z
alias_keysr   r   r   r   r   r!   r#   r$   r4   r=   r   r   r   r   r   3   s   	
r   )r6   Ztorch._CZ_Cr   r   r   r   r   r   Ú<module>   s   1