a
    hN
                     @   s   U d dl mZ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eee dddZdS )    )CallableOptional   )FakeImplHolder)RegistrationHandle)SimpleLibraryRegistrySimpleOperatorEntry	singletonc                   @   s(   e Zd ZdZdd Zedd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.
    c                 C   s
   i | _ d S N_dataself r   L/var/www/auris/lib/python3.9/site-packages/torch/_library/simple_registry.py__init__   s    zSimpleLibraryRegistry.__init__r   )qualnamereturnc                 C   s"   || j vrt|| j |< | j | S r
   )r   r   r   r   r   r   r   find   s    
zSimpleLibraryRegistry.findN)__name__
__module____qualname____doc__r   strr   r   r   r   r   r      s   r   r	   c                   @   s*   e Zd ZdZedddZe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   c                 C   s   || _ t|| _t|| _d S r
   )r   r   	fake_implGenericTorchDispatchRuleHoldertorch_dispatch_rulesr   r   r   r   r   .   s    
zSimpleOperatorEntry.__init__c                 C   s   | j S r
   )r   r   r   r   r   abstract_impl6   s    z!SimpleOperatorEntry.abstract_implN)r   r   r   r   r   r   propertyr   r   r   r   r   r   '   s   r   c                   @   s.   e Zd Zdd ZeeedddZdd ZdS )	r   c                 C   s   i | _ || _d S r
   )r   r   r   r   r   r   r   <   s    z'GenericTorchDispatchRuleHolder.__init__)torch_dispatch_classfuncr   c                    s>     rt d j | j<  fdd}t|S )Nz8 already has a `__torch_dispatch__` rule registered for c                      s    j = d S r
   r   r   r   r    r   r   
deregisterI   s    z;GenericTorchDispatchRuleHolder.register.<locals>.deregister)r   RuntimeErrorr   r   r   )r   r    r!   r#   r   r"   r   register@   s    

z'GenericTorchDispatchRuleHolder.registerc                 C   s   | j |d S r
   )r   getr"   r   r   r   r   N   s    z#GenericTorchDispatchRuleHolder.findN)	r   r   r   r   typer   r   r%   r   r   r   r   r   r   ;   s
   r   )r    r   c                 C   s   t | jj|S r
   )r	   r   r   r   )opr    r   r   r   find_torch_dispatch_ruleR   s    r)   N)typingr   r   r   r   utilsr   __all__r   r	   __annotations__r   r   r'   r)   r   r   r   r   <module>   s   