o
    2hv                     @  s  U d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	m
Z
mZ ddlmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZm Z m!Z!m"Z" dd	l#m$Z$m%Z%m&Z&m'Z'm(Z( dd
l)m*Z*m+Z+m,Z, erddl-Z-ddl.m/Z/m0Z0m1Z1 ddl#m2Z2m3Z3m4Z4m5Z5m6Z6 ede7e4 dZ8g dZ9ej:dkrddini Z;ej<dddddde;G dd dee& Z=[;G dd dZ>e> Z?de@d< e ZAde@d< [>erddlBmCZC eCdZDedZEeCdZFed ZGG d!d" d"eeDeEeFeGf ZHdd'd(ZIed)d*dd/d0ZJe	dd)d*dd3d0ZJ	dd)d*dd6d0ZJeIeJed7dd?d@ZK[J[Ie	ddddAddEdFZLeddGdFZL	ddddAddJdFZLddKdLZMejNddPdQZOddUdVZPddYdZZQdd]d^ZRddbdcZSddedfZTddjdkZUddldmZVddqdrZWddwdxZXddydzZYdd{d|ZZdd~dZ[dddZ\dddZ]dddZ^dddZ_dddZ`dddZadddZbdddZcdddZddddZedddZfe7de=e7deQeRe e$jgdehe=eheSeTe!e$jideje=ejeUeVe!e$jkdele=eleWeXee$jmdee=eecedee$jndee=ee[e\ee$jode	e=e	e]e^ee$jpde
e=e
eaebe!e$jqde%e=e%eeefe"e$jrdi	Zsde@d< e=eleYeZee$jmdZte=e	e_e`ee$jpdZudS )z&Registry for custom pytree node types.    )annotationsN)OrderedDictdefaultdictdeque
namedtuple)
itemgettermethodcaller)Lock)TYPE_CHECKINGAnyCallableClassVarGeneric
NamedTupleTypeVaroverload)	AutoEntryMappingEntryNamedTupleEntryPyTreeEntrySequenceEntryStructSequenceEntry)
PyTreeKindStructSequenceTis_namedtuple_classis_structseq_class)safe_ziptotal_order_sortedunzip2)
Collection	GeneratorIterable)KTVTCustomTreeNodeFlattenFuncUnflattenFuncCustomTreeNodeType)bound)register_pytree_noderegister_pytree_node_classunregister_pytree_nodedict_insertion_ordered   
   slotsT)initrepreqfrozenc                   @  sb   e Zd ZU dZded< ded< ded< ejdkrd	ed
< eZded< e	j
Zded< dZded< dS )PyTreeNodeRegistryEntryz>A dataclass that stores the information of a pytree node type.zbuiltins.type[Collection[T]]typeFlattenFunc[T]flatten_funcUnflattenFunc[T]unflatten_funcr.   zdataclasses.KW_ONLY_zbuiltins.type[PyTreeEntry]path_entry_typer   kind str	namespaceN)__name__
__module____qualname____doc____annotations__sysversion_infor   r=   r   CUSTOMr>   rA    rJ   rJ   J/var/www/html/chatgem/venv/lib/python3.10/site-packages/optree/registry.pyr6   @   s   
 
r6   c                   @  s$   e Zd ZU dZded< d	ddZdS )
GlobalNamespacerJ   zClassVar[tuple[()]]	__slots__returnr@   c                C     dS )Nz<GLOBAL NAMESPACE>rJ   )selfrJ   rJ   rK   __repr__W      zGlobalNamespace.__repr__N)rN   r@   )rB   rC   rD   rM   rF   rQ   rJ   rJ   rJ   rK   rL   T   s   
 rL   r@   __GLOBAL_NAMESPACEr	   __REGISTRY_LOCK)	ParamSpec_P_T_GetP_GetTc                   @  s    e Zd ZdddZdddZdS )_CallableWithGetargs_P.argskwargs	_P.kwargsrN   rW   c                O     t NNotImplementedErrorrP   r[   r]   rJ   rJ   rK   __call__i   rR   z_CallableWithGet.__call__
