o
    ei                  	   @   s   U d dl mZ d dlmZmZ ddlmZ ddlmZ ddl	m
Z
 g dZG dd	 d	Ze Zeed
< G dd dZG dd dZdededeedef  fddZdS )    )Callable)AnyOptional   )EffectHolder)FakeImplHolder)RegistrationHandle)SimpleLibraryRegistrySimpleOperatorEntry	singletonc                   @   s,   e Zd ZdZd
ddZdeddfdd	ZdS )r	   aJ  Registry for the "simple" torch.library APIs

    The "simple" torch.library APIs are a higher-level API on top of the
    raw PyTorch DispatchKey registration APIs that includes:
    - fake impl

    Registrations for these APIs do not go into the PyTorch dispatcher's
    table because they may not directly involve a DispatchKey. For example,
    the fake impl is a Python function that gets invoked by FakeTensor.
    Instead, we manage them here.

    SimpleLibraryRegistry is a mapping from a fully qualified operator name
    (including the overload) to SimpleOperatorEntry.
    returnNc                 C   s
   i | _ d S N_dataself r   h/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/_library/simple_registry.py__init__   s   
zSimpleLibraryRegistry.__init__qualnamer
   c                 C   s,   | j |d }|d u rt| | j |< }|S r   )r   getr
   )r   r   resr   r   r   find   s   zSimpleLibraryRegistry.findr   N)__name__
__module____qualname____doc__r   strr   r   r   r   r   r	      s    
r	   r   c                   @   s4   e Zd ZdZdeddfddZedefddZdS )	r
   zThis is 1:1 to an operator overload.

    The fields of SimpleOperatorEntry are Holders where kernels can be
    registered to.
    r   r   Nc                 C   s(   || _ t|| _t|| _t|| _d S r   )r   r   	fake_implGenericTorchDispatchRuleHoldertorch_dispatch_rulesr   effectr   r   r   r   r   r   0   s
   
zSimpleOperatorEntry.__init__c                 C   s   | j S r   )r   r   r   r   r   abstract_impl:   s   z!SimpleOperatorEntry.abstract_impl)	r   r   r   r   r   r   propertyr   r$   r   r   r   r   r
   )   s
    
r
   c                   @   sZ   e Zd ZdeddfddZdededef defd	d
Z	dede
edef  fddZdS )r    r   r   Nc                 C   s   i | _ || _d S r   )r   r   r#   r   r   r   r   @   s   
z'GenericTorchDispatchRuleHolder.__init__torch_dispatch_classfunc.c                    s@     rt d j | j< d fdd}t|S )Nz8 already has a `__torch_dispatch__` rule registered for r   c                      s    j = d S r   r   r   r   r&   r   r   
deregisterM   s   z;GenericTorchDispatchRuleHolder.register.<locals>.deregisterr   )r   RuntimeErrorr   r   r   )r   r&   r'   r)   r   r(   r   registerD   s   

z'GenericTorchDispatchRuleHolder.registerc                 C   s   | j |d S r   )r   r   r(   r   r   r   r   R   s   z#GenericTorchDispatchRuleHolder.find)r   r   r   r   r   typer   r   r   r+   r   r   r   r   r   r   r    ?   s    

"r    opr&   r   .c                 C   s   t | jj|S r   )r   r   r   r!   )r-   r&   r   r   r   find_torch_dispatch_ruleV   s   r.   N)collections.abcr   typingr   r   effectsr   r   r   utilsr   __all__r	   r   __annotations__r
   r    r,   r.   r   r   r   r   <module>   s"    