
    ia
                         U d dl mZmZ ddlmZ ddlmZ g dZ G d d      Z e       Z	ee
d<    G d	 d
      Z G d d      Zdedee   fdZy)    )CallableOptional   )FakeImplHolder)RegistrationHandle)SimpleLibraryRegistrySimpleOperatorEntry	singletonc                   &    e Zd ZdZd ZdeddfdZy)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                     i | _         y N_dataselfs    X/var/www/html/engine/venv/lib/python3.12/site-packages/torch/_library/simple_registry.py__init__zSimpleLibraryRegistry.__init__   s	    
    qualnamereturnr	   c                 v    | j                   j                  |d       }|t        |      x| j                   |<   }|S r   )r   getr	   )r   r   ress      r   findzSimpleLibraryRegistry.find   s8    jjnnXt,;)<X)FFDJJx 3
r   N)__name__
__module____qualname____doc__r   strr    r   r   r   r      s     S %: r   r   r
   c                   ,    e Zd ZdZdefdZed        Zy)r	   zThis is 1:1 to an operator overload.

    The fields of SimpleOperatorEntry are Holders where kernels can be
    registered to.
    r   c                 R    || _         t        |      | _        t        |      | _        y r   )r   r   	fake_implGenericTorchDispatchRuleHoldertorch_dispatch_rulesr   r   s     r   r   zSimpleOperatorEntry.__init__/   s%    %)7)A*84 	!r   c                     | j                   S r   )r#   r   s    r   abstract_implz!SimpleOperatorEntry.abstract_impl7   s    ~~r   N)r   r   r   r   r   r   propertyr(   r    r   r   r	   r	   (   s'    
 
  r   r	   c                   ,    e Zd Zd ZdededefdZd Zy)r$   c                      i | _         || _        y r   )r   r   r&   s     r   r   z'GenericTorchDispatchRuleHolder.__init__=   s    
 r   torch_dispatch_classfuncr   c                       j                        rt         d j                         | j                  <    fd}t	        |      S )Nz8 already has a `__torch_dispatch__` rule registered for c                        j                   = y r   r   r   r,   s   r   
deregisterz;GenericTorchDispatchRuleHolder.register.<locals>.deregisterJ   s    

/0r   )r   RuntimeErrorr   r   r   )r   r,   r-   r1   s   ``  r   registerz'GenericTorchDispatchRuleHolder.registerA   sZ     99)*'((`aeanan`op  ,0

'(	1 "*--r   c                 :    | j                   j                  |d       S r   )r   r   r0   s     r   r   z#GenericTorchDispatchRuleHolder.findO   s    zz~~2D99r   N)	r   r   r   r   typer   r   r3   r   r    r   r   r$   r$   <   s)    !.$(.08.	.:r   r$   r,   r   c                 r    t         j                  | j                        j                  j                  |      S r   )r
   r   r   r%   )opr,   s     r   find_torch_dispatch_ruler8   S   s+    >>"//*??DD r   N)typingr   r   r#   r   utilsr   __all__r   r
   __annotations__r	   r$   r5   r8   r    r   r   <module>r=      s_    % % % % H 4 $9#:	  : (: :.t @R r   