_GetP.args_GetP.kwargsrY   c                O  r_   r`   ra   rc   rJ   rJ   rK   getm   rR   z_CallableWithGet.getN)r[   r\   r]   r^   rN   rW   )r[   re   r]   rf   rN   rY   )rB   rC   rD   rd   rg   rJ   rJ   rJ   rK   rZ   h   s    
rZ   rg   Callable[_GetP, _GetT]rN   DCallable[[Callable[_P, _T]], _CallableWithGet[_P, _T, _GetP, _GetT]]c                  s   d fdd}|S )NfuncCallable[_P, _T]rN   &_CallableWithGet[_P, _T, _GetP, _GetT]c                  s
    | _ | S r`   rg   )rj   rm   rJ   rK   	decoratorx   s   z_add_get.<locals>.decorator)rj   rk   rN   rl   rJ   )rg   rn   rJ   rm   rK   _add_getq   s   ro   r?   )rA   clsr7   rA   PyTreeNodeRegistryEntry | Nonec               C     d S r`   rJ   rp   rA   rJ   rJ   rK   pytree_node_registry_get      rt   None#dict[type, PyTreeNodeRegistryEntry]c               C  rr   r`   rJ   rs   rJ   rJ   rK   rt      ru   type | NoneDdict[type, PyTreeNodeRegistryEntry] | PyTreeNodeRegistryEntry | Nonec                 s>  |t u rd}| dur| turt| std| dt|ts(td|d| du r^t|dh t  fddt	
 D }W d   n1 sJw   Y  t|r\t|t< t|t< |S |dkrot	|| f}|duro|S t|r| tu rztS | tu rtS t	| }|dur|S t| rt	tS t| rt	tS dS )a  Lookup the pytree node registry.

    >>> register_pytree_node.get()  # doctest: +IGNORE_WHITESPACE,ELLIPSIS
    {
        <class 'NoneType'>: PyTreeNodeRegistryEntry(
            type=<class 'NoneType'>,
            flatten_func=<function ...>,
            unflatten_func=<function ...>,
            path_entry_type=<class 'optree.PyTreeEntry'>,
            kind=<PyTreeKind.NONE: 2>,
            namespace=''
        ),
        <class 'tuple'>: PyTreeNodeRegistryEntry(
            type=<class 'tuple'>,
            flatten_func=<function ...>,
            unflatten_func=<function ...>,
            path_entry_type=<class 'optree.SequenceEntry'>,
            kind=<PyTreeKind.TUPLE: 3>,
            namespace=''
        ),
        <class 'list'>: PyTreeNodeRegistryEntry(
            type=<class 'list'>,
            flatten_func=<function ...>,
            unflatten_func=<function ...>,
            path_entry_type=<class 'optree.SequenceEntry'>,
            kind=<PyTreeKind.LIST: 4>,
            namespace=''
        ),
        ...
    }
    >>> register_pytree_node.get(defaultdict)  # doctest: +IGNORE_WHITESPACE,ELLIPSIS
    PyTreeNodeRegistryEntry(
        type=<class 'collections.defaultdict'>,
        flatten_func=<function ...>,
        unflatten_func=<function ...>,
        path_entry_type=<class 'optree.MappingEntry'>,
        kind=<PyTreeKind.DEFAULTDICT: 8>,
        namespace=''
    )
    >>> register_pytree_node.get(frozenset)  # frozenset is considered as a leaf node
    None

    Args:
        cls (type or None, optional): The class of the pytree node to retrieve. If not provided, all
            the registered pytree nodes in the namespace are returned.
        namespace (str, optional): The namespace of the registry to retrieve. If not provided, the
            global namespace is used.

    Returns:
        If the ``cls`` is not provided, a dictionary of all the registered pytree nodes in the
        namespace is returned. If the ``cls`` is provided, the corresponding registry entry is
        returned if the ``cls`` is registered as a pytree node. Otherwise, :data:`None` is returned,
        i.e., the ``cls`` is represented as a leaf node.
    r?   NzExpected a class or None, got .$The namespace must be a string, got c                   s   i | ]}|j  v r|j|qS rJ   )rA   r7   ).0handler
namespacesrJ   rK   
<dictcomp>   s
    
