Ë
    †\;jD  ã                   ó†   — d dl Z ddlmZ g Z G d„ d«      Z G d„ d«      Z e«       a e«       ad„ Zd	„ Z	dd
„Z
edd„«       Zy)é    Né   )Úsignature_safe_contextmanagerc                   ó   — e Zd ZdZdd„Zd„ Zy)ÚUniqueNameGeneratorz°
    Generate unique name with prefix.

    Args:
        prefix(str): The generated name prefix. All generated name will be
                     started with this prefix.
    Nc                 óV   — t        j                  t        «      | _        |€d}|| _        y )NÚ )ÚcollectionsÚdefaultdictÚintÚidsÚprefix)Úselfr   s     ú`G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/base/unique_name.pyÚ__init__zUniqueNameGenerator.__init__   s%   € Ü×*Ñ*¬3Ó/ˆŒØˆ>ØˆFØˆ�ó    c                 ó    — | j                   |   }| j                   |xx   dz  cc<   | j                  dj                  |t        |«      g«      z   S )z©
        Generate unique names with prefix

        Args:
            key(str): The key of return string.

        Returns(str): A unique string with the prefix
        r   Ú_)r   r   ÚjoinÚstr)r   ÚkeyÚtmps      r   Ú__call__zUniqueNameGenerator.__call__%   sC   € ð �h‰h�s‰mˆØ�‰�‹˜Ñ‹Ø�{‰{˜SŸX™X s¬C°«H oÓ6Ñ6Ð6r   ©N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   © r   r   r   r      s   „ ñóó7r   r   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚDygraphParameterNameCheckerz6
    Check whether the name of parameter is used.
    c                 ó"   — t        «       | _        y r   )ÚsetÚ	_name_set)r   s    r   r   z$DygraphParameterNameChecker.__init__8   s   € Ü›ˆ�r   c                 óX   — || j                   v ry| j                   j                  |«       y)zû
        Check whether the name is used. If not used, insert into the _name_set.

        Args:
            name(str): The name of parameter to check.

        Returns(bool): If the name is in name_set,  return True; Otherwise, return False.

        TF)r$   Úadd)r   Únames     r   r   z$DygraphParameterNameChecker.__call__;   s(   € ð �4—>‘>Ñ!Øà�N‰N×Ñ˜tÔ$Ør   Nr   r   r   r   r!   r!   3   s   „ ñòór   r!   c                 ó   — t        | «      S )aZ  
    Generate unique name with prefix key. Currently, Paddle distinguishes the
    names of the same key by numbering it from zero. For example, when key=fc,
    it continuously generates fc_0, fc_1, fc_2, etc.

    Args:
        key(str): The prefix of generated name.

    Returns:
        str: A unique string with the prefix key.

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> name1 = paddle.utils.unique_name.generate('fc')
            >>> name2 = paddle.utils.unique_name.generate('fc')
            >>> print(name1, name2)
            fc_0 fc_1
    )Ú	generator)r   s    r   Úgenerater*   Q   s   € ô, �S‹>Ðr   c                 ó`   — ddl m}m}  |«       r |«       j                  «       S t	        | «      S )Nr   )Ú_dygraph_tracerÚin_dygraph_mode)Ú	frameworkr,   r-   Ú_generate_unique_namer)   )r   r,   r-   s      r   Úgenerate_with_ignorable_keyr0   |   s'   € ß;áÔÙÓ ×6Ñ6Ó8Ð8ä�S‹>Ðr   c                 ód   — t         }t        }| €t        «       a n| a |€t        «       a||fS |a||fS )a/  
    Switch the namespace of in current context to a new namespace. Though
    :code:`switch()` and :code:`guard()` can both change namespace,
    :code:`guard()` is recommended since it can manage the context better
    together with :code:`with` statement.

    Args:
        new_generator(UniqueNameGenerator, optional): A new UniqueNameGenerator, not
            required normally. Default is None, which means switch to a new anonymous
            namespace.
        new_para_name_checker(DygraphParameterNameChecker, optional): A new DygraphParameterNameChecker,
            not required normally. Default is None, which means  switch to a new parameter name
            checker.

    Returns:
        UniqueNameGenerator: The previous UniqueNameGenerator.
        DygraphParameterNameChecker: The previous DygraphParameterNameChecker

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> name1 = paddle.utils.unique_name.generate('fc')
            >>> name2 = paddle.utils.unique_name.generate('fc')
            >>> print(name1, name2)
            fc_0 fc_1

            >>> pre_generator, pre_dygraph_name_checker = paddle.utils.unique_name.switch() # switch to a new anonymous namespace.
            >>> name2 = paddle.utils.unique_name.generate('fc')
            >>> print(name2)
            fc_0

            >>> paddle.utils.unique_name.switch(pre_generator, pre_dygraph_name_checker) # switch back to pre_generator.
            >>> name3 = paddle.utils.unique_name.generate('fc')
            >>> print(name3)
            fc_2
    )r)   Údygraph_parameter_name_checkerr   r!   )Únew_generatorÚnew_para_name_checkerÚold_generatorÚold_para_name_checkers       r   Úswitchr7   …   sT   € ôP €Mä:ÐØÐÜ'Ó)‰	à!ˆ	àÐ$Ü)DÓ)FÐ&ð Ð/Ð/Ð/ð *?Ð&ØÐ/Ð/Ð/r   c              #   óö   K  — t        | t        «      rt        | «      } n)t        | t        «      rt        | j	                  «       «      } t        | «      \  }}	 d–— t        ||«       y# t        ||«       w xY w­w)a%  
    Change the namespace of unique name with :code:`with` statement. After calling it,
    a new namespace in the context of :code:`with` will be created, and it will number
    names from zero again when calling :code:`generate()` with same key.

    Args:
        new_generator(str|bytes, optional): New name of global namespace. Note that str
            in Python2 was spilted into str and bytes in Python3, so here are two
            types. Default is None. If not None, new_generator will be added into
            the prefix of unique name generated by :code:`generate()`.

    Returns:
        None.

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> with paddle.utils.unique_name.guard():
            ...     name_1 = paddle.utils.unique_name.generate('fc')
            >>> with paddle.utils.unique_name.guard():
            ...     name_2 = paddle.utils.unique_name.generate('fc')
            >>> print(name_1, name_2)
            fc_0 fc_0

            >>> with paddle.utils.unique_name.guard('A'):
            ...     name_1 = paddle.utils.unique_name.generate('fc')
            >>> with paddle.utils.unique_name.guard('B'):
            ...     name_2 = paddle.utils.unique_name.generate('fc')
            >>> print(name_1, name_2)
            Afc_0 Bfc_0
    N)Ú
isinstancer   r   ÚbytesÚdecoder7   )r3   r5   r6   s      r   Úguardr<   ¼   sh   è ø€ ôF �-¤Ô%Ü+¨MÓ:‰Ü	�M¤5Ô	)Ü+¨M×,@Ñ,@Ó,BÓCˆä+1°-Ó+@Ñ(€MÐ(ð5Ûäˆ}Ð3Õ4øŒˆ}Ð3Õ4üs   ‚AA9ÁA( ÁA9Á(A6Á6A9)NNr   )r	   Úwrapped_decoratorr   Ú__all__r   r!   r2   r)   r*   r0   r7   r<   r   r   r   Ú<module>r?      s^   ðó å <à
€÷7ñ 7÷:ñ ñ2 "=Ó!>Ð áÓ!€	òòVó40ðn ò+5ó ñ+5r   