o
    Ù­j¶  ã                   @   s,  d Z ddlZddlZddl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 ddlmZmZmZmZ dddddd	œd
ee dee dee dee dee de	egef fdd„Zeddd�deddfdd„ƒZeddd�de
eef fdd„ƒZeeddddd �deded fd!d"„ƒƒZdS )#z Global configuration for XGBoosté    N)Úcontextmanager)Úwraps)ÚAnyÚCallableÚDictÚIteratorÚOptionalÚcasté   )Ú_F)Ú_LIBÚ_check_callÚc_strÚpy_str)ÚheaderÚ
extra_noteÚ
parametersÚreturnsÚsee_alsor   r   r   r   r   Úreturnc              	      sF   d‰d‰ dt t dtfdd„‰dtdtf‡ ‡‡‡‡‡‡‡fdd	„}|S )
aD  Decorator to format docstring for config functions.

    Parameters
    ----------
    header: str
        An introducion to the function
    extra_note: str
        Additional notes
    parameters: str
        Parameters of the function
    returns: str
        Return value
    see_also: str
        Related functions
    a  
    {header}

    Global configuration consists of a collection of parameters that can be applied in the
    global scope. See :ref:`global_config` for the full list of parameters supported in
    the global configuration.

    {extra_note}

    .. versionadded:: 1.4.0
    af  
    Example
    -------

    .. code-block:: python

        import xgboost as xgb

        # Show all messages, including ones pertaining to debugging
        xgb.set_config(verbosity=2)

        # Get current value of global configuration
        # This is a dict containing all parameters in the global configuration,
        # including 'verbosity'
        config = xgb.get_config()
        assert config['verbosity'] == 2

        # Example of using the context manager xgb.config_context().
        # The context manager will restore the previous value of the global
        # configuration upon exiting.
        with xgb.config_context(verbosity=0):
            # Suppress warning caused by model generated with XGBoost version < 1.0.0
            bst = xgb.Booster(model_file='./old_model.bin')
        assert xgb.get_config()['verbosity'] == 2  # old value restored

    Nested configuration context is also supported:

    Example
    -------

    .. code-block:: python

        with xgb.config_context(verbosity=3):
            assert xgb.get_config()["verbosity"] == 3
            with xgb.config_context(verbosity=2):
                assert xgb.get_config()["verbosity"] == 2

        xgb.set_config(verbosity=2)
        assert xgb.get_config()["verbosity"] == 2
        with xgb.config_context(verbosity=3):
            assert xgb.get_config()["verbosity"] == 3
    Úvaluer   c                 S   s   | d u rdS | S )NÚ © )r   r   r   úK/var/www/html/CropPilot/venv/lib/python3.10/site-packages/xgboost/config.pyÚnone_to_str]   s   zconfig_doc.<locals>.none_to_strÚfuncc                    sd   ˆj ˆˆƒˆˆƒd�ˆˆƒ ˆˆƒ ˆˆƒ ˆˆƒ ˆ _tˆ ƒdtdtdtf‡ fdd„ƒ}tt|ƒS )N)r   r   ÚargsÚkwargsr   c                     s   ˆ | i |¤ŽS ©Nr   )r   r   ©r   r   r   Úwrapk   s   z6config_doc.<locals>.config_doc_decorator.<locals>.wrap)ÚformatÚ__doc__r   r   r	   r   )r   r    ©Úcommon_exampleÚdoc_templater   r   r   r   r   r   r   r   Úconfig_doc_decorator`   s   ÿýüûúÿ

z(config_doc.<locals>.config_doc_decorator)r   Ústrr   )r   r   r   r   r   r&   r   r#   r   Ú
config_doc   s
   +$r(   z#
    Set global configuration.
    z‘
    Parameters
    ----------
    new_config: Dict[str, Any]
        Keyword arguments representing the parameters and their values
            )r   r   Ú
new_configc                  K   sF   i }|   ¡ D ]\}}|d ur|||< qt |¡}tt t|ƒ¡ƒ d S r   )ÚitemsÚjsonÚdumpsr   r   ÚXGBSetGlobalConfigr   )r)   Únot_noneÚkÚvÚconfigr   r   r   Ú
set_configt   s   €
r2   z9
    Get current values of the global configuration.
    zu
    Returns
    -------
    args: Dict[str, Any]
        The list of global parameters and their values
            )r   r   c                  C   s<   t  ¡ } tt t  | ¡¡ƒ | j}|sJ ‚t t	|ƒ¡}|S r   )
ÚctypesÚc_char_pr   r   ÚXGBGetGlobalConfigÚbyrefr   r+   Úloadsr   )Ú
config_strr   r1   r   r   r   Ú
get_configˆ   s   r9   z;
    Context manager for global XGBoost configuration.
    zÄ
    .. note::

        All settings, not just those presently modified, will be returned to their
        previous values when the context manager is exited. This is not thread-safe.
            z—
    See Also
    --------
    set_config: Set global XGBoost configuration
    get_config: Get current values of the global configuration
            )r   r   r   r   c               
   k   sF   � t ƒ  ¡ }tdi | ¤Ž zd V  W tdi |¤Ž d S tdi |¤Ž w )Nr   )r9   Úcopyr2   )r)   Ú
old_configr   r   r   Úconfig_contextœ   s   €
"r<   )r"   r3   r+   Ú
contextlibr   Ú	functoolsr   Útypingr   r   r   r   r   r	   Ú_typingr   Úcorer   r   r   r   r'   r(   r2   r9   r<   r   r   r   r   Ú<module>   sX    úþýüûú
ùfü	ü	ð