z,pytree_node_registry_get.<locals>.<dictcomp>)rS   r   inspectisclass	TypeError
isinstancer@   	frozensetrT   _NODETYPE_REGISTRYvalues_Cis_dict_insertion_ordered&_DICT_INSERTION_ORDERED_REGISTRY_ENTRYdict-_DEFAULTDICT_INSERTION_ORDERED_REGISTRY_ENTRYr   rg   r   r   r   )rp   rA   registryr}   rJ   r~   rK   rt      sN   <







)r=   r9   r8   r;   r:   type[Collection[T]]r=   type[PyTreeEntry]c               C  s   t | std| dt |rt|tstd|d|tur0t|ts0td|d|dkr8td|tu rA| }d}n|| f}t	 t
| |||| t| ||||dt|< W d   | S 1 sgw   Y  | S )	a  Extend the set of types that are considered internal nodes in pytrees.

    See also :func:`register_pytree_node_class` and :func:`unregister_pytree_node`.

    The ``namespace`` argument is used to avoid collisions that occur when different libraries
    register the same Python type with different behaviors. It is recommended to add a unique prefix
    to the namespace to avoid conflicts with other libraries. Namespaces can also be used to specify
    the same class in different namespaces for different use cases.

    .. warning::
        For safety reasons, a ``namespace`` must be specified while registering a custom type. It is
        used to isolate the behavior of flattening and unflattening a pytree node type. This is to
        prevent accidental collisions between different libraries that may register the same type.

    Args:
        cls (type): A Python type to treat as an internal pytree node.
        flatten_func (callable): A function to be used during flattening, taking an instance of ``cls``
            and returning a triple or optionally a pair, with (1) an iterable for the children to be
            flattened recursively, and (2) some hashable metadata to be stored in the treespec and
            to be passed to the ``unflatten_func``, and (3) (optional) an iterable for the tree path
            entries to the corresponding children. If the entries are not provided or given by
            :data:`None`, then `range(len(children))` will be used.
        unflatten_func (callable): A function taking two arguments: the metadata that was returned
            by ``flatten_func`` and stored in the treespec, and the unflattened children. The
            function should return an instance of ``cls``.
        path_entry_type (type, optional): The type of the path entry to be used in the treespec.
            (default: :class:`AutoEntry`)
        namespace (str): A non-empty string that uniquely identifies the namespace of the type registry.
            This is used to isolate the registry from other modules that might register a different
            custom behavior for the same type.

    Returns:
        The same type as the input ``cls``.

    Raises:
        TypeError: If the input type is not a class.
        TypeError: If the path entry class is not a subclass of :class:`PyTreeEntry`.
        TypeError: If the namespace is not a string.
        ValueError: If the namespace is an empty string.
        ValueError: If the type is already registered in the registry.

    Examples:
        >>> # Registry a Python type with lambda functions
        >>> register_pytree_node(
        ...     set,
        ...     lambda s: (sorted(s), None, None),
        ...     lambda _, children: set(children),
        ...     namespace='set',
        ... )
        <class 'set'>

        >>> # Register a Python type into a namespace
        >>> import torch
        >>> register_pytree_node(
        ...     torch.Tensor,
        ...     flatten_func=lambda tensor: (
        ...         (tensor.cpu().detach().numpy(),),
        ...         {'dtype': tensor.dtype, 'device': tensor.device, 'requires_grad': tensor.requires_grad},
        ...     ),
        ...     unflatten_func=lambda metadata, children: torch.tensor(children[0], **metadata),
        ...     namespace='torch2numpy',
        ... )
        <class 'torch.Tensor'>

        >>> # doctest: +SKIP
        >>> tree = {'weight': torch.ones(size=(1, 2)).cuda(), 'bias': torch.zeros(size=(2,))}
        >>> tree
        {'weight': tensor([[1., 1.]], device='cuda:0'), 'bias': tensor([0., 0.])}

        >>> # Flatten without specifying the namespace
        >>> tree_flatten(tree)  # `torch.Tensor`s are leaf nodes
        ([tensor([0., 0.]), tensor([[1., 1.]], device='cuda:0')], PyTreeSpec({'bias': *, 'weight': *}))

        >>> # Flatten with the namespace
        >>> tree_flatten(tree, namespace='torch2numpy')
        (
            [array([0., 0.], dtype=float32), array([[1., 1.]], dtype=float32)],
            PyTreeSpec(
                {
                    'bias': CustomTreeNode(Tensor[{'dtype': torch.float32, 'device': device(type='cpu'), 'requires_grad': False}], [*]),
                    'weight': CustomTreeNode(Tensor[{'dtype': torch.float32, 'device': device(type='cuda', index=0), 'requires_grad': False}], [*])
                },
                namespace='torch2numpy'
            )
        )

        >>> # Register the same type with a different namespace for different behaviors
        >>> def tensor2flatparam(tensor):
        ...     return [torch.nn.Parameter(tensor.reshape(-1))], tensor.shape, None
        ...
        ... def flatparam2tensor(metadata, children):
        ...     return children[0].reshape(metadata)
        ...
        ... register_pytree_node(
        ...     torch.Tensor,
        ...     flatten_func=tensor2flatparam,
        ...     unflatten_func=flatparam2tensor,
        ...     namespace='tensor2flatparam',
        ... )
        <class 'torch.Tensor'>

        >>> # Flatten with the new namespace
        >>> tree_flatten(tree, namespace='tensor2flatparam')
        (
            [
                Parameter containing: tensor([0., 0.], requires_grad=True),
                Parameter containing: tensor([1., 1.], device='cuda:0', requires_grad=True)
            ],
            PyTreeSpec(
                {
                    'bias': CustomTreeNode(Tensor[torch.Size([2])], [*]),
                    'weight': CustomTreeNode(Tensor[torch.Size([1, 2])], [*])
                },
                namespace='tensor2flatparam'
            )
        )
    Expected a class, got rz   (Expected a subclass of PyTreeEntry, got r{   r?   (The namespace cannot be an empty string.r=   rA   N)r   r   r   
issubclassr   rS   r   r@   
ValueErrorrT   r   register_noder6   r   )rp   r9   r;   r=   rA   registration_keyrJ   rJ   rK   r*      s>   

r*   r   
str | Nonetype[PyTreeEntry] | None2Callable[[CustomTreeNodeType], CustomTreeNodeType]c               C  rr   r`   rJ   rp   r=   rA   rJ   rJ   rK   r+        r+   c               C  rr   r`   rJ   r   rJ   rJ   rK   r+     r   CustomTreeNodeType | str | NoneGCustomTreeNodeType | Callable[[CustomTreeNodeType], CustomTreeNodeType]c                 s  | t u s	t| tr durtd| dkrtdd| }   du r&td t ur6t ts6td  dkr>td| du rLd fd
d}|S t| sYtd| ddu rct| dttrmt	t
sutddt| td| j d | S )a
  Extend the set of types that are considered internal nodes in pytrees.

    See also :func:`register_pytree_node` and :func:`unregister_pytree_node`.

    The ``namespace`` argument is used to avoid collisions that occur when different libraries
    register the same Python type with different behaviors. It is recommended to add a unique prefix
    to the namespace to avoid conflicts with other libraries. Namespaces can also be used to specify
    the same class in different namespaces for different use cases.

    .. warning::
        For safety reasons, a ``namespace`` must be specified while registering a custom type. It is
        used to isolate the behavior of flattening and unflattening a pytree node type. This is to
        prevent accidental collisions between different libraries that may register the same type.

    Args:
        cls (type, optional): A Python type to treat as an internal pytree node.
        path_entry_type (type, optional): The type of the path entry to be used in the treespec.
            (default: :class:`AutoEntry`)
        namespace (str, optional): A non-empty string that uniquely identifies the namespace of the
            type registry. This is used to isolate the registry from other modules that might
            register a different custom behavior for the same type.

    Returns:
        The same type as the input ``cls`` if the argument presents. Otherwise, return a decorator
        function that registers the class as a pytree node.

    Raises:
        TypeError: If the path entry class is not a subclass of :class:`PyTreeEntry`.
        TypeError: If the namespace is not a string.
        ValueError: If the namespace is an empty string.
        ValueError: If the type is already registered in the registry.

    This function is a thin wrapper around :func:`register_pytree_node`, and provides a
    class-oriented interface:

    .. code-block:: python

        @register_pytree_node_class(namespace='foo')
        class Special:
            TREE_PATH_ENTRY_TYPE = GetAttrEntry

            def __init__(self, x, y):
                self.x = x
                self.y = y

            def tree_flatten(self):
                return ((self.x, self.y), None, ('x', 'y'))

            @classmethod
            def tree_unflatten(cls, metadata, children):
                return cls(*children)

        @register_pytree_node_class('mylist')
        class MyList(UserList):
            TREE_PATH_ENTRY_TYPE = SequenceEntry

            def tree_flatten(self):
                return self.data, None, None

            @classmethod
            def tree_unflatten(cls, metadata, children):
                return cls(*children)
    Nz?Cannot specify `namespace` when the first argument is a string.r?   r   z<Must specify `namespace` when the first argument is a class.r{   rp   r(   rN   c                  s   t |  dS )Nr   )r+   )rp   rA   r=   rJ   rK   rn     s
   z-register_pytree_node_class.<locals>.decoratorr   rz   TREE_PATH_ENTRY_TYPEr   tree_flattenr   )rp   r(   rN   r(   )rS   r   r@   r   r   r   r   getattrr   r   r   r*   r   tree_unflatten)rp   r=   rA   rn   rJ   r   rK   r+     s:   F

c               C  s   t | std| d|turt|tstd|d|dkr&td|tu r/| }d}n|| f}t t	| | t
|W  d   S 1 sKw   Y  dS )a  Remove a type from the pytree node registry.

    See also :func:`register_pytree_node` and :func:`register_pytree_node_class`.

    This function is the inverse operation of function :func:`register_pytree_node`.

    Args:
        cls (type): A Python type to remove from the pytree node registry.
        namespace (str): The namespace of the pytree node registry to remove the type from.

    Returns:
        The removed registry entry.

    Raises:
        TypeError: If the input type is not a class.
        TypeError: If the namespace is not a string.
        ValueError: If the namespace is an empty string.
        ValueError: If the type is a built-in type that cannot be unregistered.
        ValueError: If the type is not found in the registry.

    Examples:
        >>> # Register a Python type with lambda functions
        >>> register_pytree_node(
        ...     set,
        ...     lambda s: (sorted(s), None, None),
        ...     lambda _, children: set(children),
        ...     namespace='temp',
        ... )
        <class 'set'>

        >>> # Unregister the Python type
        >>> unregister_pytree_node(set, namespace='temp')
    r   rz   r{   r?   r   N)r   r   r   rS   r   r@   r   rT   r   unregister_noder   pop)rp   rA   r   rJ   rJ   rK   r,   %  s   
"$r,   modeboolGenerator[None]c               c  s    |t urt|tstd|d|dkrtd|t u r d}t tj|dd}tt	| | W d   n1 s<w   Y  zdV  W t t|| W d   dS 1 sZw   Y  dS t t|| W d   w 1 stw   Y  w )a  Context manager to temporarily set the dictionary sorting mode.

    This context manager is used to temporarily set the dictionary sorting mode for a specific
    namespace. The dictionary sorting mode is used to determine whether the keys of a dictionary
    should be sorted or keeping the insertion order when flattening a pytree.

    >>> tree = {'b': (2, [3, 4]), 'a': 1, 'c': None, 'd': 5}
    >>> tree_flatten(tree)  # doctest: +IGNORE_WHITESPACE
    (
        [1, 2, 3, 4, 5],
        PyTreeSpec({'a': *, 'b': (*, [*, *]), 'c': None, 'd': *})
    )
    >>> with dict_insertion_ordered(True, namespace='some-namespace'):  # doctest: +IGNORE_WHITESPACE
    ...     tree_flatten(tree, namespace='some-namespace')
    (
        [2, 3, 4, 1, 5],
        PyTreeSpec({'b': (*, [*, *]), 'a': *, 'c': None, 'd': *}, namespace='some-namespace')
    )

    .. warning::
        The dictionary sorting mode is a global setting and is **not thread-safe**. It is
        recommended to use this context manager in a single-threaded environment.

    Args:
        mode (bool): The dictionary sorting mode to set.
        namespace (str): The namespace to set the dictionary sorting mode for.
    r{   rz   r?   r   F)inherit_global_namespaceN)
rS   r   r@   r   r   rT   r   r   set_dict_insertion_orderedr   )r   rA   prevrJ   rJ   rK   r-   Z  s$   (r-   itemsIterable[tuple[KT, VT]]list[tuple[KT, VT]]c                C  s   t | tddS )Nr   )key)r   r   )r   rJ   rJ   rK   _sorted_items  s   r   r<   tuple[tuple[()], None]c                C  rO   )N)rJ   NrJ   )r<   rJ   rJ   rK   _none_flatten  rR   r   childrenIterable[Any]c                C  s$   t  }tt|||urtdd S )NzExpected no children.)objectnextiterr   )r<   r   sentinelrJ   rJ   rK   _none_unflatten  s   r   tuptuple[T, ...]tuple[tuple[T, ...], None]c                C     | d fS r`   rJ   r   rJ   rJ   rK   _tuple_flatten     r   Iterable[T]c                C     t |S r`   )tupler<   r   rJ   rJ   rK   _tuple_unflatten  r   r   lstlist[T]tuple[list[T], None]c                C  r   r`   rJ   )r   rJ   rJ   rK   _list_flatten  r   r   c                C  r   r`   )listr   rJ   rJ   rK   _list_unflatten  r   r   dctdict[KT, VT]/tuple[tuple[VT, ...], list[KT], tuple[KT, ...]]c                C  s"   t t|  \}}|t||fS r`   )r   r   r   r   r   keysr   rJ   rJ   rK   _dict_flatten  s   r   r   list[KT]r   Iterable[VT]c                C     t t| |S r`   r   r   r   r   rJ   rJ   rK   _dict_unflatten     r   c                C     t |  \}}|t||fS r`   r   r   r   r   rJ   rJ   rK   _dict_insertion_ordered_flatten     r   c                C  r   r`   r   r   rJ   rJ   rK   !_dict_insertion_ordered_unflatten  r   r   OrderedDict[KT, VT]c                C  r   r`   r   r   rJ   rJ   rK   _ordereddict_flatten  r   r   c                C  r   r`   )r   r   r   rJ   rJ   rK   _ordereddict_unflatten  r   r   defaultdict[KT, VT]Otuple[tuple[VT, ...], tuple[Callable[[], VT] | None, list[KT]], tuple[KT, ...]]c                C     t | \}}}|| j|f|fS r`   )r   default_factoryr   r   r   entriesrJ   rJ   rK   _defaultdict_flatten     r   metadata!tuple[Callable[[], VT], list[KT]]c                C     | \}}t |t||S r`   )r   r   r   r   r   r   rJ   rJ   rK   _defaultdict_unflatten     r   c                C  r   r`   )r   r   r   rJ   rJ   rK   &_defaultdict_insertion_ordered_flatten  r   r   c                C  r   r`   )r   r   r   rJ   rJ   rK   (_defaultdict_insertion_ordered_unflatten  r   r   deqdeque[T]tuple[deque[T], int | None]c                C  s
   | | j fS r`   maxlen)r   rJ   rJ   rK   _deque_flatten  s   
r   r   
int | Nonec                C  s   t || dS )Nr   )r   )r   r   rJ   rJ   rK   _deque_unflatten     r   NamedTuple[T])tuple[tuple[T, ...], type[NamedTuple[T]]]c                C     | t | fS r`   r7   r   rJ   rJ   rK   _namedtuple_flatten  r   r   type[NamedTuple[T]]c                C  s   | | S r`   rJ   rp   r   rJ   rJ   rK   _namedtuple_unflatten  r   r  seqStructSequence[T]-tuple[tuple[T, ...], type[StructSequence[T]]]c                C  r   r`   r   )r  rJ   rJ   rK   _structseq_flatten  r   r  type[StructSequence[T]]c                C  s   | |S r`   rJ   r   rJ   rJ   rK   _structseq_unflatten  s   r  )r=   r>   z6dict[type | tuple[str, type], PyTreeNodeRegistryEntry]r   rJ   )rg   rh   rN   ri   )rp   r7   rA   r@   rN   rq   r`   )rp   rv   rA   r@   rN   rw   )rp   rx   rA   r@   rN   ry   )r9   r8   r;   r:   rp   r   r=   r   rA   r@   rN   r   )rp   r   r=   r   rA   r   rN   r   )rp   r(   r=   r   rA   r@   rN   r(   )rp   r   r=   r   rA   r   rN   r   )rp   r7   rA   r@   rN   r6   )r   r   rA   r@   rN   r   )r   r   rN   r   )r<   rv   rN   r   )r<   rv   r   r   rN   rv   )r   r   rN   r   )r<   rv   r   r   rN   r   )r   r   rN   r   )r<   rv   r   r   rN   r   )r   r   rN   r   )r   r   r   r   rN   r   )r   r   rN   r   )r   r   r   r   rN   r   )r   r   rN   r   )r   r   r   r   rN   r   )r   r   rN   r   )r   r   r   r   rN   r   )r   r   rN   r   )rp   r   r   r   rN   r   )r  r  rN   r  )rp   r  r   r   rN   r  )vrE   
__future__r   
contextlibdataclassesr   rG   collectionsr   r   r   r   operatorr   r   	threadingr	   typingr
   r   r   r   r   r   r   r   	optree._Cr   optree.accessorsr   r   r   r   r   r   optree.typingr   r   r   r   r   optree.utilsr   r   r   builtinscollections.abcr    r!   r"   r#   r$   r%   r&   r'   r7   r(   __all__rH   SLOTS	dataclassr6   rL   rS   rF   rT   typing_extensionsrU   rV   rW   rX   rY   rZ   ro   rt   r*   r+   r,   contextmanagerr-   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  NONEr   TUPLEr   LISTr   DICT
NAMEDTUPLEORDEREDDICTDEFAULTDICTDEQUESTRUCTSEQUENCEr   r   r   rJ   rJ   rJ   rK   <module>   sT  ( 
	
k !	

p5
.














	

	




	C
